Skip to content

Commit df44cd1

Browse files
committed
refactor(*): fixing compile errors
1 parent a52329c commit df44cd1

18 files changed

+583
-544
lines changed

include/stdsharp/cassert/cassert.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#pragma once
22

3+
#include "../concepts/concepts.h"
4+
#include "../namespace_alias.h"
5+
6+
#include <gsl/assert>
7+
38
#include <cassert>
49
#include <functional>
5-
#include <gsl/assert>
610

7-
#include "../namespace_alias.h"
8-
#include "../concepts/concepts.h"
9-
#include "../type_traits/core_traits.h"
1011

1112
namespace stdsharp
1213
{
@@ -21,7 +22,7 @@ namespace stdsharp
2122
inline constexpr auto assert_with =
2223
[]<typename... Args>(std::predicate<Args...> auto&& fn, Args&&... args) noexcept
2324
{
24-
Expects(invoke_r<bool>(fn, cpp_forward(args)...)); //
25+
Expects(std::invoke(fn, cpp_forward(args)...)); //
2526
};
2627

2728
inline constexpr auto assert_equal = []<typename T, typename U>(T&& t, U&& u) noexcept

include/stdsharp/functional/compose.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ namespace stdsharp::details
1111
noexcept( //
1212
composed_invoke<I + 1>(
1313
cpp_forward(fn),
14-
invoke_at<I>(cpp_forward(fn), cpp_forward(arg)...)
14+
cpp_forward(fn).get<I>()(cpp_forward(arg)...)
1515
)
1616
)
1717
)
1818
requires requires {
1919
composed_invoke<I + 1>(
2020
cpp_forward(fn),
21-
invoke_at<I>(cpp_forward(fn), cpp_forward(arg)...)
21+
cpp_forward(fn).get<I>()(cpp_forward(arg)...)
2222
);
2323
}
2424
{
2525
return composed_invoke<I + 1>(
2626
cpp_forward(fn),
27-
invoke_at<I>(cpp_forward(fn), cpp_forward(arg)...)
27+
cpp_forward(fn).get<I>()(cpp_forward(arg)...)
2828
);
2929
}
3030

include/stdsharp/functional/conditional_invoke.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ namespace stdsharp
1212
constexpr decltype(auto) operator()(Func&& func, const auto& /*unused*/ = empty_invoke) //
1313
const noexcept(nothrow_invocable<Func>)
1414
{
15-
return invoke(func);
15+
return invoke(cpp_forward(func));
1616
}
1717

1818
template<std::invocable Func = empty_invoke_fn>
1919
constexpr decltype(auto) operator()(const auto& /*unused*/, Func&& func = empty_invoke) //
2020
const noexcept(nothrow_invocable<Func>)
2121
{
22-
return invoke(func);
22+
return invoke(cpp_forward(func));
2323
}
2424
};
2525

include/stdsharp/functional/invocables.h

Lines changed: 42 additions & 163 deletions
Original file line numberDiff line numberDiff line change
@@ -1,208 +1,87 @@
11
#pragma once
22

33
#include "../type_traits/indexed_traits.h"
4+
#include "invoke.h"
45

5-
#include <algorithm>
6-
#include <functional>
6+
#include <tuple>
77

88
#include "../compilation_config_in.h"
99

10-
namespace stdsharp::details
11-
{
12-
template<typename... Func>
13-
struct invocables_traits
14-
{
15-
template<typename = std::index_sequence_for<Func...>>
16-
struct impl;
17-
18-
using type = impl<>;
19-
20-
template<std::size_t I>
21-
struct indexed_operator
22-
{
23-
template<
24-
typename Self,
25-
typename... Args,
26-
std::invocable<Args...> Fn = get_element_t<I, forward_cast_t<Self, type>>>
27-
constexpr decltype(auto) operator()(this Self&& self, Args&&... args)
28-
noexcept(nothrow_invocable<Fn, Args...>)
29-
{
30-
return invoke(
31-
cpo::get_element<I>(forward_cast<Self, type>(self)),
32-
cpp_forward(args)...
33-
);
34-
}
35-
};
36-
37-
using indexed_values = stdsharp::indexed_values<Func...>;
38-
39-
template<std::size_t... I>
40-
struct STDSHARP_EBO impl<std::index_sequence<I...>> : indexed_values, indexed_operator<I>...
41-
{
42-
using indexed_values::indexed_values;
43-
using indexed_operator<I>::operator()...;
44-
};
45-
};
46-
}
4710

