//===----------------------------------------------------------------------===//
//
// 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
// constexpr const iterator_t& base() const & noexcept;
// constexpr iterator_t base() &&;
#include
#include
#include
#include
#include
#include "MoveOnly.h"
#include "../types.h"
// Test Noexcept
template
concept IsBaseNoexcept =
requires {
{ std::declval().base() } noexcept;
};
using BaseView = std::ranges::subrange*>;
using ElementsIter = std::ranges::iterator_t>;
static_assert(IsBaseNoexcept);
static_assert(IsBaseNoexcept);
static_assert(IsBaseNoexcept);
LIBCPP_STATIC_ASSERT(!IsBaseNoexcept);
constexpr bool test() {
std::tuple t{5};
// const &
{
const ElementsIter it{&t};
decltype(auto) base = it.base();
static_assert(std::is_same_v* const&>);
assert(base == &t);
}
// &
{
ElementsIter it{&t};
decltype(auto) base = it.base();
static_assert(std::is_same_v* const&>);
assert(base == &t);
}
// &&
{
ElementsIter it{&t};
decltype(auto) base = std::move(it).base();
static_assert(std::is_same_v*>);
assert(base == &t);
}
// const &&
{
const ElementsIter it{&t};
decltype(auto) base = std::move(it).base();
static_assert(std::is_same_v* const&>);
assert(base == &t);
}
// move only
{
struct MoveOnlyIter : IterBase {
MoveOnly mo;
};
struct Sent {
constexpr bool operator==(const MoveOnlyIter&) const { return true; }
};
using MoveOnlyElemIter =
std::ranges::iterator_t, 0>>;
MoveOnlyElemIter it{MoveOnlyIter{{}, MoveOnly{5}}};
decltype(auto) base = std::move(it).base();
static_assert(std::is_same_v);
assert(base.mo.get() == 5);
}
return true;
}
int main(int, char**) {
test();
static_assert(test());
return 0;
}