Template function inside template class
Write this: template <class T> template <class U> void MyClass<T>::foo() { /* … */ }
Write this: template <class T> template <class U> void MyClass<T>::foo() { /* … */ }
You need to cast to void *: std::cout << (void*)(ftype*)f<A> << std::endl; std::cout << (void*)(ftype*)f<B> << std::endl; If you cast to a function pointer (or several other classes of non-void pointers), it will be interpreted as a bool by the operator<< for std::ostream (hence the 1).
I suspect the answer is “you cannot do this”. Yes, that is the case, you cannot pass a function template as a template argument. From 14.3.3: A template-argument for a template template-parameter shall be the name of a class template or an alias template, expressed as id-expression. The template function needs to be instantiated before … Read more
Because when a function parameter pack is not the last parameter, then the template parameter pack cannot be deduced from it and it will be ignored by template argument deduction. So the two arguments 0, 0 are compared against , int, yielding a mismatch. Deduction rules like this need to cover many special cases (like … Read more
You can create a macro like #define FUNCTORIZE(func) [](auto&&… val) \ noexcept(noexcept(func(std::forward<decltype(val)>(val)…))) -> decltype(auto) \ {return func(std::forward<decltype(val)>(val)…);} which will let you wrap any callable into a closure object. You would use it like auto constexpr predObj = FUNCTORIZE(pred);
As it stands now it definitly looks that way. Previously [namespace.std] contained A program may add a template specialization for any standard library template to namespace std only if the declaration depends on a user-defined type and the specialization meets the standard library requirements for the original template and is not explicitly prohibited. While the … Read more
AFAIK that’s changed in C++0x. I guess it was just an oversight (considering that you can always get the partial specialization effect with more verbose code, by placing the function as a static member of a class). You might look up the relevant DR (Defect Report), if there is one. EDIT: checking this, I find … Read more
Templates are all about the compiler generating code at compile-time. Virtual functions are all about the run-time system figuring out which function to call at run-time. Once the run-time system figured out it would need to call a templatized virtual function, compilation is all done and the compiler cannot generate the appropriate instance anymore. Therefore … Read more