Skip to content

Commit 5c9f788

Browse files
committed
Refine alloy interface
1 parent f789eaf commit 5c9f788

20 files changed

Lines changed: 760 additions & 184 deletions

include/iris/alloy/adapt.hpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,33 +3,35 @@
33

44
// SPDX-License-Identifier: MIT
55

6+
#include <iris/config.hpp> // IWYU pragma: keep
7+
8+
#include <iris/type_traits.hpp> // IWYU pragma: keep
9+
610
#include <iris/pp/comma.hpp>
711
#include <iris/pp/seq.hpp>
812
#include <iris/pp/tuple.hpp>
913

1014
namespace iris::alloy {
1115

12-
namespace detail {
13-
14-
template<auto... Vs>
15-
struct non_type_list;
16-
17-
} // detail
18-
1916
template<class T>
2017
struct adaptor;
2118

22-
template<auto... Getters>
23-
using make_getters_list = detail::non_type_list<Getters...>;
24-
2519
} // iris::alloy
2620

27-
#define IRIS_ALLOY_ADAPT_STRUCT(class_name, ...) \
28-
template<> \
29-
struct iris::alloy::adaptor<class_name> { \
30-
using getters_list = make_getters_list<IRIS_PP_SEQ_FOR_EACH_WITH_INDEX(IRIS_PP_TUPLE_TO_SEQ((__VA_ARGS__)), IRIS_ALLOY_ADAPT_STRUCT_I, class_name)>; \
21+
#define IRIS_ALLOY_ADAPT_STRUCT_I(index, data_member, class_name) \
22+
IRIS_PP_COMMA_IF(index) & class_name::data_member
23+
24+
#define IRIS_ALLOY_ADAPT_STRUCT(class_name, ...) \
25+
template<> \
26+
struct iris::alloy::adaptor<class_name> \
27+
{ \
28+
using getters_list = iris::constant_list< \
29+
IRIS_PP_SEQ_FOR_EACH_WITH_INDEX( \
30+
IRIS_PP_TUPLE_TO_SEQ((__VA_ARGS__)), \
31+
IRIS_ALLOY_ADAPT_STRUCT_I, \
32+
class_name \
33+
) \
34+
>; \
3135
};
3236

33-
#define IRIS_ALLOY_ADAPT_STRUCT_I(index, data_member, class_name) IRIS_PP_COMMA_IF(index) & class_name::data_member
34-
3537
#endif

include/iris/alloy/adapted/std_pair.hpp

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,62 @@
33

44
// SPDX-License-Identifier: MIT
55

6-
#include <utility>
6+
#include <iris/config.hpp> // IWYU pragma: keep
7+
8+
#include <iris/alloy/detail/std_get.hpp>
9+
10+
#include <utility> // IWYU pragma: export
11+
12+
#include <cstddef>
713

814
namespace iris::alloy {
915

10-
namespace detail {
16+
template<class T>
17+
struct tuple_size;
18+
19+
template<class T, class U>
20+
struct tuple_size<std::pair<T, U>> : std::integral_constant<std::size_t, 2>
21+
{};
22+
23+
template<class T, class U>
24+
struct tuple_size<std::pair<T, U> const> : std::integral_constant<std::size_t, 2>
25+
{};
26+
27+
template<class T, class U>
28+
struct tuple_size<std::pair<T, U> volatile> : std::integral_constant<std::size_t, 2>
29+
{};
30+
31+
template<class T, class U>
32+
struct tuple_size<std::pair<T, U> const volatile> : std::integral_constant<std::size_t, 2>
33+
{};
34+
35+
template<std::size_t I, class Tuple>
36+
struct tuple_element;
37+
38+
template<std::size_t I, class T, class U>
39+
struct tuple_element<I, std::pair<T, U>> : std::tuple_element<I, std::pair<T, U>>
40+
{};
41+
42+
template<std::size_t I, class T, class U>
43+
struct tuple_element<I, std::pair<T, U> const> : std::tuple_element<I, std::pair<T, U> const>
44+
{};
45+
46+
template<std::size_t I, class T, class U>
47+
struct tuple_element<I, std::pair<T, U> volatile> : std::tuple_element<I, std::pair<T, U> volatile>
48+
{};
1149

12-
template<auto... Vs>
13-
struct non_type_list;
50+
template<std::size_t I, class T, class U>
51+
struct tuple_element<I, std::pair<T, U> const volatile> : std::tuple_element<I, std::pair<T, U> const volatile>
52+
{};
1453

15-
} // detail
1654

1755
template<class T>
1856
struct adaptor;
1957

2058
template<class T, class U>
2159
struct adaptor<std::pair<T, U>>
2260
{
23-
using getters_list = detail::non_type_list<&std::pair<T, U>::first, &std::pair<T, U>::second>;
61+
using getters_list = detail::call_std_get<std::index_sequence<0, 1>>::type;
2462
};
2563

2664
} // iris::alloy

include/iris/alloy/adapted/std_tuple.hpp

Lines changed: 41 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,63 @@
33

44
// SPDX-License-Identifier: MIT
55

6-
#include <iris/alloy/detail/integer_seq_transform.hpp>
6+
#include <iris/config.hpp> // IWYU pragma: keep
77

8-
#include <tuple>
8+
#include <iris/alloy/detail/std_get.hpp>
9+
10+
#include <tuple> // IWYU pragma: export
911
#include <utility>
1012

1113
#include <cstddef>
1214

1315
namespace iris::alloy {
1416

1517
template<class T>
16-
struct adaptor;
18+
struct tuple_size;
1719

18-
namespace detail {
20+
template<class... Ts>
21+
struct tuple_size<std::tuple<Ts...>> : std::integral_constant<std::size_t, sizeof...(Ts)>
22+
{};
1923

20-
template<std::size_t I>
21-
struct call_std_get
22-
{
23-
template<class Tuple>
24-
static constexpr decltype(auto) operator()(Tuple&& t)
25-
{
26-
return std::get<I>(static_cast<Tuple&&>(t));
27-
}
28-
};
24+
template<class... Ts>
25+
struct tuple_size<std::tuple<Ts...> const> : std::integral_constant<std::size_t, sizeof...(Ts)>
26+
{};
2927

30-
template<std::size_t I>
31-
struct make_call_std_get
32-
{
33-
static constexpr auto value = call_std_get<I>{};
34-
};
28+
template<class... Ts>
29+
struct tuple_size<std::tuple<Ts...> volatile> : std::integral_constant<std::size_t, sizeof...(Ts)>
30+
{};
3531

36-
} // detail
32+
template<class... Ts>
33+
struct tuple_size<std::tuple<Ts...> const volatile> : std::integral_constant<std::size_t, sizeof...(Ts)>
34+
{};
35+
36+
template<std::size_t I, class Tuple>
37+
struct tuple_element;
38+
39+
template<std::size_t I, class... Ts>
40+
struct tuple_element<I, std::tuple<Ts...>> : std::tuple_element<I, std::tuple<Ts...>>
41+
{};
42+
43+
template<std::size_t I, class... Ts>
44+
struct tuple_element<I, std::tuple<Ts...> const> : std::tuple_element<I, std::tuple<Ts...> const>
45+
{};
46+
47+
template<std::size_t I, class... Ts>
48+
struct tuple_element<I, std::tuple<Ts...> volatile> : std::tuple_element<I, std::tuple<Ts...> volatile>
49+
{};
50+
51+
template<std::size_t I, class... Ts>
52+
struct tuple_element<I, std::tuple<Ts...> const volatile> : std::tuple_element<I, std::tuple<Ts...> const volatile>
53+
{};
54+
55+
56+
template<class T>
57+
struct adaptor;
3758

3859
template<class... Ts>
3960
struct adaptor<std::tuple<Ts...>>
4061
{
41-
using getters_list = detail::integer_seq_transform_t<std::make_index_sequence<sizeof...(Ts)>, detail::make_call_std_get>;
62+
using getters_list = detail::call_std_get<std::index_sequence_for<Ts...>>::type;
4263
};
4364

4465
} // iris::alloy

include/iris/alloy/detail/deduce.hpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,20 @@
33

44
// SPDX-License-Identifier: MIT
55

6+
#include <iris/config.hpp> // IWYU pragma: keep
7+
68
#include <type_traits>
79

810
namespace iris::alloy::detail {
911

1012
template<class FromLValue, class FromXValue>
1113
struct deduce
1214
{
13-
static_assert(std::conjunction_v<std::is_reference<FromLValue>, std::is_reference<FromXValue>,
14-
std::is_same<std::remove_reference_t<FromLValue>, std::remove_reference_t<FromXValue>>>);
15+
static_assert(std::conjunction_v<
16+
std::is_reference<FromLValue>,
17+
std::is_reference<FromXValue>,
18+
std::is_same<std::remove_reference_t<FromLValue>, std::remove_reference_t<FromXValue>>
19+
>);
1520
};
1621

1722
template<class T>
@@ -33,7 +38,7 @@ struct deduce<T&&, T&&>
3338
};
3439

3540
template<class FromLValue, class FromXValue>
36-
using deduce_t = typename deduce<FromLValue, FromXValue>::type;
41+
using deduce_t = deduce<FromLValue, FromXValue>::type;
3742

3843
} // iris::alloy::detail
3944

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef IRIS_ZZ_ALLOY_DETAIL_STD_GET_HPP
2+
#define IRIS_ZZ_ALLOY_DETAIL_STD_GET_HPP
3+
4+
// SPDX-License-Identifier: MIT
5+
6+
#include <iris/config.hpp> // IWYU pragma: keep
7+
8+
#include <iris/type_traits.hpp>
9+
10+
#include <utility>
11+
12+
#include <cstddef> // IWYU pragma: keep
13+
14+
namespace iris::alloy::detail {
15+
16+
template<std::size_t I>
17+
struct call_std_get_impl
18+
{
19+
template<class Tuple>
20+
[[nodiscard]] static constexpr decltype(auto) operator()(Tuple&& t) noexcept
21+
{
22+
return std::get<I>(static_cast<Tuple&&>(t));
23+
}
24+
};
25+
26+
template<class Seq>
27+
struct call_std_get;
28+
29+
template<std::size_t... Is>
30+
struct call_std_get<std::index_sequence<Is...>>
31+
{
32+
using type = constant_list<call_std_get_impl<Is>{}...>;
33+
};
34+
35+
} // iris::alloy::detail
36+
37+
#endif

