xref: /llvm-project/libcxx/test/std/containers/sequences/forwardlist/forwardlist.cons/range.pass.cpp (revision 773ae4412468433c134e668b4047c94f4599e0fd)
1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 
9 // <forward_list>
10 
11 // template <class InputIterator>
12 //     forward_list(InputIterator first, InputIterator last);
13 
14 #include <forward_list>
15 #include <cassert>
16 #include <iterator>
17 
18 #include "test_macros.h"
19 #include "test_iterators.h"
20 #include "min_allocator.h"
21 
main(int,char **)22 int main(int, char**)
23 {
24     {
25         typedef int T;
26         typedef std::forward_list<T> C;
27         typedef cpp17_input_iterator<const T*> I;
28         const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
29         C c(I(std::begin(t)), I(std::end(t)));
30         int n = 0;
31         for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
32             assert(*i == n);
33         assert(n == std::end(t) - std::begin(t));
34     }
35 #if TEST_STD_VER >= 11
36     {
37         typedef int T;
38         typedef std::forward_list<T, min_allocator<T>> C;
39         typedef cpp17_input_iterator<const T*> I;
40         const T t[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
41         C c(I(std::begin(t)), I(std::end(t)));
42         int n = 0;
43         for (C::const_iterator i = c.begin(), e = c.end(); i != e; ++i, ++n)
44             assert(*i == n);
45         assert(n == std::end(t) - std::begin(t));
46     }
47 #endif
48 
49   return 0;
50 }
51