From 7dd453290dfa1d72e6036099d31ac5eb6a50e89b Mon Sep 17 00:00:00 2001 From: Jakub Mazurkiewicz Date: Wed, 10 Aug 2022 01:56:48 +0200 Subject: [PATCH] Extra: test example from P2446R2 --- tests/std/tests/P2446R2_views_as_rvalue/test.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/std/tests/P2446R2_views_as_rvalue/test.cpp b/tests/std/tests/P2446R2_views_as_rvalue/test.cpp index a896e1f50a..b97d980b15 100644 --- a/tests/std/tests/P2446R2_views_as_rvalue/test.cpp +++ b/tests/std/tests/P2446R2_views_as_rvalue/test.cpp @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +#include #include #include #include @@ -392,6 +393,18 @@ using move_only_view = test::range}, test::CanView::yes, test::Copyability::move_only>; +void test_example_from_p2446r2() { + const vector pattern = {"the", "quick", "brown", "fox", "ate", "a", "pterodactyl"}; + + vector words = pattern; + vector new_words; + ranges::copy(words | views::as_rvalue, back_inserter(new_words)); // moves each string from words into new_words + + assert(ranges::equal(new_words, pattern)); + assert(words.size() == pattern.size()); // size of words in preserved + assert(ranges::all_of(words, ranges::empty)); // all strings from words are empty +} + int main() { { // Validate views // ... copyable @@ -435,4 +448,6 @@ int main() { STATIC_ASSERT(instantiation_test()); instantiation_test(); + + test_example_from_p2446r2(); }