Rules for defining a set of function types compatible with std :: function <R (T1, T2)>?

Suppose if I have this,

std::function<int(int,int)> fs;

then how can I define a set of functions (or function objects) that fscan be initialized with <

Which of the following permissions is allowed and what is not:

std::function<int(int,int)> fs = [](int, int) { return int(10); };
std::function<int(int,int)> fs = [](char, char) { return char(10); };
std::function<int(int,int)> fs = [](int, short) { return int(10); };
std::function<int(int,int)> fs = [](double, int) { return float(10); };
std::function<int(int,int)> fs = [](int, wchar_t) { return wchar_t(10); };

std::function<int(int,int)> fs = [](const char*, int){ return "string"; };
std::function<int(int,int)> fs = [](const char*, int){ return 10; };
std::function<int(int,int)> fs = [](const char*, int){ return std::string(); };

Of course, I can compile and see which one compiles and what does not. But this does not help me understand the changes in parameter types and return type. How far can I use different types for them?

In other words, if I gave a function (or a function object), how can I determine at compile time if it is compatible with std::function<int(int,int)>or not? I understand a little, but I'm not sure enough.

, , , std::function<R(T1,T2)>? , , , ?

, , -, : http://ideone.com/hJpG3

+5
2

( ) Callable , .. fun( declval< Types >() ... ) R.

., , ++ 11 ยง20.8.2; - .. ยง20.8.11.2/2 20.8.11.2.1/7 std::function.

+4

. , . , Potatoswatter. .

template <class _F, class ..._Args> struct __invokable;
template <class _F, class ..._Args> struct __invoke_of;

http://llvm.org/svn/llvm-project/libcxx/trunk/include/type_traits

"-" std::function:

template <class _F, bool = __invokable<_F&, _ArgTypes...>::value>
    struct __callable;

http://llvm.org/svn/llvm-project/libcxx/trunk/include/functional

, tr2- ( ). , , .

, . , , .

+4

All Articles