std::views::as_rvalue() banned?

61 views
Skip to first unread message

Thomas Sepez

unread,
Jan 23, 2026, 6:02:20 PM (8 days ago) Jan 23
to cxx, Matthew Riley, Daniel Cheng
Since we prefer constructing containers using the std::from_range constructor form over the two-iterator constructor form, a problem occurs with cases like this:

  std::vector<T> vec(std::make_move_iterator(that.begin()),
                     std::make_move_iterator(that.end()));
which is expressed in range form as

  std::vector<T> vec(std::from_range, std::views::as_rvalue(that));

but as_rvalue() is still banned. Thoughts?

Jan Wilken Dörrie

unread,
Jan 25, 2026, 1:19:17 PM (6 days ago) Jan 25
to cxx, Thomas Sepez, Matthew Riley, Daniel Cheng
I doubt we'll allow std::views anytime soon, see https://groups.google.com/a/chromium.org/g/cxx/c/ZnIbkfJ0Glw for a related discussion.

For the case of std::views::as_rvalue there is the alternative base::RangeAsRvalues, which should allow you to do 

  std::vector vec(std::from_range, 
base::RangeAsRvalues(std::move(that)));.

In the case of vector

  auto vec = base::ToVector(that, [](auto& e) { std::move(e); });

should also work.

Best,
Jan

Thomas Sepez

unread,
Jan 26, 2026, 11:29:54 AM (5 days ago) Jan 26
to Jan Wilken Dörrie, cxx, Matthew Riley, Daniel Cheng
Ah, thanks, good to know base/ already has this covered. 
Reply all
Reply to author
Forward
0 new messages