Created
October 16, 2019 11:51
-
-
Save qrealka/5318b98be46121653864646db9437413 to your computer and use it in GitHub Desktop.
concepts for c++14
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
// (C) eric niebler | |
#include <type_traits> | |
#define CAT_(X, ...) X ## __VA_ARGS__ | |
#define CAT(X, ...) CAT_(X, __VA_ARGS__) | |
#define RETURN(...) return_t<__VA_ARGS__, std::enable_if_t<RETURN_ | |
#define RETURN_(...) CAT(RETURN_, __VA_ARGS__)>> | |
#define RETURN_requires | |
// for real concepts | |
// #define EXPAND(...) __VA_ARGS__ | |
// #define RETURN(...) __VA_ARGS__ EXPAND | |
template<class T, class...> | |
using return_t = T; | |
template<class T> | |
auto foo(T) -> RETURN(int)(requires (std::is_integral_v<T>)) | |
{ | |
return 42; | |
} | |
int main() | |
{ | |
// foo(""); // compile error | |
return foo(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment