Skip to content

Commit fbf1186

Browse files
committed
fix(forward-cast): applied deducing this
1 parent 51da52c commit fbf1186

File tree

4 files changed

+38
-80
lines changed

4 files changed

+38
-80
lines changed

include/stdsharp/synchronizer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include <shared_mutex>
44

55
#include "mutex/mutex.h"
6-
#include "utility/forward_cast.h"
6+
#include "utility/utility.h"
77

88
namespace stdsharp
99
{
@@ -53,7 +53,7 @@ namespace stdsharp
5353
.value = static_cast<cast_t>(value),
5454
.lock =
5555
Lock{
56-
static_cast<lock_type&>(forward_cast<Self, synchronizer&>(self).lockable_),
56+
as_lvalue(forward_cast<Self, synchronizer>(self)).lockable_,
5757
cpp_forward(args)...
5858
}
5959
};

include/stdsharp/type_traits/core_traits.h

Lines changed: 28 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ namespace stdsharp
127127
using ref_collapse_t = typename ref_collapse<T, U...>::type;
128128

129129
template<typename T, typename... U>
130+
using const_collapse_t = std::
131+
conditional_t<(std::is_const_v<T> || ... || std::is_const_v<U>), std::add_const_t<T>, T>;
130132
}
131133

132134
namespace stdsharp::details
@@ -484,98 +486,47 @@ namespace stdsharp
484486

485487
template<typename T>
486488
inline constexpr std::string_view type_id = ::nameof::nameof_full_type<T>();
489+
}
487490

488-
namespace literals
491+
namespace stdsharp::literals
492+
{
493+
template<std::size_t Size>
494+
struct ltr : std::array<char, Size>
489495
{
490-
template<std::size_t Size>
491-
struct ltr : std::array<char, Size>
492-
{
493-
private:
494-
using array_t = const char (&)[Size]; // NOLINT(*-avoid-c-arrays)
495-
496-
public:
497-
using base = std::array<char, Size>;
498-
using base::base;
499-
500-
constexpr ltr(array_t arr) noexcept { std::ranges::copy(arr, base::begin()); }
496+
private:
497+
using array_t = const char (&)[Size]; // NOLINT(*-avoid-c-arrays)
501498

502-
constexpr ltr& operator=(array_t arr) noexcept
503-
{
504-
std::ranges::copy(arr, base::begin());
505-
return *this;
506-
}
499+
public:
500+
using base = std::array<char, Size>;
501+
using base::base;
507502

508-
[[nodiscard]] constexpr operator std::string_view() const noexcept
509-
{
510-
return {base::data(), Size - 1};
511-
}
503+
constexpr ltr(array_t arr) noexcept { std::ranges::copy(arr, base::begin()); }
512504

513-
[[nodiscard]] constexpr auto to_string_view() const noexcept
514-
{
515-
return static_cast<std::string_view>(*this);
516-
}
517-
};
518-
519-
template<std::size_t Size>
520-
ltr(const char (&)[Size]) -> ltr<Size>; // NOLINT(*-avoid-c-arrays)
521-
522-
template<ltr Ltr>
523-
[[nodiscard]] constexpr auto operator""_ltr() noexcept
505+
constexpr ltr& operator=(array_t arr) noexcept
524506
{
525-
return Ltr;
507+
std::ranges::copy(arr, base::begin());
508+
return *this;
526509
}
527-
}
528-
}
529510

530-
namespace stdsharp::details
531-
{
532-
template<typename T>
533-
struct ebo_union
534-
{
535-
union type
511+
[[nodiscard]] constexpr operator std::string_view() const noexcept
536512
{
537-
T v;
538-
};
539-
};
513+
return {base::data(), Size - 1};
514+
}
540515

541-
template<typename T>
542-
requires std::is_empty_v<T>
543-
struct ebo_union<T>
544-
{
545-
union type
516+
[[nodiscard]] constexpr auto to_string_view() const noexcept
546517
{
547-
STDSHARP_NO_UNIQUE_ADDRESS T v;
548-
};
518+
return static_cast<std::string_view>(*this);
519+
}
549520
};
550521

551-
template<
552-
typename T,
553-
typename Tuple,
554-
typename = std::make_index_sequence<std::tuple_size_v<Tuple>>>
555-
struct piecewise_traits;
522+
template<std::size_t Size>
523+
ltr(const char (&)[Size]) -> ltr<Size>; // NOLINT(*-avoid-c-arrays)
556524

557-
template<typename T, typename Tuple, std::size_t... I>
558-
struct piecewise_traits<T, Tuple, std::index_sequence<I...>>
525+
template<ltr Ltr>
526+
[[nodiscard]] constexpr auto operator""_ltr() noexcept
559527
{
560-
static constexpr auto constructible_from =
561-
requires { requires std::constructible_from<T, get_element_t<I, Tuple>...>; };
562-
563-
static constexpr auto nothrow_constructible_from =
564-
requires { requires std::is_nothrow_constructible_v<T, get_element_t<I, Tuple>...>; };
565-
};
566-
}
567-
568-
namespace stdsharp
569-
{
570-
template<typename T>
571-
using ebo_union = details::ebo_union<T>::type;
572-
573-
template<typename T, typename Tuple>
574-
concept piecewise_constructible_from = details::piecewise_traits<T, Tuple>::constructible_from;
575-
576-
template<typename T, typename Tuple>
577-
concept piecewise_nothrow_constructible_from =
578-
details::piecewise_traits<T, Tuple>::nothrow_constructible_from;
528+
return Ltr;
529+
}
579530
}
580531

581532
namespace meta::extension

include/stdsharp/utility/utility.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ namespace stdsharp
2525

2626
template<typename T, typename U>
2727
using forward_like_t = decltype(forward_like<T>(std::declval<U>()));
28+
29+
inline constexpr struct as_lvalue_fn
30+
{
31+
STDSHARP_INTRINSIC constexpr auto& operator()(auto&& t) const noexcept { return t; }
32+
33+
void operator()(const auto&& t) = delete;
34+
} as_lvalue{};
2835
}
2936

3037
#include "../compilation_config_out.h"

tests/src/utility/forward_cast.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ SCENARIO("forward cast", "[utility]")
2929
STATIC_REQUIRE(same_as<decltype(forward_cast<const t0&, t0&>(v)), const t0&>);
3030
STATIC_REQUIRE(same_as<decltype(forward_cast<t0&&, t0>(v)), t0&&>);
3131
STATIC_REQUIRE(same_as<decltype(forward_cast<const t0&&, t0>(v)), const t0&&>);
32-
STATIC_REQUIRE(same_as<decltype(forward_cast<const t0&&, t0&>(v)), const t0&>);
32+
STATIC_REQUIRE(same_as<decltype(forward_cast<const t0&&, t0&>(v)), const t0&&>);
3333
STATIC_REQUIRE(same_as<decltype(forward_cast<const t0&&, t0&&>(v)), const t0&&>);
3434
}
3535

0 commit comments

Comments
 (0)