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 9, 2022
1 parent b164f60 commit 36b81bb
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 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,17 @@ 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));

assert(ranges::equal(new_words, pattern)); // moves each string from words into new_words
assert(words.size() == pattern.size()); // size of words in preserved
}

int main() {
{ // Validate views
// ... copyable
Expand Down Expand Up @@ -435,4 +447,6 @@ int main() {

STATIC_ASSERT(instantiation_test());
instantiation_test();

test_example_from_p2446r2();
}

0 comments on commit 36b81bb

Please sign in to comment.