Date: Wed, 4 Jun 2025 12:26:45 +0200
On 04/06/2025 09:58, Tymi via Std-Proposals 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);
Could you elaborate a bit just how often do you need something like
this, so that it makes sense to be offered as building block in the
Standard Library?
> I find the move_as example more intuitive and generally "safer". Also my first thought was that std::string(std::move(c)) copied c._value and created a new object out of it, instead of just moving c._value.
But that's not what happens, so again how this new spelling better?
> template<typename T, typename U>
> constexpr std::remove_reference_t<T>&& move_as(U& u) noexcept
> {
> return static_cast<T&&>(static_cast<U&&>(u));
> }
This doesn't accept rvalues (unlike std::move), why?
My 2 c,
--
Giuseppe D'Angelo
> 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);
Could you elaborate a bit just how often do you need something like
this, so that it makes sense to be offered as building block in the
Standard Library?
> I find the move_as example more intuitive and generally "safer". Also my first thought was that std::string(std::move(c)) copied c._value and created a new object out of it, instead of just moving c._value.
But that's not what happens, so again how this new spelling better?
> template<typename T, typename U>
> constexpr std::remove_reference_t<T>&& move_as(U& u) noexcept
> {
> return static_cast<T&&>(static_cast<U&&>(u));
> }
This doesn't accept rvalues (unlike std::move), why?
My 2 c,
--
Giuseppe D'Angelo
Received on 2025-06-04 10:26:52