| 1 |
#include <type_traits> |
| 2 |
|
| 3 |
//generic |
| 4 |
template <typename ...Types> |
| 5 |
struct allIntegralTypes; |
| 6 |
|
| 7 |
template <> |
| 8 |
struct allIntegralTypes<> |
| 9 |
{ |
| 10 |
static bool const value = true; |
| 11 |
}; |
| 12 |
//= |
| 13 |
|
| 14 |
//partial |
| 15 |
template <typename First, typename ...Types> |
| 16 |
struct allIntegralTypes<First, Types ...> |
| 17 |
{ |
| 18 |
static bool const value = std::is_integral<First>::value and |
| 19 |
allIntegralTypes<Types ...>::value; |
| 20 |
}; |
| 21 |
//= |
| 22 |
|
| 23 |
//concept |
| 24 |
template <typename ...Types> |
| 25 |
concept IntegralOnly = allIntegralTypes<Types ...>::value; |
| 26 |
|
| 27 |
template <IntegralOnly ...Types> |
| 28 |
void fun(Types ...types) |
| 29 |
{} |
| 30 |
//= |
| 31 |
|
| 32 |
int main() |
| 33 |
{ |
| 34 |
fun(12, 13, 'a', true); |
| 35 |
fun(); |
| 36 |
// fun(12.5); // WC: 12.5 is not an integral type |
| 37 |
} |