File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -50,6 +50,7 @@ template<typename T> struct [[nodiscard]] forwarding_ref
5050
5151 [[nodiscard]] explicit constexpr forwarding_ref (reference_type ref_ LIFETIMEBOUND) noexcept : ref{ &ref_ } {}
5252 [[nodiscard]] constexpr operator reference_type () noexcept LIFETIMEBOUND { return static_cast <reference_type>(*ref); }
53+ [[nodiscard]] constexpr reference_type take () noexcept LIFETIMEBOUND { return static_cast <reference_type>(*ref); }
5354
5455private:
5556 pointer_type ref;
Original file line number Diff line number Diff line change @@ -58,6 +58,8 @@ struct [[nodiscard]] moving_ref
5858 moving_ref (const T &) = delete (" this type is only to be used with rvalue reference parameters" );
5959
6060 [[nodiscard]] constexpr operator reference_type () noexcept LIFETIMEBOUND { return static_cast <reference_type>(*ref); }
61+ [[nodiscard]] constexpr reference_type take () noexcept LIFETIMEBOUND { return static_cast <reference_type>(*ref); }
62+
6163
6264private:
6365 pointer_type ref;
Original file line number Diff line number Diff line change @@ -75,6 +75,17 @@ template<typename T> constexpr auto can_construct_const()
7575 return requires (const T mct) { T{ lefticus::tools::moving_ref<T>{ std::move (mct) } }; };
7676}
7777
78+ TEST_CASE (" [forwarding_ref] take() behaves as expected" )
79+ {
80+ [] () consteval {
81+ auto use_forwarding_ref = []<typename T>(lefticus::tools::forwarding_ref<T> data) {
82+ std::string (data.take ());
83+ };
84+
85+ use_forwarding_ref (lefticus::tools::forwarding_ref{" Hello World" });
86+ }();
87+ }
88+
7889
7990TEST_CASE (" [forwarding_ref] behaves as expected" )
8091{
You can’t perform that action at this time.
0 commit comments