4811
namespace stdsharp
4912
{
50-
template<typename... Func>
51-
struct invocables : details::invocables_traits<Func...>::type
13+
template<std::size_t I, typename Func>
14+
struct indexed_invocable : value_wrapper<Func>
5215
{
53-
private:
54-
using m_invocables = details::invocables_traits<Func...>::type;
55-
56-
public:
57-
template<typename... Args>
58-
requires std::constructible_from<m_invocables, Args...>
59-
constexpr invocables(Args&&... args)
60-
noexcept(nothrow_constructible_from<m_invocables, Args...>):
61-
m_invocables(cpp_forward(args)...)
16+
template<
17+
typename Self,
18+
typename... Args,
19+
std::invocable<Args...> Fn = forward_cast_t<Self, Func>>
20+
constexpr decltype(auto) operator()(this Self&& self, Args&&... args)
21+
noexcept(nothrow_invocable<Fn, Args...>)
6222
{
23+
return invoke(forward_cast<Self, indexed_invocable, Func>(self), cpp_forward(args)...);
6324
}
64-
65-
invocables() = default;
6625
};
26+
}
6727

68-
template<typename... T>
69-
invocables(T&&...) -> invocables<std::decay_t<T>...>;
28+
namespace stdsharp::details
29+
{
30+
template<typename...>
31+
struct invocables;
7032

71-
template<std::size_t Index>
72-
struct invoke_at_fn
33+
template<typename... Func, std::size_t... I>
34+
struct STDSHARP_EBO invocables<std::index_sequence<I...>, Func...> :
35+
indexed_invocable<I, Func>...
7336
{
74-
template<typename T, typename... Args>
75-
requires std::invocable<get_element_t<Index, T>, Args...>
76-
constexpr decltype(auto) operator()(T&& t, Args&&... args) const
77-
noexcept(nothrow_invocable<get_element_t<Index, T>, Args...>)
78-
{
79-
return cpo::get_element<Index>(t)(cpp_forward(args)...);
80-
}
81-
};
37+
static constexpr auto size() noexcept { return sizeof...(Func); }
8238

83-
template<auto Index>
84-
inline constexpr invoke_at_fn<Index> invoke_at{};
39+
template<std::size_t J>
40+
using type = type_at<J, Func...>;
8541

86-
template<template<typename> typename Predicator>
87-
struct invoke_first_fn
88-
{
89-
private:
90-
template<typename T, typename... Args, std::size_t I = 0>
91-
static constexpr std::size_t find_first(const index_constant<I> /*unused*/ = {}) noexcept
42+
template<std::size_t J, typename Self>
43+
constexpr forward_cast_t<Self, type<J>> get(this Self&& self) noexcept
9244
{
93-
if constexpr( //
94-
requires {
95-
requires I < std::tuple_size_v<std::decay_t<T>>;
96-
typename get_element_t<I, T>;
97-
} //
98-
)
99-
if constexpr(Predicator<get_element_t<I, T>>::template value<Args...>) return I;
100-
else return find_first<T, Args...>(index_constant<I + 1>{});
101-
else return static_cast<std::size_t>(-1);
45+
return forward_cast<Self, invocables, indexed_value<J, type<J>>>(self).get();
10246
}
10347

104-
template<typename T, typename... Args>
105-
static constexpr auto index = find_first<T, Args...>();
106-
107-
template<typename T, typename... Args>
108-
requires(index<T, Args...> != -1)
109-
using invoke_at_t = invoke_at_fn<index<T, Args...>>;
110-
111-
public:
112-
template<typename T, typename... Args>
113-
requires requires { typename invoke_at_t<T, Args...>; }
114-
constexpr decltype(auto) operator()(T&& t, Args&&... args) const
115-
noexcept(nothrow_invocable<invoke_at_t<T, Args...>, T, Args...>)
48+
template<std::size_t J, typename Self, typename SelfT = const Self>
49+
constexpr forward_cast_t<SelfT, type<J>> cget(this const Self&& self) noexcept
11650
{
117-
return invoke_at_t<T, Args...>{}(t, cpp_forward(args)...);
51+
return forward_cast<SelfT, invocables, indexed_value<J, type<J>>>(self).cget();
11852
}
119-
};
120-
121-
template<template<typename> typename Predicator>
122-
inline constexpr invoke_first_fn<Predicator> invoke_first{};
123-
124-
namespace details
125-
{
126-
template<typename Func>
127-
struct sequenced_invocables_predicate
128-
{
129-
template<typename... Args>
130-
static constexpr auto value = std::invocable<Func, Args...>;
131-
};
132-
}
133-
134-
using sequenced_invoke_fn = invoke_first_fn<details::sequenced_invocables_predicate>;
135-
136-
inline constexpr sequenced_invoke_fn sequenced_invoke{};
137-
138-
template<typename... Invocable>
139-
struct sequenced_invocables : invocables<Invocable...>
140-
{
141-
using base = invocables<Invocable...>;
142-
143-
using base::base;
144-
145-
sequenced_invocables() = default;
14653

147-
template<typename Self, typename... Args, typename Base = forward_cast_t<Self, base>>
148-
requires std::invocable<sequenced_invoke_fn, Base, Args...>
149-
constexpr decltype(auto) operator()(this Self&& self, Args&&... args)
150-
noexcept(nothrow_invocable<sequenced_invoke_fn, Base, Args...>)
54+
template<std::size_t J, typename Self, typename SelfT = const Self&>
55+
constexpr forward_cast_t<SelfT, type<J>> cget(this const Self& self) noexcept
15156
{
152-
return sequenced_invoke(
153-
forward_cast<Self, sequenced_invocables, base>(self),
154-
cpp_forward(args)...
155-
);
57+
return forward_cast<SelfT, invocables, indexed_value<J, type<J>>>(self).cget();
15658
}
15759
};
60+
}
15861

