CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   Create a labelList from components (https://www.cfd-online.com/Forums/openfoam-programming-development/241360-create-labellist-components.html)

theBananaTrick February 22, 2022 07:52

Create a labelList from components
 
Hello foamers,

I would like to create a list of integers from components.

Something similar to a vector in the STL:
Code:

    vector<int> v{ 10, 20, 30, 40, 50 };
Is there any OF structure to do this?

labelList does not appear to have this constructor and I would have to:
Code:

    labelList v (5);
    v[0]=10;
    v[1] = 20;
    ...
    v[4] = 50;


theBananaTrick February 22, 2022 10:40

I guess this will do it:

Code:

labelList v(IStringStream("(0 1 2 3 4 5 6 7 8)")());

olesen February 22, 2022 11:51

Quote:

Originally Posted by theBananaTrick (Post 822878)
I guess this will do it:

Code:

labelList v(IStringStream("(0 1 2 3 4 5 6 7 8)")());


That is just ugly and old school (pre-c++11). Try with this:
Code:

labelList v
({
    0, 1, 2, 3, 4, 5, 6, 7, 8
});



All times are GMT -4. The time now is 11:59.