-
Notifications
You must be signed in to change notification settings - Fork 0
/
typeof_concept.h
96 lines (88 loc) · 4.55 KB
/
typeof_concept.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#pragma once
/* C++20
| |
__| __| | | __| |
( ( | | | |
\___| \___| \__,_| \__| _|
ccutl Core Utilities
[ccutl.typeof_concept]: creates a template spec-detection concept
Copyright (C) 2020, 2021 Justin Collier
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the internalied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>. */
#include <pputl/cat.h>
#include <pputl/tuple/args.h>
#include "src/ctl/detail/config.h"
/**
* creates a template spececialization detection concept.
* different template parameter layouts require different SFINAE setups;
* use this macro to create a concept for a given parameter layout.
*
* see ccutl.typeof for an example using a (class...) paramter layout.
*
* \param name - final name of the concept
* \param template_params_tuple - tupled template parameter types and names
* \param template_args_tuple - tupled template argument invocation text
*
* \note template parameter names cannot be `Template_` or `T_`
*
* \code
* #include <vector>
* #include <tuple>
* #include <array>
*
* #include <ctl/typeof_concept.h>
*
* using std::vector;
* using std::array;
* using std::tuple;
*
* // template<class T, template<class... Ts> class Template>
* // concept type_typeof = {sfinae};
* CTL_TYPEOF_CONCEPT(type_typeof, (class... Ts), (Ts...));
*
* constexpr bool ex0 = type_typeof<vector<int>, vector>; // true
* constexpr bool ex1 = type_typeof<vector<int>, tuple>; // false
*
* // template<class T, template<class T, std::size_t sz> class Template>
* // concept type_size_typeof = {sfinae};
* CTL_TYPEOF_CONCEPT(type_size_typeof, (class T, std::size_t sz), (T, sz));
*
* constexpr bool ex2 = type_size_typeof<array<int, 3>, array>; // true
* constexpr bool ex3 = type_size_typeof<tuple<int>, array>; // false
* \endcode
*
* \anchor typeof_concept
* \ingroup ccutl
*/
#define CTL_TYPEOF_CONCEPT(name, template_params_tuple, template_args_tuple) \
namespace detail { \
namespace PPUTL_CAT(name, _concept_) { \
\
template <template <PPUTL_TUPLE_ARGS(template_params_tuple)> class, class> \
struct test { \
static constexpr bool result = false; \
}; \
\
template < \
template <PPUTL_TUPLE_ARGS(template_params_tuple)> class Template_, \
PPUTL_TUPLE_ARGS(template_params_tuple)> \
struct test<Template_, Template_<PPUTL_TUPLE_ARGS(template_args_tuple)>> { \
static constexpr bool result = true; \
}; \
\
} /* namespace PPUTL_CAT(name, _concept_) */ \
} /* namespace detail */ \
\
template < \
class T_, \
template <PPUTL_TUPLE_ARGS(template_params_tuple)> class Template_> \
concept name = \
detail::PPUTL_CAT(name, _concept_)::test<Template_, T_>::result