Skip to content

Instantly share code, notes, and snippets.

@qrealka
Created October 16, 2019 11:51
Show Gist options
  • Save qrealka/5318b98be46121653864646db9437413 to your computer and use it in GitHub Desktop.
Save qrealka/5318b98be46121653864646db9437413 to your computer and use it in GitHub Desktop.
concepts for c++14
// (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