Created
August 20, 2021 19:30
-
-
Save talybin/0f231da0df50e76c462662dcbf4e5b8b to your computer and use it in GitHub Desktop.
Concept Lite (Filip Roséen)
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 <type_traits> | |
template <class T, class = std::enable_if_t<std::is_integral<T>::value>> | |
using integral_t = T; | |
// the usage | |
template <class T> | |
void f(integral_t<T> a) {} | |
int main() | |
{ | |
f ( 123); // ok | |
// f (3.14f); // ill-formed | |
} |
Works fine as variadic argument too.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One must be aware of the fact that the above technique will make it troublesome to provide an additional overload of f having the same signature — since we, effectively, are declaring
template<class T> void f (T)
in both cases.