Most terse and reusable way of wrapping template or overloaded functions in function objects

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);

Will specialization of function templates in std for program-defined types no longer be allowed in C++20?

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

Why function template cannot be partially specialized?

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

Can a class member function template be virtual?

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