Skip to content

Instantly share code, notes, and snippets.

@talybin
Created August 20, 2021 19:30
Show Gist options
  • Select an option

  • Save talybin/0f231da0df50e76c462662dcbf4e5b8b to your computer and use it in GitHub Desktop.

Select an option

Save talybin/0f231da0df50e76c462662dcbf4e5b8b to your computer and use it in GitHub Desktop.
Concept Lite (Filip Roséen)
#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
}
@talybin

talybin commented Aug 20, 2021

Copy link
Copy Markdown
Author

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.

@talybin

talybin commented Aug 20, 2021

Copy link
Copy Markdown
Author

@talybin

talybin commented Sep 20, 2021

Copy link
Copy Markdown
Author

Works fine as variadic argument too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment