Created
October 17, 2014 08:27
-
-
Save zakky-dev/cef3901f48924272fb2e to your computer and use it in GitHub Desktop.
templateにlambdaを渡したい
This file contains hidden or 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> | |
/* | |
// lambdaをtemplate parameterとして渡したい | |
auto template_func = [](int l, int r) { return l == r; }; | |
typedef decltype(template_func) template_function_parameter; | |
template <template_function_parameter f> | |
bool template_function_bad() | |
{ | |
return f(1,1); | |
} | |
*/ | |
template <bool(*f)(int,int)> | |
bool template_function() | |
{ | |
return f(1,23); | |
} | |
bool param_func(int r, int l) | |
{ | |
return r == l; | |
} | |
int main() | |
{ | |
// std::cout << template_function_bad<[](int l, int r){ return l == r; }>(); | |
std::cout << template_function<*param_func>(); | |
return 0; | |
} |
otf
commented
Oct 17, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment