OGS
Get.h
Go to the documentation of this file.
1
10#pragma once
11
12#include <boost/mp11.hpp>
13
15
16namespace ProcessLib::Graph
17{
18namespace detail
19{
20template <typename T, typename Tuple, typename... Tuples>
21auto& getImpl(Tuple& t, Tuples&... ts)
22{
23 using namespace boost::mp11;
24
25 using PlainTuple = std::remove_cv_t<Tuple>;
26 using TupleOfPlainTypes = mp_transform<std::remove_cvref_t, PlainTuple>;
27 using Index = mp_find<TupleOfPlainTypes, T>;
28
29 if constexpr (Index::value != mp_size<PlainTuple>::value)
30 {
31 return std::get<Index::value>(t);
32 }
33 else
34 {
35 return getImpl<T>(ts...);
36 }
37}
38
39template <typename... Tuples>
41{
42 // This check is necessary only to ensure that mp_flatten works as expected.
43 static_assert(boost::mp11::mp_similar<std::tuple<>, Tuples...>::value,
44 "All template arguments must be std::tuple's.");
45
46 using type = boost::mp11::mp_flatten<std::tuple<Tuples...>>;
47};
48} // namespace detail
49
58template <typename T, typename... Tuples>
59auto& get(Tuples&... ts)
60{
61 using namespace boost::mp11;
62
63 static_assert(std::is_same_v<T, std::remove_cvref_t<T>>,
64 "The passed type T must not be cvref qualified.");
65
66 using FlattenedTuple = typename detail::GetFlattenedTupleTypes<
67 std::remove_cv_t<Tuples>...>::type;
68 using FlattenedTupleOfPlainTypes =
69 mp_transform<std::remove_cvref_t, FlattenedTuple>;
70
71 static_assert(
72 mp_is_set_v<FlattenedTupleOfPlainTypes>,
73 "The types of all elements of all passed tuples must be unique.");
74
75 static_assert(mp_contains_v<FlattenedTupleOfPlainTypes, T>,
76 "Type T must be inside any of the passed tuples.");
77
78 return detail::getImpl<T>(ts...);
79}
80
81} // namespace ProcessLib::Graph
auto & getImpl(Tuple &t, Tuples &... ts)
Definition Get.h:21
auto & get(Tuples &... ts)
Definition Get.h:59
boost::mp11::mp_flatten< std::tuple< Tuples... > > type
Definition Get.h:46