Skip to content

Commit

Permalink
Extra: test example from P2446R2
Browse files Browse the repository at this point in the history
  • Loading branch information
JMazurkiewicz committed Aug 10, 2022
1 parent b164f60 commit 7dd4532
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tests/std/tests/P2446R2_views_as_rvalue/test.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Copyright (c) Microsoft Corporation.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception

#include <algorithm>
#include <cassert>
#include <forward_list>
#include <ranges>
Expand Down Expand Up @@ -392,6 +393,18 @@ using move_only_view = test::range<Category, const int, test::Sized{is_random},
IsCommon, test::CanCompare::yes, test::ProxyRef{!derived_from<Category, contiguous_iterator_tag>},
test::CanView::yes, test::Copyability::move_only>;

void test_example_from_p2446r2() {
const vector<string> pattern = {"the", "quick", "brown", "fox", "ate", "a", "pterodactyl"};

vector<string> words = pattern;
vector<string> 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
Expand Down Expand Up @@ -435,4 +448,6 @@ int main() {

STATIC_ASSERT(instantiation_test());
instantiation_test();

test_example_from_p2446r2();
}

0 comments on commit 7dd4532

Please sign in to comment.