Sure. You have const optional<T> in the structure. You return an instance of rvalue and gain access to an optional member.
Because of how you built it, you can guarantee that in this case an additional one is involved. Therefore, you call value() . Type T contains a mutable state that can be effectively reused / stolen. Overloading T const&& gives permission to the consumption function to steal this state.
struct mutable_type { mutable std::vector<char> cache; }; struct test_type { const std::optional<mutable_type> bob; }; test_type factory( int x ) { if (x==0) return {}; return {mutable_type({{1,2,x}})}; } auto moved_into = factory(3).bob.value().cache;
This, I believe, moves the vector within the bob , which is const rvalue in this context. It relies on value() , which returns const&& in the context of const&& .
source share