Skip to content

Initializer Lists for OpenSim::Array #4046

Open
@alexbeattie42

Description

@alexbeattie42

The Problem

The OpenSim::Array class does not support initializer lists in the standard way. The code sample below shows what is possible with the current API. It should be possible to initialize an array with arbitrary element literals specified in the initializer list but this isn't the case. The first case requires initializing a blank array and then filling it. The second uses an initializer list but does the same operation as the first which is misleading. The third example does not compile, but should when initializer lists are supported.

    // This works 
    OpenSim::Array<double> timeRange(0, 2, 2);
    timeRange[0] = -1.0;
    timeRange[1] = 2.0;
    std::cout << timeRange << std::endl;

    // And this works but doesn't give me what I expect
    OpenSim::Array<int> timeRange2{-1, 2};
    std::cout << timeRange2 << std::endl;

    // But this doesn't even compile
    // OpenSim::Array<double> timeRange3{1.0, 2.0};

Full code sample.

The Solution

Adding initializer list support for the OpenSim::Array class.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions