c++ - How to make these std::function parameters unambiguous? -
The following function overlaps are unclear when passing lambda. I found out that Here are some similar questions, but none of them can solve my problem. How can I solve the ambiguity without changing the usage? More than that, at that time I must explicitly mention the template type. Is there a way around this? It has one half, removing The other part of the problem is an overload resolution: With a library that implements LWG2132, probably surprising: Why? Zero (T & amp;, ID) & gt; The probable solution is Lambda's This will not work for general lambdas arbitrary function objects, which can be ((whose std :: function may be, even if their signature is no match. Therefore, the compiler can not tell which function to use.
template & lt; Typename T & gt; Zero each (standard :: actions & lt; zero (t) & gt; iterator); Template & lt; Typename T & gt; Zero each (std :: function & gt; zero (t, id) & gt; iterator); Template & lt; Typename T & gt; Zero (each std :: function & lt; void (T & amp;)> Iterator); Template & lt; Typename T & gt; Zero each (std :: function & lt; void (t & amp; id) & gt; iterator);
std :: function Constraint from overload resolution until the argument is actually not able to specify the argument type. Expression is required to implement SFINAE support, which is not near VC ++.
# include & lt; Functional & gt; # Include & lt; Iostream & gt; Structure id {}; Template & lt; Typename T & gt; Zero (each std :: function & lt; void (T) & gt;) {std :: cout & lt; & Lt; __PRETTY_FUNCTION__ & lt; & Lt; Std :: endl; } Template & lt; Typename T & gt; Each of the zero (standard :: actions & lt; zero (t, id) gt;) {std :: cout & lt; & Lt; __PRETTY_FUNCTION__ & lt; & Lt; Std :: endl; } Template & lt; Typename T & gt; Zero (each std :: function & lt; void (T & amp;) & gt;) {std :: cout & lt; & Lt; __PRETTY_FUNCTION__ & lt; & Lt; Std :: endl; } Template & lt; Typename T & gt; Each of the zero (standard :: works & lt; zero (T & amp ;, ID) & gt;) {std :: cout & lt; & Lt; __PRETTY_FUNCTION__ & lt; & Lt; Std :: endl; } Int main () {each & lt; Int & gt; ([] (Int, id) {}); }
zero
[] (integer, id) {} to first , it is possible to build a
std :: function. Eventually, may be > > template & lt; Typename T & gt; Zero each (std :: function & gt; zero (t, id) & gt;); Template & lt; Typename T & gt; Zero each (standard :: actions & lt; zero (T & amp; amp ;, ID) & gt;); Second, functional templates are more specific than before partial order rules, then it has always been chosen by the overload resolution.
operator () :
template & lt; Class T & gt; Struct mem_fn_type; to remove the signature by adding the type of Template & lt; Class R, Class C, Class ... T & gt; Struct mem_fn_type & lt; R (C :: *) (T ...)> {Type = std :: function & lt; R (t ...)>; }; Template & lt; Class R, Class C, Class ... T & gt; Struct mem_fn_type & lt; R (C: *) (T ...) const & gt; {Type = std :: function & lt; R (t ...)>; }; // optional additional CV-made // after qualifier and left ref-qualifier combo he detects smoke // Not to be used with lambdas, then a class std :: function template & lt expertise, Class T & Gt; Struct is_st__function_specialization: std :: false_type {}; Template & lt; Class T & gt; Structure is_st__function_specialization & lt; Std :: function & lt; T & gt; & Gt; : Std :: true_type {}; // A lambda template with incorrect cases & lt; Class t & gt; There is a specialization of t-std :: function, bound to not accept cases where t to prevent uninterrupted recurrence when passed. Typename std :: enable_if & lt; Is_std_function_specialization & lt; T & gt; :: Price & gt; :: Type every (t function) {typename mem_fn_type & lt; Decltype (& T :: operator ()) & gt; :: type f = function; Each (f); }
operator () a template) or arbitrarily many
operator () overload).
Comments
Post a Comment