Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 18 additions & 16 deletions include/iris/alloy/adapt.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,35 @@

// SPDX-License-Identifier: MIT

#include <iris/config.hpp> // IWYU pragma: keep

#include <iris/type_traits.hpp> // IWYU pragma: keep

#include <iris/pp/comma.hpp>
#include <iris/pp/seq.hpp>
#include <iris/pp/tuple.hpp>

namespace iris::alloy {

namespace detail {

template<auto... Vs>
struct non_type_list;

} // detail

template<class T>
struct adaptor;

template<auto... Getters>
using make_getters_list = detail::non_type_list<Getters...>;

} // iris::alloy

#define IRIS_ALLOY_ADAPT_STRUCT(class_name, ...) \
template<> \
struct iris::alloy::adaptor<class_name> { \
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)>; \
#define IRIS_ALLOY_ADAPT_STRUCT_I(index, data_member, class_name) \
IRIS_PP_COMMA_IF(index) & class_name::data_member

#define IRIS_ALLOY_ADAPT_STRUCT(class_name, ...) \
template<> \
struct iris::alloy::adaptor<class_name> \
{ \
using getters_list = iris::constant_list< \
IRIS_PP_SEQ_FOR_EACH_WITH_INDEX( \
IRIS_PP_TUPLE_TO_SEQ((__VA_ARGS__)), \
IRIS_ALLOY_ADAPT_STRUCT_I, \
class_name \
) \
>; \
};

#define IRIS_ALLOY_ADAPT_STRUCT_I(index, data_member, class_name) IRIS_PP_COMMA_IF(index) & class_name::data_member

#endif
50 changes: 44 additions & 6 deletions include/iris/alloy/adapted/std_pair.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,62 @@

// SPDX-License-Identifier: MIT

#include <utility>
#include <iris/config.hpp> // IWYU pragma: keep

#include <iris/alloy/detail/std_get.hpp>

#include <utility> // IWYU pragma: export

#include <cstddef>

namespace iris::alloy {

namespace detail {
template<class T>
struct tuple_size;

template<class T, class U>
struct tuple_size<std::pair<T, U>> : std::integral_constant<std::size_t, 2>
{};

template<class T, class U>
struct tuple_size<std::pair<T, U> const> : std::integral_constant<std::size_t, 2>
{};

template<class T, class U>
struct tuple_size<std::pair<T, U> volatile> : std::integral_constant<std::size_t, 2>
{};

template<class T, class U>
struct tuple_size<std::pair<T, U> const volatile> : std::integral_constant<std::size_t, 2>
{};

template<std::size_t I, class Tuple>
struct tuple_element;

template<std::size_t I, class T, class U>
struct tuple_element<I, std::pair<T, U>> : std::tuple_element<I, std::pair<T, U>>
{};

template<std::size_t I, class T, class U>
struct tuple_element<I, std::pair<T, U> const> : std::tuple_element<I, std::pair<T, U> const>
{};

template<std::size_t I, class T, class U>
struct tuple_element<I, std::pair<T, U> volatile> : std::tuple_element<I, std::pair<T, U> volatile>
{};

template<auto... Vs>
struct non_type_list;
template<std::size_t I, class T, class U>
struct tuple_element<I, std::pair<T, U> const volatile> : std::tuple_element<I, std::pair<T, U> const volatile>
{};

} // detail

template<class T>
struct adaptor;

template<class T, class U>
struct adaptor<std::pair<T, U>>
{
using getters_list = detail::non_type_list<&std::pair<T, U>::first, &std::pair<T, U>::second>;
using getters_list = detail::call_std_get<std::index_sequence<0, 1>>::type;
};

} // iris::alloy
Expand Down
61 changes: 41 additions & 20 deletions include/iris/alloy/adapted/std_tuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,63 @@

// SPDX-License-Identifier: MIT

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

#include <tuple>
#include <iris/alloy/detail/std_get.hpp>

#include <tuple> // IWYU pragma: export
#include <utility>

#include <cstddef>

