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

How to pass a template function in a template argument list

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

Variadic function template with pack expansion not in last parameter

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

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?

From C++ Templates The Complete Guide: Member function templates cannot be declared virtual. This constraint is imposed because the usual implementation of the virtual function call mechanism uses a fixed-size table with one entry per virtual function. However, the number of instantiations of a member function template is not fixed until the entire program has … Read more

tech