Created
June 23, 2014 14:43
-
-
Save gimKondo/2fc95e3f442cbf5e5acd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
template <typename VAL, typename FUNC> | |
inline typename std::result_of<FUNC(const VAL&)>::type | |
invoke(const VAL& trg, FUNC func) | |
{ | |
return func(trg); | |
} | |
template <typename VAL, typename FUNC> | |
inline typename std::result_of<FUNC(VAL&)>::type | |
invoke(VAL& trg, FUNC func) | |
{ | |
return func(trg); | |
} | |
struct IsEven | |
{ | |
typedef bool reuslt_type; | |
bool operator()(const int& n) { return n % 2 == 0; } | |
}; | |
struct Increment | |
{ | |
typedef bool reuslt_type; | |
void operator()(int& n) { ++n; } | |
}; | |
int main() | |
{ | |
int a = 2; | |
std::cout << invoke(a, IsEven()) << std::endl; | |
invoke(a, Increment()); | |
std::cout << a << std::endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
VS2013のエラーメッセージ
「error C2664: 'void Increment::operator ()(int &)' : 引数 1 を 'const int' から 'int &' へ変換できません。」