Skip to content

Instantly share code, notes, and snippets.

@rinfz
Last active March 7, 2019 11:33
Show Gist options
  • Save rinfz/0e10185c673c95a40cab973b4eeaec94 to your computer and use it in GitHub Desktop.
Save rinfz/0e10185c673c95a40cab973b4eeaec94 to your computer and use it in GitHub Desktop.
constexpr and std::function crap
#include <iostream>
#include <functional>
enum Dir { H, V };
template<Dir d>
void call(double x, double y) {
std::function<double(double, double)> f;
if constexpr (d == H) {
f = [](double x, double y) -> double {
return x * y;
};
} else {
f = [](double x, double y) -> double {
return x * y * 10;
};
}
std::cout << f(x, y) << '\n';
}
void call1() {
int n = 10;
std::function<bool()> f;
f = [&n]() -> bool {
return n > 15;
};
std::cout << f() << '\n';
n += 6;
std::cout << f() << '\n';
}
int main() {
call<V>(5, 5);
call1();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment