Date: Wed, 4 Jun 2025 10:01:17 +0200
It could also allow std::expected to be even easier to use!
const auto myExpected = Meow();
assert(myExpected.has_value());
const auto myValue = std::move_as<ValueType>(myExpected);
But I believe that could be a long-shot, I would use it myself, not sure
whether other programmers would find it.. intuitive, your call.
Tymi.
On Wed, Jun 4, 2025 at 9:58 AM Tymi <tymi.cpp_at_[hidden]> wrote:
> Well the current solutions are insufficient because they are
> non-existent...
> Consider this class:
> struct StringWrapper
> {
> // [...]
> [[nodiscard]] explicit operator std::string&&(void) && noexcept {
> return std::move(this->_value); }
> private:
> std::string _value;
> };
> I would want to perform that conversion like that:
> C c = AcquireC();
> const auto myString = std::move_as<std::string>(c);
>
> Tymi.
>
> On Wed, Jun 4, 2025 at 6:36 AM Jan Schultke <janschultke_at_[hidden]>
> wrote:
>
>> How is it supposed to perform a conversion and return an rvalue
>> reference? This looks like you're returning a reference to a temporary
>> object.
>>
>
const auto myExpected = Meow();
assert(myExpected.has_value());
const auto myValue = std::move_as<ValueType>(myExpected);
But I believe that could be a long-shot, I would use it myself, not sure
whether other programmers would find it.. intuitive, your call.
Tymi.
On Wed, Jun 4, 2025 at 9:58 AM Tymi <tymi.cpp_at_[hidden]> wrote:
> Well the current solutions are insufficient because they are
> non-existent...
> Consider this class:
> struct StringWrapper
> {
> // [...]
> [[nodiscard]] explicit operator std::string&&(void) && noexcept {
> return std::move(this->_value); }
> private:
> std::string _value;
> };
> I would want to perform that conversion like that:
> C c = AcquireC();
> const auto myString = std::move_as<std::string>(c);
>
> Tymi.
>
> On Wed, Jun 4, 2025 at 6:36 AM Jan Schultke <janschultke_at_[hidden]>
> wrote:
>
>> How is it supposed to perform a conversion and return an rvalue
>> reference? This looks like you're returning a reference to a temporary
>> object.
>>
>
Received on 2025-06-04 08:01:28