[C++20][modules] Fix std::initializer_list recognition if it's exported out of a...
[llvm-project.git] / libcxx / test / std / iterators / iterator.requirements / alg.req.permutable / permutable.compile.pass.cpp
blob8c3bef68532a90c307a8165edb2bab903135b33f
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 // UNSUPPORTED: c++03, c++11, c++14, c++17
11 // template<class I>
12 // concept permutable = see below; // Since C++20
14 #include <iterator>
16 #include "test_iterators.h"
18 using AllConstraintsSatisfied = forward_iterator<int*>;
19 static_assert( std::forward_iterator<AllConstraintsSatisfied>);
20 static_assert( std::indirectly_movable_storable<AllConstraintsSatisfied, AllConstraintsSatisfied>);
21 static_assert( std::indirectly_swappable<AllConstraintsSatisfied>);
22 static_assert( std::permutable<AllConstraintsSatisfied>);
24 using NotAForwardIterator = cpp20_input_iterator<int*>;
25 static_assert(!std::forward_iterator<NotAForwardIterator>);
26 static_assert( std::indirectly_movable_storable<NotAForwardIterator, NotAForwardIterator>);
27 static_assert( std::indirectly_swappable<NotAForwardIterator>);
28 static_assert(!std::permutable<NotAForwardIterator>);
30 struct NonCopyable {
31 NonCopyable(const NonCopyable&) = delete;
32 NonCopyable& operator=(const NonCopyable&) = delete;
33 friend void swap(NonCopyable&, NonCopyable&);
35 using NotIMS = forward_iterator<NonCopyable*>;
37 static_assert( std::forward_iterator<NotIMS>);
38 static_assert(!std::indirectly_movable_storable<NotIMS, NotIMS>);
39 static_assert( std::indirectly_swappable<NotIMS>);
40 static_assert(!std::permutable<NotIMS>);
42 // Note: it is impossible for an iterator to satisfy `indirectly_movable_storable` but not `indirectly_swappable`:
43 // `indirectly_swappable` requires both iterators to be `indirectly_readable` and for `ranges::iter_swap` to be
44 // well-formed for both iterators. `indirectly_movable_storable` also requires the iterator to be `indirectly_readable`.
45 // `ranges::iter_swap` is always defined for `indirectly_movable_storable` iterators.