-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
43 lines (33 loc) · 1.18 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script
src="https://cdn.jsdelivr.net/gh/google/code-prettify@master/loader/run_prettify.js?autoload=true&skin=desert&lang=cpp"
defer="">
</script>
</head>
<body>
<pre class="prettyprint" id="lang-cpp">
#include <type_traits>
template<class T>
concept aggregate = std::is_aggregate_v<std::remove_cvref_t<T>>;
// empty class convertible to anything
struct ToAnything{ template<class To> operator To&&(); };
// for an aggregate type 'T',
// return the number of data members
template<aggregate T>
consteval auto arity(auto... to_anything)
{
// could 'T' be construct with one more argument ?
if constexpr(requires{ T{ {to_anything}..., {ToAnything{}} }; })
// yes ? keep trying with more argument
return arity<T>(to_anything..., ToAnything{});
// no ? so we found the aggregate arity
// as we can aggregate initialize 'T' with {to_anything...} at most
else
return sizeof...(to_anything);
}
</pre>
</body>
</html>