• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 // <numeric>
11 
12 // template <InputIterator InIter,
13 //           OutputIterator<auto, const InIter::value_type&> OutIter>
14 //   requires HasMinus<InIter::value_type, InIter::value_type>
15 //         && Constructible<InIter::value_type, InIter::reference>
16 //         && OutputIterator<OutIter,
17 //                           HasMinus<InIter::value_type, InIter::value_type>::result_type>
18 //         && MoveAssignable<InIter::value_type>
19 //   OutIter
20 //   adjacent_difference(InIter first, InIter last, OutIter result);
21 
22 #include <numeric>
23 #include <cassert>
24 
25 #include "test_iterators.h"
26 
27 template <class InIter, class OutIter>
28 void
test()29 test()
30 {
31     int ia[] = {15, 10, 6, 3, 1};
32     int ir[] = {15, -5, -4, -3, -2};
33     const unsigned s = sizeof(ia) / sizeof(ia[0]);
34     int ib[s] = {0};
35     OutIter r = std::adjacent_difference(InIter(ia), InIter(ia+s), OutIter(ib));
36     assert(base(r) == ib + s);
37     for (unsigned i = 0; i < s; ++i)
38         assert(ib[i] == ir[i]);
39 }
40 
41 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
42 
43 class Y;
44 
45 class X
46 {
47     int i_;
48 
49     X& operator=(const X&);
50 public:
X(int i)51     explicit X(int i) : i_(i) {}
X(const X & x)52     X(const X& x) : i_(x.i_) {}
operator =(X && x)53     X& operator=(X&& x)
54     {
55         i_ = x.i_;
56         x.i_ = -1;
57         return *this;
58     }
59 
operator -(const X & x,const X & y)60     friend X operator-(const X& x, const X& y) {return X(x.i_ - y.i_);}
61 
62     friend class Y;
63 };
64 
65 class Y
66 {
67     int i_;
68 
69     Y& operator=(const Y&);
70 public:
Y(int i)71     explicit Y(int i) : i_(i) {}
Y(const Y & y)72     Y(const Y& y) : i_(y.i_) {}
operator =(const X & x)73     void operator=(const X& x) {i_ = x.i_;}
74 };
75 
76 #endif
77 
main()78 int main()
79 {
80     test<input_iterator<const int*>, output_iterator<int*> >();
81     test<input_iterator<const int*>, forward_iterator<int*> >();
82     test<input_iterator<const int*>, bidirectional_iterator<int*> >();
83     test<input_iterator<const int*>, random_access_iterator<int*> >();
84     test<input_iterator<const int*>, int*>();
85 
86     test<forward_iterator<const int*>, output_iterator<int*> >();
87     test<forward_iterator<const int*>, forward_iterator<int*> >();
88     test<forward_iterator<const int*>, bidirectional_iterator<int*> >();
89     test<forward_iterator<const int*>, random_access_iterator<int*> >();
90     test<forward_iterator<const int*>, int*>();
91 
92     test<bidirectional_iterator<const int*>, output_iterator<int*> >();
93     test<bidirectional_iterator<const int*>, forward_iterator<int*> >();
94     test<bidirectional_iterator<const int*>, bidirectional_iterator<int*> >();
95     test<bidirectional_iterator<const int*>, random_access_iterator<int*> >();
96     test<bidirectional_iterator<const int*>, int*>();
97 
98     test<random_access_iterator<const int*>, output_iterator<int*> >();
99     test<random_access_iterator<const int*>, forward_iterator<int*> >();
100     test<random_access_iterator<const int*>, bidirectional_iterator<int*> >();
101     test<random_access_iterator<const int*>, random_access_iterator<int*> >();
102     test<random_access_iterator<const int*>, int*>();
103 
104     test<const int*, output_iterator<int*> >();
105     test<const int*, forward_iterator<int*> >();
106     test<const int*, bidirectional_iterator<int*> >();
107     test<const int*, random_access_iterator<int*> >();
108     test<const int*, int*>();
109 
110 #ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
111     X x[3] = {X(1), X(2), X(3)};
112     Y y[3] = {Y(1), Y(2), Y(3)};
113     std::adjacent_difference(x, x+3, y);
114 #endif
115 }
116