Skip to content

Commit ca43094

Browse files
committed
added meta::transform
1 parent 86559bf commit ca43094

File tree

5 files changed

+83
-25
lines changed

5 files changed

+83
-25
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// include/beman/execution26/detail/meta_transform.hpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#ifndef INCLUDED_BEMAN_EXECUTION26_DETAIL_META_TRANSFORM
5+
#define INCLUDED_BEMAN_EXECUTION26_DETAIL_META_TRANSFORM
6+
7+
#include <beman/execution26/detail/meta_contains.hpp>
8+
9+
// ----------------------------------------------------------------------------
10+
11+
namespace beman::execution26::detail::meta::detail
12+
{
13+
template <template <typename> class Transform, typename List> struct transform;
14+
15+
template <template <typename> class Transform,
16+
template <typename... T> class List,
17+
typename... T>
18+
struct transform<Transform, List<T...>>
19+
{
20+
using type = List<Transform<T>...>;
21+
};
22+
}
23+
24+
namespace beman::execution26::detail::meta
25+
{
26+
template <template <typename> class Transform, typename List>
27+
using transform = typename
28+
::beman::execution26::detail::meta::detail::transform<Transform, List>
29+
::type;
30+
}
31+
32+
// ----------------------------------------------------------------------------
33+
34+
#endif

include/beman/execution26/detail/meta_unique.hpp

-25
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,6 @@ namespace beman::execution26::detail::meta::detail
1616
template <typename, typename> struct make_unique;
1717
template <typename> struct unique;
1818

19-
#if 0
20-
21-
template <template <typename...> class List>
22-
struct unique<List<>>
23-
{
24-
using type = List<>;
25-
};
26-
template <template <typename...> class List, typename T>
27-
struct unique<List<T>>
28-
{
29-
using type = List<T>;
30-
};
31-
32-
template <template <typename...> class List, typename H, typename... T>
33-
struct unique<List<H, T...>>
34-
{
35-
using tail = ::beman::execution26::detail::meta::detail::unique<List<T...>>::type;
36-
using type = ::std::conditional_t<
37-
::beman::execution26::detail::meta::contains<H, T...>,
38-
tail,
39-
::beman::execution26::detail::meta::prepend<H, tail>
40-
>;
41-
};
42-
#else
4319
template <template <typename...> class List, typename... R>
4420
struct make_unique<List<R...>, List<>>
4521
{
@@ -67,7 +43,6 @@ namespace beman::execution26::detail::meta::detail
6743
List<T...>
6844
>::type;
6945
};
70-
#endif
7146
}
7247

7348
namespace beman::execution26::detail::meta

src/beman/execution26/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ target_sources(${TARGET_LIBRARY}
8484
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/meta_contains.hpp
8585
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/meta_filter.hpp
8686
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/meta_prepend.hpp
87+
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/meta_transform.hpp
8788
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/meta_unique.hpp
8889
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/movable_value.hpp
8990
${PROJECT_SOURCE_DIR}/include/beman/execution26/detail/never_stop_token.hpp

src/beman/execution26/tests/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33

44
list(APPEND execution_tests
5+
meta-transform.pass
56
exec-then.pass
67
exec-read-env.pass
78
exec-get-delegation-scheduler.pass
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// src/beman/execution26/tests/meta-transform.pass.cpp -*-C++-*-
2+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
3+
4+
#include <beman/execution26/detail/meta_transform.hpp>
5+
#include <beman/execution26/detail/type_list.hpp>
6+
#include <test/execution.hpp>
7+
#include <concepts>
8+
#include <type_traits>
9+
10+
// ----------------------------------------------------------------------------
11+
12+
namespace
13+
{
14+
template <typename>
15+
struct foo {};
16+
template <typename T>
17+
using bar = foo<T>;
18+
19+
template <typename T>
20+
struct baz { using type = foo<T>; };
21+
template <typename T>
22+
using baz_t = typename baz<T>::type;;
23+
}
24+
25+
auto main() -> int
26+
{
27+
static_assert(std::same_as<
28+
test_detail::type_list<>,
29+
test_detail::meta::transform<foo, test_detail::type_list<>>
30+
>);
31+
static_assert(std::same_as<
32+
test_detail::type_list<foo<bool>, foo<char>>,
33+
test_detail::meta::transform<foo, test_detail::type_list<bool, char>>
34+
>);
35+
static_assert(std::same_as<
36+
test_detail::type_list<foo<bool>, foo<char>>,
37+
test_detail::meta::transform<bar, test_detail::type_list<bool, char>>
38+
>);
39+
static_assert(std::same_as<
40+
test_detail::type_list<foo<bool>, foo<char>>,
41+
test_detail::meta::transform<baz_t, test_detail::type_list<bool, char>>
42+
>);
43+
static_assert(std::same_as<
44+
test_detail::type_list<bool, char>,
45+
test_detail::meta::transform<std::type_identity_t, test_detail::type_list<bool, char>>
46+
>);
47+
}

0 commit comments

Comments
 (0)