Let's say I have a type of lookup table that I can build for a given integer:
class FooLookupTable { ... public: FooLookupTable(int radix) { ... } };
Then there is a class whose template parameter is the same integer, and whose constructor initializes the member instance of this lookup table:
template <int radix> class Foo { ... private: FooLookupTable table; public: Foo () : FooLookupTable (radix) { ... } };
In my code, I create them with different radix values:
int main() { ... Foo<1> myFoo; Foo<1> yourFoo; Foo<10> theirFoo; ... }
This works and does not create any problems with the hair or API. But he did not divide the radix table by 1 between myFoo and yourFoo . I could hard code the dependency on the proposed library of threads and build a global map filled on demand. But my question is:
"In the modern world of C ++ 11, is there a clean way to develop a library for Foo that has no dependencies outside standard libraries?"
I was thinking of using a static member for this, since each individual instance of the template class creates only one static member variable . But this raises the question of who is responsible for declaring space for the static member and whoever does this should βknow the correct way to initialize itβ:
FooLookupTable Foo<1>::table (1); FooLookupTable Foo<10>::table (10); int main() { ... Foo<1> myFoo; Foo<1> yourFoo; Foo<10> theirFoo; ... }
Reading what is written on a topic like C ++ Static initalization membership (boilerplate fun inside) "doesn't seem to be very hopeful ... if I don't," something is missing. Also, what happens if the Foo tags themselves were static ?: - /
c ++ templates lookup-tables
Hostilefork
source share