libcopp  2.2.0
algorithm.h
Go to the documentation of this file.
1 // Copyright 2023 owent
2 
3 #pragma once
4 
5 #include <libcopp/utils/config/libcopp_build_features.h>
6 
7 // clang-format off
8 #include <libcopp/utils/config/stl_include_prefix.h> // NOLINT(build/include_order)
9 // clang-format on
10 #include <type_traits>
11 #if defined(LIBCOPP_MACRO_ENABLE_CONCEPTS) && LIBCOPP_MACRO_ENABLE_CONCEPTS
12 # include <concepts>
13 #endif
14 // clang-format off
15 #include <libcopp/utils/config/stl_include_suffix.h> // NOLINT(build/include_order)
16 // clang-format on
17 
19 #include "libcopp/utils/gsl/span.h"
20 
21 #if defined(LIBCOPP_MACRO_ENABLE_STD_COROUTINE) && LIBCOPP_MACRO_ENABLE_STD_COROUTINE
22 
23 LIBCOPP_COPP_NAMESPACE_BEGIN
24 
25 template <class TWAITING_CONTAINER>
26 struct LIBCOPP_COPP_API_HEAD_ONLY some_waiting_container_traits {
27  using element_type = typename std::remove_pointer<decltype(gsl::data(std::declval<TWAITING_CONTAINER>()))>::type;
28  using value_type = typename std::remove_reference<
29  typename std::decay<decltype(pick_some_reference<typename std::remove_reference<element_type>::type>::unwrap(
30  std::declval<typename std::add_lvalue_reference<element_type>::type>()))>::type>::type;
31 };
32 
33 # if defined(LIBCOPP_MACRO_ENABLE_CONCEPTS) && LIBCOPP_MACRO_ENABLE_CONCEPTS
34 template <class TREADY_ELEMENT, class TWAITING_ELEMENT>
35 concept SomeContainerConvertible =
36  std::same_as<TWAITING_ELEMENT, TREADY_ELEMENT> || std::convertible_to<TWAITING_ELEMENT*, TREADY_ELEMENT*>;
37 # else
38 template <class TREADY_ELEMENT, class TWAITING_ELEMENT>
39 struct LIBCOPP_COPP_API_HEAD_ONLY some_container_convertible
40  : std::enable_if<std::is_same<TWAITING_ELEMENT, TREADY_ELEMENT>::value ||
41  std::is_convertible<TWAITING_ELEMENT*, TREADY_ELEMENT*>::value> {};
42 # endif
43 
44 template <class TREADY_CONTAINER, class TWAITING_CONTAINER
45 # if !(defined(LIBCOPP_MACRO_ENABLE_CONCEPTS) && LIBCOPP_MACRO_ENABLE_CONCEPTS)
46  ,
47  class = typename some_container_convertible<
50 # endif
51  >
52 LIBCOPP_COPP_API_HEAD_ONLY inline callable_future<promise_status> some(TREADY_CONTAINER&& ready_futures,
53  size_t ready_count,
54  TWAITING_CONTAINER&& pending_futures)
55 # if defined(LIBCOPP_MACRO_ENABLE_CONCEPTS) && LIBCOPP_MACRO_ENABLE_CONCEPTS
56  // clang-format off
57  requires SomeContainerConvertible<
60  >
61 // clang-format on
62 # endif
63 {
65  std::forward<TREADY_CONTAINER>(ready_futures), ready_count, &pending_futures);
66 }
67 
68 template <class TREADY_CONTAINER, class TWAITING_CONTAINER
69 # if !(defined(LIBCOPP_MACRO_ENABLE_CONCEPTS) && LIBCOPP_MACRO_ENABLE_CONCEPTS)
70  ,
71  class = typename some_container_convertible<
74 # endif
75  >
76 LIBCOPP_COPP_API_HEAD_ONLY inline callable_future<promise_status> any(TREADY_CONTAINER&& ready_futures,
77  TWAITING_CONTAINER&& pending_futures)
78 # if defined(LIBCOPP_MACRO_ENABLE_CONCEPTS) && LIBCOPP_MACRO_ENABLE_CONCEPTS
79  // clang-format off
80  requires SomeContainerConvertible<
83  >
84 // clang-format on
85 # endif
86 {
88  std::forward<TREADY_CONTAINER>(ready_futures), 1, &pending_futures);
89 }
90 
91 template <class TREADY_CONTAINER, class TWAITING_CONTAINER
92 # if !(defined(LIBCOPP_MACRO_ENABLE_CONCEPTS) && LIBCOPP_MACRO_ENABLE_CONCEPTS)
93  ,
94  class = typename some_container_convertible<
97 # endif
98  >
99 LIBCOPP_COPP_API_HEAD_ONLY inline callable_future<promise_status> all(TREADY_CONTAINER&& ready_futures,
100  TWAITING_CONTAINER&& pending_futures)
101 # if defined(LIBCOPP_MACRO_ENABLE_CONCEPTS) && LIBCOPP_MACRO_ENABLE_CONCEPTS
102  // clang-format off
103  requires SomeContainerConvertible<
106  >
107 // clang-format on
108 # endif
109 {
111  std::forward<TREADY_CONTAINER>(ready_futures), gsl::size(pending_futures), &pending_futures);
112 }
113 
114 LIBCOPP_COPP_NAMESPACE_END
115 
116 #endif
constexpr auto size(TCONTAINER &&container) -> decltype(container.size())
Definition: span.h:44
std::shared_ptr< cli::cmd_option_value > value_type
Definition: cmd_option.h:50