Explicit constructing boost intrusive list

Hi, I would like to use a boost::intrusive::list as a static global resource, which are accessed by other global objects. To ensure that the list is initialized before it is used by "other" global objects, I have been looking in to using the "Nifty counter" method (http://en.wikibooks.org/wiki/More_C%2B%2B_Idioms/Nifty_Counter). The problem is, that the nifty counter demands that it can control construction and destruction of the object. Is there any achieve this or something similar when using intrusive::list as a global resource? Best regards Allan W. Nielsen

On Tue, Jun 26, 2012 at 4:39 PM, Allan Nielsen wrote:
Is there any achieve this or something similar when using intrusive::list as a global resource?
If you can use C++11 lambda expressions, you can do something like this: static const ContainerType GLOBAL_REGISTRY = []() -> ContainerType // lambda that return a ContainerType { ContainerType my_container; // fill the container however you want, done only once return my_container; }(); // don't forget the () to execute the lambda on initialization It's better than a free function because you are sure it cannot be called by any other code. Hope it helps. Joel Lamotte
participants (2)
-
Allan Nielsen
-
Klaim - Joël Lamotte