Skip to content

Instantly share code, notes, and snippets.

@gimKondo
Created June 23, 2014 14:43
Show Gist options
  • Save gimKondo/2fc95e3f442cbf5e5acd to your computer and use it in GitHub Desktop.
Save gimKondo/2fc95e3f442cbf5e5acd to your computer and use it in GitHub Desktop.
#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;
}
@gimKondo
Copy link
Author

VS2013のエラーメッセージ
「error C2664: 'void Increment::operator ()(int &)' : 引数 1 を 'const int' から 'int &' へ変換できません。」

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment