CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM (https://www.cfd-online.com/Forums/openfoam/)
-   -   labelListList handling (https://www.cfd-online.com/Forums/openfoam/93739-labellistlist-handling.html)

tomislav_maric May 20, 2014 06:14

@Daniel:

Quote:

Because when i write : "const labelListList & listlist; " i get the error because of non-initialization.
You are trying to bind a const reference to nothing. References are aliases to objects, put most simply. Se this SO answer for information on the differences between pointers and references.

If you need an empty object, do this:

Code:

    labelListList listlist;
If you are going to use the listlist in the constructor and zero-initialize it, it makes no sense to declare it const. The member functions will not be able to modify the zero-initialized listlist. So, just use the listlist as a regular object as in the code snippet above.

If you need a dynamic list of label lists, using the DynamicList template with default template arguments for container expansion, it looks like this:

Code:

    // Shorten the type name. Note the space between the last '> >' -
    // unless you are using the C++11 standad. 
    typedef DynamicList<DynamicList<label> > dynamicLabelListList;

    // Use your new type name alias and declare an empty list object.
    dynamicLabelListList listList;

    // append a label

    listList.append(0);

Note that even though the dynamic list is dynamic the cost of expansion is still slightly better than O(n) (because of a default expansion strategy that reserves extra capacity). If you are using the list to store 100 labels, you won't see the difference. With 1e06 labels you will, and you should initialize the list with a reasonable starting size.

Good luck, hope this helps.T

Daniel73 May 20, 2014 08:20

Many Thanks :)


All times are GMT -4. The time now is 07:55.