-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstructable_with.hpp
33 lines (28 loc) · 1.03 KB
/
constructable_with.hpp
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
#pragma once
#include <cstddef> // std::size_t
#include <iostream> // std::cout
#include <type_traits> // std::is_aggregate
#include <utility> // std::index_sequence
namespace mlib
{
template <std::size_t i>
struct convertible_to_anything {
template <typename T>
operator T() {};
};
template <typename T, std::size_t I>
concept is_constructable_with = requires {
[] <std::size_t... is>(std::index_sequence<is...> i_s)
-> decltype(T{ convertible_to_anything<is>{}... }) {
return {};
}(std::make_index_sequence<I>{});
};
template <typename T, std::size_t n>
concept aggregate_of = std::is_aggregate_v<T> && is_constructable_with<T, n> &&
!is_constructable_with<T, n + 1>;
template <typename T>
constexpr auto number_of_aggregate_members =
[]<std::size_t... indexes>(std::index_sequence<indexes...> i_s) {
return ((aggregate_of<T, indexes> *indexes) + ... + 0);
}(std::make_index_sequence<12>{});
} // namespace mlib