I'm confused by this: I don't want to use a catch-all: template class Test // arguments unused class Test { public: template void* get( const T1& ); void* get(const int& ); // overload of the above }; typedef Test foo; // illegal to instantiate a template before its members are defined inline template class Test; // "inline template" is meaningless template void* foo::get(int const&); // typedef name "foo" cannot be used here /* ^ illegal to explicitly instantiate a member of an already explicitly instantiated template Update: The error results from the non-template overload not having priority over the member template Unfortunately, you cannot explicitly specialize a member template of a template parent. The workaround at that question is to partially specialize, but that won't work because you have a function template Workaround #2 is SFINAE include #include template boost::disable_if, void* >::type get( const T1& ); // "turn off" declaration if in conflict void* get(const int& ); // unambiguous overload of the above If you can't use Boost template struct disable_if_int { typedef void *type; }; template struct disable_if_int {} template disable_if_int::type get( const T1& ); void* get(const int& ); // unambiguous overload of the above.
I'm confused by this: I don't want to use a catch-all: template class Test because the overload get(const int&) will not be defined for all possible explicit instantiations and hence the compiler will throw a fit for types which don't support it. Explicitness of one specialization does not affect the semantics of other specializations. The overload get(const int&) is simply a member function, and it will be instantiated for explicit and implicit specializations like any other.
Explicit instantiation can only slow down the compiler. It only processes each instantiation at most once. Unused parts of an implicit instantiation may be ignored, but by explicitly instantiating, you are forcing it to handle the whole thing.
Not that a single instantiation is likely to take a measurable amount of time, anyway. To run through errors in the code: template // arguments unused class Test { public: template void* get( const T1& ); void* get(const int& ); // overload of the above }; typedef Test foo; // illegal to instantiate a template before its members are defined inline template class Test; // "inline template" is meaningless template void* foo::get(int const&); // typedef name "foo" cannot be used here /* ^ illegal to explicitly instantiate a member of an already explicitly instantiated template */ Update: The error results from the non-template overload not having priority over the member template. Unfortunately, you cannot explicitly specialize a member template of a template parent.
The workaround at that question is to partially specialize, but that won't work because you have a function template. Workaround #2 is SFINAE. #include #include template boost::disable_if, void* >::type get( const T1& ); // "turn off" declaration if in conflict void* get(const int& ); // unambiguous overload of the above If you can't use Boost, template struct disable_if_int { typedef void *type; }; template struct disable_if_int {}; ... template disable_if_int::type get( const T1& ); void* get(const int& ); // unambiguous overload of the above.
In gcc, if you instantiate with inline, then no member functions are intantiated and you can do it on need basis. If you do not use "inline" while instantiating, then all the members of the template are instantiated. Ref: gcc.gnu.Org/onlinedocs/gcc/Template-Instantiation.
Html Sorry for the bad phrasing, I wanted the capability to instantiate every necessary member by using inline and got the error when trying to do so. – Venkatesan Aug 30 '10 at 6:39 @Venkatesan: "every necessary member"? According to the page you linked, no members are instantiated by that.
– Potatoswatter Aug 30 '10 at 6:54.
Template class Test { public: template void* get( const T1& ) { return nullptr; } template void* get(const int& ) { return nullptr; } //Specialization of the above }; typedef Test foo; int main() { foo lols; void* innit = lols. Get(1); void* bruv = lols. Get("yocakes"); } This compiles just fine for me on VS2010.
Nullptr is c++0x btw, but you could just replace with 0/NULL.
14.7.3/2: "An explicit specialization shall be declared… for member templates, in the namespace of which the enclosing class or enclosing class template is a member. " Also, you removed the explicit instantiations entirely, which kinda sidesteps the question. – Potatoswatter Aug 28 '10 at 18:49.
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.