// Range v3 library // // Copyright Eric Niebler 2014-present // // Use, modification and distribution is subject to the // Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at // http://www.boost.org/LICENSE_1_0.txt) // // Project home: https://github.com/ericniebler/range-v3 //===----------------------------------------------------------------------===// // // The LLVM Compiler Infrastructure // // This file is dual licensed under the MIT and the University of Illinois Open // Source Licenses. See LICENSE.TXT for details. // //===----------------------------------------------------------------------===// #include #include #include #include #include "../simple_test.hpp" #include "../test_utils.hpp" #include "../test_iterators.hpp" template void test() { { const int N = 1000; int ia[N]; for(int i = 0; i < N; ++i) ia[i] = i; int ib[N] = {0}; ranges::move_result r = ranges::move(InIter(ia), Sent(ia+N), OutIter(ib)); CHECK(base(r.in) == ia+N); CHECK(base(r.out) == ib+N); for(int i = 0; i < N; ++i) CHECK(ia[i] == ib[i]); } { const int N = 1000; int ia[N]; for(int i = 0; i < N; ++i) ia[i] = i; int ib[N] = {0}; ranges::move_result r = ranges::move(as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+N))), OutIter(ib)); CHECK(base(r.in) == ia+N); CHECK(base(r.out) == ib+N); for(int i = 0; i < N; ++i) CHECK(ia[i] == ib[i]); } } template constexpr bool test_constexpr() { { constexpr int N = 1000; int ia[N]{1}; for(int i = 0; i < N; ++i) ia[i] = i; int ib[N] = {0}; const auto r = ranges::move(InIter(ia), Sent(ia + N), OutIter(ib)); if(base(r.in) != ia + N) { return false; } if(base(r.out) != ib + N) { return false; } for(int i = 0; i < N; ++i) if(ia[i] != ib[i]) { return false; } } { constexpr int N = 1000; int ia[N]{1}; for(int i = 0; i < N; ++i) ia[i] = i; int ib[N] = {0}; const auto r = ranges::move( as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia + N))), OutIter(ib)); if(base(r.in) != ia + N) { return false; } if(base(r.out) != ib + N) { return false; } for(int i = 0; i < N; ++i) if(ia[i] != ib[i]) { return false; } } return true; } struct S { std::unique_ptr p; }; template void test1() { { const int N = 100; std::unique_ptr ia[N]; for(int i = 0; i < N; ++i) ia[i].reset(new int(i)); std::unique_ptr ib[N]; ranges::move_result r = ranges::move(InIter(ia), Sent(ia+N), OutIter(ib)); CHECK(base(r.in) == ia+N); CHECK(base(r.out) == ib+N); for(int i = 0; i < N; ++i) { CHECK(ia[i].get() == nullptr); CHECK(*ib[i] == i); } } { const int N = 100; std::unique_ptr ia[N]; for(int i = 0; i < N; ++i) ia[i].reset(new int(i)); std::unique_ptr ib[N]; ranges::move_result r = ranges::move(as_lvalue(ranges::make_subrange(InIter(ia), Sent(ia+N))), OutIter(ib)); CHECK(base(r.in) == ia+N); CHECK(base(r.out) == ib+N); for(int i = 0; i < N; ++i) { CHECK(ia[i].get() == nullptr); CHECK(*ib[i] == i); } ranges::move(ib, ib+N, ia); auto r2 = ranges::move(ranges::make_subrange(InIter(ia), Sent(ia+N)), OutIter(ib)); CHECK(base(r2.in) == ia+N); CHECK(base(r2.out) == ib+N); for(int i = 0; i < N; ++i) { CHECK(ia[i].get() == nullptr); CHECK(*ib[i] == i); } } } int main() { test, OutputIterator >(); test, InputIterator >(); test, ForwardIterator >(); test, BidirectionalIterator >(); test, RandomAccessIterator >(); test, int*>(); test, OutputIterator >(); test, InputIterator >(); test, ForwardIterator >(); test, BidirectionalIterator >(); test, RandomAccessIterator >(); test, int*>(); test, OutputIterator >(); test, InputIterator >(); test, ForwardIterator >(); test, BidirectionalIterator >(); test, RandomAccessIterator >(); test, int*>(); test, OutputIterator >(); test, InputIterator >(); test, ForwardIterator >(); test, BidirectionalIterator >(); test, RandomAccessIterator >(); test, int*>(); test >(); test >(); test >(); test >(); test >(); test(); test, OutputIterator, Sentinel>(); test, InputIterator, Sentinel >(); test, ForwardIterator, Sentinel >(); test, BidirectionalIterator, Sentinel >(); test, RandomAccessIterator, Sentinel >(); test, OutputIterator, Sentinel >(); test, InputIterator, Sentinel >(); test, ForwardIterator, Sentinel >(); test, BidirectionalIterator, Sentinel >(); test, RandomAccessIterator, Sentinel >(); test, OutputIterator, Sentinel >(); test, InputIterator, Sentinel >(); test, ForwardIterator, Sentinel >(); test, BidirectionalIterator, Sentinel >(); test, RandomAccessIterator, Sentinel >(); test, OutputIterator, Sentinel >(); test, InputIterator, Sentinel >(); test, ForwardIterator, Sentinel >(); test, BidirectionalIterator, Sentinel >(); test, RandomAccessIterator, Sentinel >(); test1*>, OutputIterator*> >(); test1*>, InputIterator*> >(); test1*>, ForwardIterator*> >(); test1*>, BidirectionalIterator*> >(); test1*>, RandomAccessIterator*> >(); test1*>, std::unique_ptr*>(); test1*>, OutputIterator*> >(); test1*>, InputIterator*> >(); test1*>, ForwardIterator*> >(); test1*>, BidirectionalIterator*> >(); test1*>, RandomAccessIterator*> >(); test1*>, std::unique_ptr*>(); test1*>, OutputIterator*> >(); test1*>, InputIterator*> >(); test1*>, ForwardIterator*> >(); test1*>, BidirectionalIterator*> >(); test1*>, RandomAccessIterator*> >(); test1*>, std::unique_ptr*>(); test1*>, OutputIterator*> >(); test1*>, InputIterator*> >(); test1*>, ForwardIterator*> >(); test1*>, BidirectionalIterator*> >(); test1*>, RandomAccessIterator*> >(); test1*>, std::unique_ptr*>(); test1*, OutputIterator*> >(); test1*, InputIterator*> >(); test1*, ForwardIterator*> >(); test1*, BidirectionalIterator*> >(); test1*, RandomAccessIterator*> >(); test1*, std::unique_ptr*>(); test1*>, OutputIterator*>, Sentinel*> >(); test1*>, InputIterator*>, Sentinel*> >(); test1*>, ForwardIterator*>, Sentinel*> >(); test1*>, BidirectionalIterator*>, Sentinel*> >(); test1*>, RandomAccessIterator*>, Sentinel*> >(); test1*>, std::unique_ptr*>(); test1*>, OutputIterator*>, Sentinel*> >(); test1*>, InputIterator*>, Sentinel*> >(); test1*>, ForwardIterator*>, Sentinel*> >(); test1*>, BidirectionalIterator*>, Sentinel*> >(); test1*>, RandomAccessIterator*>, Sentinel*> >(); test1*>, std::unique_ptr*>(); test1*>, OutputIterator*>, Sentinel*> >(); test1*>, InputIterator*>, Sentinel*> >(); test1*>, ForwardIterator*>, Sentinel*> >(); test1*>, BidirectionalIterator*>, Sentinel*> >(); test1*>, RandomAccessIterator*>, Sentinel*> >(); test1*>, std::unique_ptr*>(); test1*>, OutputIterator*>, Sentinel*> >(); test1*>, InputIterator*>, Sentinel*> >(); test1*>, ForwardIterator*>, Sentinel*> >(); test1*>, BidirectionalIterator*>, Sentinel*> >(); test1*>, RandomAccessIterator*>, Sentinel*> >(); { STATIC_CHECK(test_constexpr, OutputIterator>()); STATIC_CHECK(test_constexpr, InputIterator>()); STATIC_CHECK( test_constexpr, ForwardIterator>()); STATIC_CHECK( test_constexpr, BidirectionalIterator>()); STATIC_CHECK( test_constexpr, RandomAccessIterator>()); STATIC_CHECK(test_constexpr, int *>()); STATIC_CHECK( test_constexpr, OutputIterator>()); STATIC_CHECK( test_constexpr, InputIterator>()); STATIC_CHECK( test_constexpr, ForwardIterator>()); STATIC_CHECK( test_constexpr, BidirectionalIterator>()); STATIC_CHECK( test_constexpr, RandomAccessIterator>()); STATIC_CHECK(test_constexpr, int *>()); STATIC_CHECK( test_constexpr, OutputIterator>()); STATIC_CHECK( test_constexpr, InputIterator>()); STATIC_CHECK( test_constexpr, ForwardIterator>()); STATIC_CHECK(test_constexpr, BidirectionalIterator>()); STATIC_CHECK(test_constexpr, RandomAccessIterator>()); STATIC_CHECK(test_constexpr, int *>()); STATIC_CHECK( test_constexpr, OutputIterator>()); STATIC_CHECK( test_constexpr, InputIterator>()); STATIC_CHECK( test_constexpr, ForwardIterator>()); STATIC_CHECK(test_constexpr, BidirectionalIterator>()); STATIC_CHECK(test_constexpr, RandomAccessIterator>()); STATIC_CHECK(test_constexpr, int *>()); STATIC_CHECK(test_constexpr>()); STATIC_CHECK(test_constexpr>()); STATIC_CHECK(test_constexpr>()); STATIC_CHECK(test_constexpr>()); STATIC_CHECK(test_constexpr>()); STATIC_CHECK(test_constexpr()); STATIC_CHECK(test_constexpr, OutputIterator, Sentinel>()); STATIC_CHECK(test_constexpr, InputIterator, Sentinel>()); STATIC_CHECK(test_constexpr, ForwardIterator, Sentinel>()); STATIC_CHECK(test_constexpr, BidirectionalIterator, Sentinel>()); STATIC_CHECK(test_constexpr, RandomAccessIterator, Sentinel>()); STATIC_CHECK(test_constexpr, OutputIterator, Sentinel>()); STATIC_CHECK(test_constexpr, InputIterator, Sentinel>()); STATIC_CHECK(test_constexpr, ForwardIterator, Sentinel>()); STATIC_CHECK(test_constexpr, BidirectionalIterator, Sentinel>()); STATIC_CHECK(test_constexpr, RandomAccessIterator, Sentinel>()); STATIC_CHECK(test_constexpr, OutputIterator, Sentinel>()); STATIC_CHECK(test_constexpr, InputIterator, Sentinel>()); STATIC_CHECK(test_constexpr, ForwardIterator, Sentinel>()); STATIC_CHECK(test_constexpr, BidirectionalIterator, Sentinel>()); STATIC_CHECK(test_constexpr, RandomAccessIterator, Sentinel>()); STATIC_CHECK(test_constexpr, OutputIterator, Sentinel>()); STATIC_CHECK(test_constexpr, InputIterator, Sentinel>()); STATIC_CHECK(test_constexpr, ForwardIterator, Sentinel>()); STATIC_CHECK(test_constexpr, BidirectionalIterator, Sentinel>()); STATIC_CHECK(test_constexpr, RandomAccessIterator, Sentinel>()); } return test_result(); }