Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <type_traits>
- #include <cstdlib>
- template< bool condition >
- void
- f(char const * message = "")
- {
- auto a = [&] (std::true_type) { std::cout << __PRETTY_FUNCTION__ << ' ' << message << std::endl; };
- auto b = [&] (std::false_type) { std::cout << __PRETTY_FUNCTION__ << ' ' << message << std::endl; };
- struct static_if : decltype(a), decltype(b)
- {
- using decltype(a)::operator ();
- using decltype(b)::operator ();
- static_if(decltype(a) _a, decltype(b) _b)
- : decltype(a){_a}, decltype(b){_b}
- { ; }
- };
- static_if{a, b}(std::integral_constant< bool, condition >{});
- }
- int
- main()
- {
- f< true >("Success!");
- f< false >("Failure!");
- return EXIT_SUCCESS;
- }
Advertisement
Add Comment
Please, Sign In to add comment