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 // requires RandomAccessIterator<Iter> 15 // unspecified operator[](difference_type n) const; 16 // 17 // constexpr in C++17 18 19 #include <iterator> 20 #include <cassert> 21 #include <memory> 22 23 #include "test_macros.h" 24 #include "test_iterators.h" 25 26 template <class It> 27 void 28 test(It i, typename std::iterator_traits<It>::difference_type n, 29 typename std::iterator_traits<It>::value_type x) 30 { 31 typedef typename std::iterator_traits<It>::value_type value_type; 32 const std::move_iterator<It> r(i); 33 value_type rr = r[n]; 34 assert(rr == x); 35 } 36 37 struct do_nothing 38 { 39 void operator()(void*) const {} 40 }; 41 42 int main() 43 { 44 { 45 char s[] = "1234567890"; 46 test(random_access_iterator<char*>(s+5), 4, '0'); 47 test(s+5, 4, '0'); 48 } 49 #if TEST_STD_VER >= 11 50 { 51 int i[5]; 52 typedef std::unique_ptr<int, do_nothing> Ptr; 53 Ptr p[5]; 54 for (unsigned j = 0; j < 5; ++j) 55 p[j].reset(i+j); 56 test(p, 3, Ptr(i+3)); 57 } 58 #endif 59 #if TEST_STD_VER > 14 60 { 61 constexpr const char *p = "123456789"; 62 typedef std::move_iterator<const char *> MI; 63 constexpr MI it1 = std::make_move_iterator(p); 64 static_assert(it1[0] == '1', ""); 65 static_assert(it1[5] == '6', ""); 66 } 67 #endif 68 } 69