Files
clang-p2996/libcxx/test/std/ranges/range.adaptors/range.lazy.split/range.lazy.split.outer/increment.pass.cpp
Konstantin Varlamov e53c461bf3 [libc++][ranges] Implement lazy_split_view.
Note that this class was called just `split_view` in the original One
Ranges Proposal and was renamed to `lazy_split_view` by
[P2210](https://wg21.link/p2210).

Co-authored-by: zoecarver <z.zoelec2@gmail.com>

Differential Revision: https://reviews.llvm.org/D107500
2022-04-12 22:28:38 -07:00

87 lines
2.0 KiB
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// UNSUPPORTED: c++03, c++11, c++14, c++17
// UNSUPPORTED: libcpp-has-no-incomplete-ranges
// constexpr outer-iterator& outer-iterator::operator++();
// constexpr decltype(auto) outer-iterator::operator++(int);
// Note that corner cases are tested in `range.lazy.split/general.pass.cpp`.
#include <ranges>
#include <algorithm>
#include <string_view>
#include "../small_string.h"
#include "../types.h"
constexpr bool test() {
// Can call `outer-iterator::operator++`; `View` is a forward range.
{
SplitViewForward v("abc def ghi", " ");
// ++i
{
auto i = v.begin();
assert(*i == "abc"_str);
decltype(auto) i2 = ++i;
static_assert(std::is_lvalue_reference_v<decltype(i2)>);
assert(&i2 == &i);
assert(*i2 == "def"_str);
}
// i++
{
auto i = v.begin();
assert(*i == "abc"_str);
decltype(auto) i2 = i++;
static_assert(!std::is_reference_v<decltype(i2)>);
assert(*i2 == "abc"_str);
assert(*i == "def"_str);
}
}
// Can call `outer-iterator::operator++`; `View` is an input range.
{
SplitViewInput v("abc def ghi", ' ');
// ++i
{
auto i = v.begin();
assert(*i == "abc"_str);
decltype(auto) i2 = ++i;
static_assert(std::is_lvalue_reference_v<decltype(i2)>);
assert(&i2 == &i);
assert(*i2 == "def"_str);
}
// i++
{
auto i = v.begin();
assert(*i == "abc"_str);
static_assert(std::is_void_v<decltype(i++)>);
i++;
assert(*i == "def"_str);
}
}
return true;
}
int main(int, char**) {
test();
static_assert(test());
return 0;
}