Skip to content

Commit 4efa0f6

Browse files
committed
fix(forward-cast): fixing
1 parent df44cd1 commit 4efa0f6

File tree

14 files changed

+528
-428
lines changed

14 files changed

+528
-428
lines changed

include/stdsharp/functional/always_return.h

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,38 @@ namespace stdsharp
88
{
99
inline constexpr struct always_return_fn
1010
{
11-
constexpr decltype(auto) operator()(auto&& v, const auto&... /*unused*/) const noexcept
11+
[[nodiscard]] constexpr decltype(auto
12+
) operator()(auto&& v, const auto&... /*unused*/) const noexcept
1213
{
1314
return cpp_forward(v);
1415
}
1516
} always_return{};
1617

17-
inline constexpr auto always_true = std::bind_front(always_return, true);
18-
19-
using always_true_fn = decltype(always_true);
20-
21-
inline constexpr auto always_false = std::bind_front(always_return, false);
18+
inline constexpr struct always_true_fn
19+
{
20+
[[nodiscard]] constexpr bool operator()(const auto&... /*unused*/) const noexcept
21+
{
22+
return true;
23+
}
24+
} always_true{};
2225

23-
using always_false_fn = decltype(always_false);
26+
inline constexpr struct always_false_fn
27+
{
28+
[[nodiscard]] constexpr bool operator()(const auto&... /*unused*/) const noexcept
29+
{
30+
return false;
31+
}
32+
} always_false{};
2433

2534
template<typename T>
26-
inline constexpr auto always_default = std::bind_front(always_return, T{});
35+
struct always_default_fn
36+
{
37+
[[nodiscard]] constexpr auto operator()(const auto&... /*unused*/) const noexcept
38+
{
39+
return T{};
40+
}
41+
};
2742

2843
template<typename T>
29-
using always_default_fn = decltype(always_default<T>);
44+
inline constexpr always_default_fn<T> always_default{};
3045
}

include/stdsharp/functional/sequenced_invocables.h

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

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

56
#include <tuple>
67

@@ -22,7 +23,7 @@ namespace stdsharp::details
2223
{
2324
using fn = forward_cast_t<Self, type<J>>;
2425

25-
if constexpr(std::invocable<fn, Args...>) return type_constant<indexed_value<J, fn>>{};
26+
if constexpr(std::invocable<fn, Args...>) return J;
2627
else return first_invocable<Self, J + 1, Args...>();
2728
}
2829

@@ -55,11 +56,13 @@ namespace stdsharp::details
5556
template<
5657
typename Self,
5758
typename... Args,
58-
std::invocable<Args...> Fn = decltype(first_invocable<0, Args...>())::type>
59+
auto J = first_invocable<Self, 0, Args...>(),
60+
std::invocable<Args...> Fn = forward_cast_t<Self, type<J>>>
5961
constexpr decltype(auto) operator()(this Self&& self, Args&&... args)
6062
noexcept(nothrow_invocable<Fn, Args...>)
6163
{
62-
return invoke(forward_cast<Self, sequenced_invocables, Fn>(self), cpp_forward(args)...);
64+
auto&& fn = forward_cast<Self, sequenced_invocables>(self).template get<J>();
65+
return invoke(cpp_forward(fn), cpp_forward(args)...);
6366
}
6467
};
6568
}

include/stdsharp/type_traits/indexed_traits.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,19 @@ namespace stdsharp::details
1717
consteval type_constant<T> get() const noexcept { return {}; }
1818
};
1919

20+
template<std::size_t>
2021
struct invalid
2122
{
2223
};
2324

24-
template<>
25-
struct filter<invalid>
26-
{
27-
};
28-
2925
public:
3026
template<std::size_t I, std::size_t... J, typename... T>
3127
static consteval auto impl(
3228
const std::index_sequence<J...> /*unused*/,
3329
const basic_type_sequence<T...> /*unused*/
3430
)
3531
{
36-
constexpr struct : filter<std::conditional_t<I == J, T, invalid>>...
32+
constexpr struct STDSHARP_EBO : std::conditional_t<I == J, filter<T>, invalid<J>>...
3733
{
3834
} f{};
3935

include/stdsharp/type_traits/object.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11

22
#pragma once
33

4+
#include "../concepts/object.h"
45
#include "expression.h"
56
#include "regular_type_sequence.h"
6-
#include "../concepts/object.h"
7+
78

89
namespace stdsharp
910
{

include/stdsharp/type_traits/regular_value_sequence.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ namespace stdsharp
7777
using make_index_sequence = make_integer_sequence<std::size_t, N>;
7878

7979
template<auto From, std::size_t Size, auto PlusF = std::plus{}>
80-
using make_value_sequence_t =
80+
using make_value_sequence =
8181
decltype(details::make_value_sequence<From, PlusF>(std::make_index_sequence<Size>{}));
8282

8383
template<typename... T>

0 commit comments

Comments
 (0)