159-
template<typename... T>
160-
sequenced_invocables(T&&...) -> sequenced_invocables<std::decay_t<T>...>;
161-
162-
template<typename Func>
163-
struct nodiscard_invocable : invocables<Func>
62+
namespace stdsharp
63+
{
64+
template<typename... Func>
65+
struct invocables : details::invocables<std::index_sequence_for<Func...>, Func...>
16466
{
165-
using base = invocables<Func>;
166-
167-
using base::base;
168-
169-
template<typename Self, typename... Args, typename Base = forward_cast_t<Self, base>>
170-
requires std ::invocable<Base, Args...>
171-
[[nodiscard]] constexpr decltype(auto) operator()(this Self&& self, Args&&... args)
172-
noexcept(nothrow_invocable<Base, Args...>)
173-
{
174-
return forward_cast<Self, nodiscard_invocable, base>(self)(cpp_forward(args)...);
175-
}
17667
};
17768

178-
template<typename Func>
179-
nodiscard_invocable(Func&&) -> nodiscard_invocable<std::decay_t<Func>>;
69+
template<typename... T>
70+
invocables(T&&...) -> invocables<std::decay_t<T>...>;
18071
}
18172

18273
namespace std
18374
{
18475
template<typename... T>
185-
struct tuple_size<::stdsharp::invocables<T...>> :
186-
::std::tuple_size<::stdsharp::indexed_types<T...>>
187-
{
188-
};
189-
190-
template<std::size_t I, typename... T>
191-
struct tuple_element<I, ::stdsharp::invocables<T...>> :
192-
::std::tuple_element<I, ::stdsharp::indexed_types<T...>>
193-
{
194-
};
195-
196-
template<typename... T>
197-
struct tuple_size<::stdsharp::sequenced_invocables<T...>> :
198-
::std::tuple_size<::stdsharp::invocables<T...>>
76+
struct tuple_size<::stdsharp::invocables<T...>>
19977
{
78+
static constexpr auto value = ::stdsharp::invocables<T...>::size();
20079
};
20180

20281
template<std::size_t I, typename... T>
203-
struct tuple_element<I, ::stdsharp::sequenced_invocables<T...>> :
204-
::std::tuple_element<I, ::stdsharp::invocables<T...>>
82+
struct tuple_element<I, ::stdsharp::invocables<T...>>
20583
{
84+
using type = ::stdsharp::invocables<T...>::template type<I>;
20685
};
20786
}
20887

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#pragma once
2+
3+
#include "../utility/value_wrapper.h"
4+
#include "invoke.h"
5+
6+
namespace stdsharp
7+
{
8+
template<typename Func>
9+
struct nodiscard_invocable : value_wrapper<Func>
10+
{
11+
template<
12+
typename Self,
13+
typename... Args,
14+
std ::invocable<Args...> Fn = forward_cast_t<Self, Func>>
15+
[[nodiscard]] constexpr decltype(auto) operator()(this Self&& self, Args&&... args)
16+
noexcept(nothrow_invocable<Fn, Args...>)
17+
{
18+
return invoke(
19+
forward_cast<Self, nodiscard_invocable>(self).get(),
20+
cpp_forward(args)...
21+
);
22+
}
23+
};
24+
25+
template<typename Func>
26+
nodiscard_invocable(Func&&) -> nodiscard_invocable<std::decay_t<Func>>;
27+
}

0 commit comments

Comments
 (0)