Skip to content

Commit 1fd5389

Browse files
committed
support int const and friends
1 parent 21e19c3 commit 1fd5389

File tree

2 files changed

+22
-9
lines changed

2 files changed

+22
-9
lines changed

include/libfork/ev.hpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ namespace lf {
2424
* @tparam T The type to test.
2525
*/
2626
template <typename T>
27-
concept trivial_return = std::default_initializable<T> && std::is_trivially_destructible_v<T>;
27+
concept trivial_return = std::constructible_from<T> && std::is_trivially_destructible_v<T>;
2828

2929
/**
3030
* @brief A wrapper for return values from libfork's coroutines.
@@ -61,6 +61,18 @@ class ev : detail::immovable<ev<T>> {
6161
template <trivial_return T>
6262
class ev<T> : detail::immovable<ev<T>> {
6363
public:
64+
constexpr ev() = default;
65+
66+
/*
67+
* @brief Default construct
68+
*
69+
* This is required to subsume the trivial constuctor for
70+
* non default-initializable types like `int const`.
71+
*/
72+
constexpr ev() noexcept
73+
requires (!requires { ::new T; })
74+
: m_value() {}
75+
6476
template <typename Self>
6577
[[nodiscard]] constexpr auto operator*(this Self &&self) noexcept -> auto && {
6678
return std::forward<Self>(self).m_value;

test/src/test_ev.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,8 @@
99

1010
namespace {
1111

12-
template <typename T, typename Ref>
13-
concept deref_like = requires (T val, Ref ref) {
14-
{ *val } -> std::same_as<decltype((ref))>;
15-
{ *std::move(val) } -> std::same_as<decltype(std::move(ref))>;
16-
};
17-
1812
struct non_trivial {
13+
int x;
1914
constexpr ~non_trivial() {}
2015
};
2116

@@ -25,18 +20,24 @@ consteval auto const_test() -> bool {
2520

2621
{
2722
lf::ev<non_trivial const> x;
28-
x.emplace();
23+
x.emplace(5);
2924
}
3025

3126
{
32-
lf::ev<int> x;
27+
lf::ev<int const> x;
3328
int const *p = x.get();
3429
std::construct_at(p, 3);
3530
}
3631

3732
return true;
3833
}
3934

35+
template <typename T, typename Ref>
36+
concept deref_like = requires (T val, Ref ref) {
37+
{ *val } -> std::same_as<decltype((ref))>;
38+
{ *std::move(val) } -> std::same_as<decltype(std::move(ref))>;
39+
};
40+
4041
} // namespace
4142

4243
TEST_CASE("Ev constexpr tests", "[ev]") { REQUIRE(const_test()); }

0 commit comments

Comments
 (0)