include/iris/alloy/detail/tuple_comparison.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@
33

44
// SPDX-License-Identifier: MIT
55

6+
#include <iris/config.hpp> // IWYU pragma: keep
7+
68
#include <iris/requirements.hpp>
79

8-
#include <concepts>
910
#include <type_traits>
1011

1112
namespace iris::alloy {

include/iris/alloy/detail/tuple_impl.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#ifndef IRIS_ALLOY_GENERATE_PREPROCESSED
77

8-
#include <iris/config.hpp>
8+
#include <iris/config.hpp> // IWYU pragma: keep
99

1010
#include <iris/alloy/detail/tuple_comparison.hpp>
1111

@@ -15,7 +15,7 @@
1515

1616
#include <type_traits>
1717

18-
#include <cstddef>
18+
#include <cstddef> // IWYU pragma: keep
1919

2020
#endif
2121

include/iris/alloy/io.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33

44
// SPDX-License-Identifier: MIT
55

6+
#include <iris/config.hpp> // IWYU pragma: keep
7+
68
#include <iris/io_fwd.hpp>
79

810
#include <iris/alloy/tuple.hpp>
911

1012
#include <ostream>
1113
#include <utility>
1214

13-
#include <cstddef>
15+
#include <cstddef> // IWYU pragma: keep
1416

1517
namespace iris::alloy {
1618

0 commit comments

Comments
 (0)