namespace iris::alloy {

template<class T>
struct adaptor;
struct tuple_size;

namespace detail {
template<class... Ts>
struct tuple_size<std::tuple<Ts...>> : std::integral_constant<std::size_t, sizeof...(Ts)>
{};

template<std::size_t I>
struct call_std_get
{
template<class Tuple>
static constexpr decltype(auto) operator()(Tuple&& t)
{
return std::get<I>(static_cast<Tuple&&>(t));
}
};
template<class... Ts>
struct tuple_size<std::tuple<Ts...> const> : std::integral_constant<std::size_t, sizeof...(Ts)>
{};

template<std::size_t I>
struct make_call_std_get
{
static constexpr auto value = call_std_get<I>{};
};
template<class... Ts>
struct tuple_size<std::tuple<Ts...> volatile> : std::integral_constant<std::size_t, sizeof...(Ts)>
{};

} // detail
template<class... Ts>
struct tuple_size<std::tuple<Ts...> const volatile> : std::integral_constant<std::size_t, sizeof...(Ts)>
{};

template<std::size_t I, class Tuple>
struct tuple_element;

template<std::size_t I, class... Ts>
struct tuple_element<I, std::tuple<Ts...>> : std::tuple_element<I, std::tuple<Ts...>>
{};

template<std::size_t I, class... Ts>
struct tuple_element<I, std::tuple<Ts...> const> : std::tuple_element<I, std::tuple<Ts...> const>
{};

template<std::size_t I, class... Ts>
struct tuple_element<I, std::tuple<Ts...> volatile> : std::tuple_element<I, std::tuple<Ts...> volatile>
{};

template<std::size_t I, class... Ts>
struct tuple_element<I, std::tuple<Ts...> const volatile> : std::tuple_element<I, std::tuple<Ts...> const volatile>
{};


template<class T>
struct adaptor;

template<class... Ts>
struct adaptor<std::tuple<Ts...>>
{
using getters_list = detail::integer_seq_transform_t<std::make_index_sequence<sizeof...(Ts)>, detail::make_call_std_get>;
using getters_list = detail::call_std_get<std::index_sequence_for<Ts...>>::type;
};

} // iris::alloy
Expand Down
11 changes: 8 additions & 3 deletions include/iris/alloy/detail/deduce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,20 @@

// SPDX-License-Identifier: MIT

#include <iris/config.hpp> // IWYU pragma: keep

#include <type_traits>

namespace iris::alloy::detail {

template<class FromLValue, class FromXValue>
struct deduce
{
static_assert(std::conjunction_v<std::is_reference<FromLValue>, std::is_reference<FromXValue>,
std::is_same<std::remove_reference_t<FromLValue>, std::remove_reference_t<FromXValue>>>);
static_assert(std::conjunction_v<
std::is_reference<FromLValue>,
std::is_reference<FromXValue>,
std::is_same<std::remove_reference_t<FromLValue>, std::remove_reference_t<FromXValue>>
>);
};

template<class T>
Expand All @@ -33,7 +38,7 @@ struct deduce<T&&, T&&>
};

template<class FromLValue, class FromXValue>
using deduce_t = typename deduce<FromLValue, FromXValue>::type;
using deduce_t = deduce<FromLValue, FromXValue>::type;

} // iris::alloy::detail

Expand Down
27 changes: 0 additions & 27 deletions include/iris/alloy/detail/integer_seq_transform.hpp

This file was deleted.

37 changes: 37 additions & 0 deletions include/iris/alloy/detail/std_get.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#ifndef IRIS_ZZ_ALLOY_DETAIL_STD_GET_HPP
#define IRIS_ZZ_ALLOY_DETAIL_STD_GET_HPP

// SPDX-License-Identifier: MIT

#include <iris/config.hpp> // IWYU pragma: keep

#include <iris/type_traits.hpp>

#include <utility>

#include <cstddef> // IWYU pragma: keep

namespace iris::alloy::detail {

template<std::size_t I>
struct call_std_get_impl
{
template<class Tuple>
[[nodiscard]] static constexpr decltype(auto) operator()(Tuple&& t) noexcept
{
return std::get<I>(static_cast<Tuple&&>(t));
}
};

template<class Seq>
struct call_std_get;

template<std::size_t... Is>
struct call_std_get<std::index_sequence<Is...>>
{
using type = constant_list<call_std_get_impl<Is>{}...>;
};

} // iris::alloy::detail

#endif
3 changes: 2 additions & 1 deletion include/iris/alloy/detail/tuple_comparison.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

// SPDX-License-Identifier: MIT

#include <iris/config.hpp> // IWYU pragma: keep

#include <iris/requirements.hpp>

#include <concepts>
#include <type_traits>

namespace iris::alloy {
Expand Down
4 changes: 2 additions & 2 deletions include/iris/alloy/detail/tuple_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#ifndef IRIS_ALLOY_GENERATE_PREPROCESSED

#include <iris/config.hpp>
#include <iris/config.hpp> // IWYU pragma: keep

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

Expand All @@ -15,7 +15,7 @@

#include <type_traits>

#include <cstddef>
#include <cstddef> // IWYU pragma: keep

#endif

Expand Down
4 changes: 3 additions & 1 deletion include/iris/alloy/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@

// SPDX-License-Identifier: MIT

#include <iris/config.hpp> // IWYU pragma: keep

#include <iris/io_fwd.hpp>

#include <iris/alloy/tuple.hpp>

#include <ostream>
#include <utility>

#include <cstddef>
#include <cstddef> // IWYU pragma: keep

namespace iris::alloy {

Expand Down
Loading
Loading