There is one easy solution (maybe you didn't think about it), which is: template T& pool_map::get( size_t index ) { if (sizeof(T) * CHAR_BIT == 8) { // Dispatch to pool8_ } else if (sizeof(T) * CHAR_BIT == 16) { // Dispatch to pool16_ } else if (...) { ... } else { // Default case } } But since this will maybe give you compilation errors (depending on what you put instead of "dispatch to ...") you could simply overload the get() function template typename std::enable_if::type& get( size_t index ) { ... } template typename std::enable_if::type& get( size_t index ) { ... } etc The only problem is that the default implementation (if you need any) needs a condition like sizeof(T) * CHAR_BIT! = 8 && sizeof(T) * CHAR_BIT! = 16 && sizeof(T) * CHAR_BIT!
= 32 && sizeof(T) * CHAR_BIT! = 64 The last solution (the best one I'd say) would still to use a private class with a static function which you can specialize (what you said was not the "real static way").
There is one easy solution (maybe you didn't think about it), which is: template T& pool_map::get( size_t index ) { if (sizeof(T) * CHAR_BIT == 8) { // Dispatch to pool8_ } else if (sizeof(T) * CHAR_BIT == 16) { // Dispatch to pool16_ } else if (...) { ... } else { // Default case } } But since this will maybe give you compilation errors (depending on what you put instead of "dispatch to ...") you could simply overload the get() function. Template typename std::enable_if::type& get( size_t index ) { ... } template typename std::enable_if::type& get( size_t index ) { ... } etc. The only problem is that the default implementation (if you need any) needs a condition like sizeof(T) * CHAR_BIT! = 8 && sizeof(T) * CHAR_BIT!
= 16 && sizeof(T) * CHAR_BIT! = 32 && sizeof(T) * CHAR_BIT! = 64 The last solution (the best one I'd say) would still to use a private class with a static function which you can specialize (what you said was not the "real static way").
I managed to solve it. Thanks for your very accurate and exhaustive answer :) – Aurélien Vallée Aug 13 '10 at 13:03.
One solution is the use of enable_if and disable_if (normally) though I haven't tested it. Another solution is to simply forward the implementation details to a helper: namespace helper { template struct getter { static void Do() {} }; // specializations by type } template T& pool_map::get(size_t index) { return helper::getter::Do(); }.
You obviously noticed that I wrote what would be possible in a wonderful and ideal world where default template parameters and partial specialization of template methods are possible (without specializing the entire class). I would like to ear about advices to achieve the same effect, that is, being able to have a specialized method for each size S so that I can select the proper pool to use. The only solution that comes to my mind, would be to use an outer get_pool class that would take the pool_map as parameters an returns a reference to the poolX_ member, but I would like to avoid it, since it does not seems to be "the real static way".
Thanks for reading!
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.