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#include <iterator>
18#include <cassert>
19#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
20#include <memory>
21#endif
22
23#include "test_iterators.h"
24
25template <class It>
26void
27test(It i, typename std::iterator_traits<It>::difference_type n,
28     typename std::iterator_traits<It>::value_type x)
29{
30    typedef typename std::iterator_traits<It>::value_type value_type;
31    const std::move_iterator<It> r(i);
32    value_type rr = r[n];
33    assert(rr == x);
34}
35
36#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
37
38struct do_nothing
39{
40    void operator()(void*) const {}
41};
42
43#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
44
45int main()
46{
47    char s[] = "1234567890";
48    test(random_access_iterator<char*>(s+5), 4, '0');
49    test(s+5, 4, '0');
50#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
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#endif  // _LIBCPP_HAS_NO_RVALUE_REFERENCES
58}
59