libcxx

libcxx mirror with random patches
git clone https://git.neptards.moe/neptards/libcxx.git
Log | Files | Refs

minus.pass.cpp (1418B)


      1 //===----------------------------------------------------------------------===//
      2 //
      3 //                     The LLVM Compiler Infrastructure
      4 //
      5 // This file is dual licensed under the MIT and the University of Illinois Open
      6 // Source Licenses. See LICENSE.TXT for details.
      7 //
      8 //===----------------------------------------------------------------------===//
      9 
     10 // <iterator>
     11 
     12 // move_iterator
     13 
     14 // template <RandomAccessIterator Iter1, RandomAccessIterator Iter2>
     15 //   requires HasMinus<Iter1, Iter2>
     16 //   auto
     17 //   operator-(const move_iterator<Iter1>& x, const move_iterator<Iter2>& y)
     18 //   -> decltype(x.base() - y.base());
     19 //
     20 //  constexpr in C++17
     21 
     22 #include <iterator>
     23 #include <cassert>
     24 
     25 #include "test_macros.h"
     26 #include "test_iterators.h"
     27 
     28 template <class It>
     29 void
     30 test(It l, It r, typename std::iterator_traits<It>::difference_type x)
     31 {
     32     const std::move_iterator<It> r1(l);
     33     const std::move_iterator<It> r2(r);
     34     assert(r1 - r2 == x);
     35 }
     36 
     37 int main()
     38 {
     39     char s[] = "1234567890";
     40     test(random_access_iterator<char*>(s+5), random_access_iterator<char*>(s), 5);
     41     test(s+5, s, 5);
     42 
     43 #if TEST_STD_VER > 14
     44     {
     45     constexpr const char *p = "123456789";
     46     typedef std::move_iterator<const char *> MI;
     47     constexpr MI it1 = std::make_move_iterator(p);
     48     constexpr MI it2 = std::make_move_iterator(p+1);
     49     static_assert( it1 - it2 == -1, "");
     50     static_assert( it2 - it1 ==  1, "");
     51     }
     52 #endif
     53 }