Skip to content

Commit cd52820

Browse files
authored
implement indexed_tuple with different get method (#58)
* implement indexed_tuple with different get method * workaround clang bug with base class pack * fix indexed_tuple.cpp includes * replace all usage of std::tuple with indexed_tuple * replace ordered_set with indexed_tuple * cleanup tuple * make cib::detail::tuple cib::tuple * cleanup cib::tuple * multi index testcase for tuple * remove unused tuple_details.hpp * add support for cib::tuple set operations * workarounds for gcc * fully qualify calls to cib::make_tuple * add test case for cib::detail::name * fix test case
1 parent 8be8566 commit cd52820

26 files changed

+1124
-503
lines changed

Diff for: include/cib/cib.hpp

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@
4343
#include "built.hpp"
4444
#include "config.hpp"
4545
#include "builder_meta.hpp"
46+
#include "set.hpp"
47+
#include "tuple.hpp"
4648

4749

4850
#endif //COMPILE_TIME_INIT_BUILD_CIB_HPP

Diff for: include/cib/config.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include "detail/extend.hpp"
1111
#include "detail/config_item.hpp"
1212

13-
#include <tuple>
1413
#include <type_traits>
1514

1615

Diff for: include/cib/detail/components.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "compiler.hpp"
22
#include "config_item.hpp"
33
#include "meta.hpp"
4-
#include "ordered_set.hpp"
4+
#include "../tuple.hpp"
55
#include "type_list.hpp"
66

77
#include <type_traits>
@@ -19,7 +19,7 @@ namespace cib::detail {
1919
Builders const & builders_tuple,
2020
Args const & ... args
2121
) const {
22-
return detail::fold_right(ordered_set{Components{}...}, builders_tuple, [&](auto const & c, auto const & builders){
22+
return detail::fold_right(cib::make_tuple(Components{}...), builders_tuple, [&](auto const & c, auto const & builders){
2323
return c.config.init(builders, args...);
2424
});
2525
}

Diff for: include/cib/detail/conditional.hpp

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
#include "compiler.hpp"
22
#include "config_item.hpp"
33
#include "config_details.hpp"
4-
#include "ordered_set.hpp"
54
#include "type_list.hpp"
6-
7-
#include <tuple>
5+
#include "../tuple.hpp"
86

97

108
#ifndef COMPILE_TIME_INIT_BUILD_CONDITIONAL_HPP
@@ -72,7 +70,7 @@ namespace cib::detail {
7270

7371
template<typename... Args>
7472
CIB_CONSTEVAL auto operator()(Args... args) const {
75-
return detail::fold_right(std::make_tuple(args...), detail::int_<0>, [=](auto elem, [[maybe_unused]] auto state){
73+
return detail::fold_right(cib::make_tuple(self_type_index, args...), detail::int_<0>, [=](auto elem, [[maybe_unused]] auto state){
7674
using ElemType = typename std::remove_cv_t<std::remove_reference_t<decltype(elem)>>::value_type;
7775

7876
if constexpr (std::is_same_v<ElemType, MatchType>) {

Diff for: include/cib/detail/config_details.hpp

+4-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
#include "compiler.hpp"
22
#include "config_item.hpp"
33
#include "meta.hpp"
4-
#include "ordered_set.hpp"
4+
#include "../tuple.hpp"
55
#include "type_list.hpp"
66

7-
#include <tuple>
8-
97

108
#ifndef COMPILE_TIME_INIT_BUILD_DETAIL_CONFIG_HPP
119
#define COMPILE_TIME_INIT_BUILD_DETAIL_CONFIG_HPP
@@ -17,18 +15,18 @@ namespace cib::detail {
1715

1816
template<auto... Args>
1917
struct args {
20-
static CIB_CONSTEXPR auto value = ordered_set{as_constant_v<Args>...};
18+
static CIB_CONSTEXPR auto value = cib::make_tuple(self_type_index, as_constant_v<Args>...);
2119
};
2220

2321
template<typename ConfigArgs, typename... ConfigTs>
2422
struct config : public detail::config_item {
25-
std::tuple<ConfigTs...> configs_tuple;
23+
cib::tuple<ConfigTs...> configs_tuple;
2624

2725
CIB_CONSTEVAL explicit config(
2826
ConfigArgs,
2927
ConfigTs const & ... configs
3028
)
31-
: configs_tuple{configs...}
29+
: configs_tuple{cib::make_tuple(configs...)}
3230
{
3331
// pass
3432
}

Diff for: include/cib/detail/config_item.hpp

-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
#include "compiler.hpp"
2-
#include "ordered_set.hpp"
32
#include "type_list.hpp"
43

5-
#include <tuple>
6-
74

85
#ifndef COMPILE_TIME_INIT_BUILD_CONFIG_DETAIL_HPP
96
#define COMPILE_TIME_INIT_BUILD_CONFIG_DETAIL_HPP

Diff for: include/cib/detail/exports.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
#include "type_list.hpp"
44
#include "builder_traits.hpp"
55

6-
#include <tuple>
76
#include <utility>
87

98

Diff for: include/cib/detail/extend.hpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "config_item.hpp"
2-
#include "ordered_set.hpp"
2+
#include "../tuple.hpp"
33

4-
#include <tuple>
54
#include <utility>
65

76

@@ -14,12 +13,12 @@ namespace cib::detail {
1413
typename ExtensionPath,
1514
typename... Args>
1615
struct extend : public config_item {
17-
ordered_set<Args...> args_tuple;
16+
cib::tuple<Args...> args_tuple;
1817

1918
CIB_CONSTEVAL explicit extend(
2019
Args const & ... args
2120
)
22-
: args_tuple{args...}
21+
: args_tuple{cib::make_tuple(args...)}
2322
{
2423
// pass
2524
}
@@ -76,7 +75,7 @@ namespace cib::detail {
7675
(is_same_v<typename ExtensionPath::First, typename std::remove_cv_t<std::remove_reference_t<decltype(builders)>>::Service> + ... + 0) <= 1,
7776
"Extension matched more than 1 service");
7877

79-
return detail::ordered_set(add(ExtensionPath{}, builders)...);
78+
return cib::make_tuple(index_metafunc_<extract_service_tag>, add(ExtensionPath{}, builders)...);
8079
}, builders_tuple);
8180
}
8281

Diff for: include/cib/detail/find.hpp

-126
This file was deleted.

Diff for: include/cib/detail/meta.hpp

+6-56
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include "compiler.hpp"
2-
#include "ordered_set.hpp"
2+
#include "../tuple.hpp"
33

4-
#include <tuple>
54
#include <type_traits>
65

76

@@ -55,7 +54,7 @@ namespace cib::detail {
5554
};
5655

5756
/**
58-
* fold_right a ordered_set of elements.
57+
* fold_right a tuple of elements.
5958
*
6059
* Fold operations are sometimes called accumulate or reduce in other
6160
* languages or libraries.
@@ -66,7 +65,7 @@ namespace cib::detail {
6665
* A callable that takes the current element being processed
6766
* and the current state, and returns the state to be used
6867
* to process the next element. Called for each element in
69-
* the ordered_set.
68+
* the tuple.
7069
*
7170
* @return
7271
* The final state of all of the operations.
@@ -76,7 +75,7 @@ namespace cib::detail {
7675
typename InitType,
7776
typename CallableType>
7877
[[nodiscard]] CIB_CONSTEXPR inline static auto fold_right(
79-
std::tuple<ElementTypes...> const & elements,
78+
tuple_impl<ElementTypes...> const & elements,
8079
InitType const & initial_state,
8180
CallableType const & operation
8281
) {
@@ -85,37 +84,6 @@ namespace cib::detail {
8584
}, elements);
8685
}
8786

88-
/**
89-
* fold_right a ordered_set of elements.
90-
*
91-
* Fold operations are sometimes called accumulate or reduce in other
92-
* languages or libraries.
93-
*
94-
* https://en.wikipedia.org/wiki/Fold_%28higher-order_function%29
95-
*
96-
* @param operation
97-
* A callable that takes the current element being processed
98-
* and the current state, and returns the state to be used
99-
* to process the next element. Called for each element in
100-
* the ordered_set.
101-
*
102-
* @return
103-
* The final state of all of the operations.
104-
*/
105-
template<
106-
typename... ElementTypes,
107-
typename InitType,
108-
typename CallableType>
109-
[[nodiscard]] CIB_CONSTEXPR inline static auto fold_right(
110-
ordered_set<ElementTypes...> const & elements,
111-
InitType const & initial_state,
112-
CallableType const & operation
113-
) {
114-
return apply([&](auto const & ... element_pack){
115-
return (fold_helper{element_pack, operation} + ... + initial_state);
116-
}, elements);
117-
}
118-
11987
/**
12088
* Perform an operation on each element of an integral sequence.
12189
*
@@ -153,7 +121,7 @@ namespace cib::detail {
153121
}
154122

155123
/**
156-
* Perform an operation on each element of a ordered_set.
124+
* Perform an operation on each element of a tuple.
157125
*
158126
* @param operation
159127
* The operation to perform. Must be a callable that accepts a single parameter.
@@ -162,31 +130,13 @@ namespace cib::detail {
162130
typename... ElementTypes,
163131
typename CallableType>
164132
CIB_CONSTEXPR inline void for_each(
165-
std::tuple<ElementTypes...> const & elements,
133+
tuple_impl<ElementTypes...> const & elements,
166134
CallableType const & operation
167135
) {
168136
apply([&](auto const & ... element_pack){
169137
(operation(element_pack) , ...);
170138
}, elements);
171139
}
172-
173-
/**
174-
* Perform an operation on each element of a ordered_set.
175-
*
176-
* @param operation
177-
* The operation to perform. Must be a callable that accepts a single parameter.
178-
*/
179-
template<
180-
typename... ElementTypes,
181-
typename CallableType>
182-
CIB_CONSTEXPR inline void for_each(
183-
ordered_set<ElementTypes...> const & elements,
184-
CallableType const & operation
185-
) {
186-
apply([&](auto const & ... element_pack){
187-
(operation(element_pack) , ...);
188-
}, elements);
189-
}
190140
}
191141

192142

0 commit comments

Comments
 (0)