• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1  // Copyright (C) 2019 T. Zachary Laine
2  //
3  // Distributed under the Boost Software License, Version 1.0. (See
4  // accompanying file LICENSE_1_0.txt or copy at
5  // http://www.boost.org/LICENSE_1_0.txt)
6  #include <boost/stl_interfaces/iterator_interface.hpp>
7  #include <boost/stl_interfaces/view_interface.hpp>
8  #include <boost/stl_interfaces/sequence_container_interface.hpp>
9  
10  #include <boost/core/lightweight_test.hpp>
11  
12  #include <array>
13  #include <list>
14  #include <vector>
15  
16  
17  namespace detail = boost::stl_interfaces::detail;
18  namespace v1_dtl = boost::stl_interfaces::v1::v1_dtl;
19  
20  
21  // iter_difference_t
22  static_assert(
23      std::is_same<v1_dtl::iter_difference_t<int *>, std::ptrdiff_t>::value, "");
24  static_assert(std::is_same<
25                    v1_dtl::iter_difference_t<std::vector<double>::iterator>,
26                    std::vector<double>::difference_type>::value, "");
27  static_assert(std::is_same<
28                    v1_dtl::iter_difference_t<std::list<double>::iterator>,
29                    std::list<double>::difference_type>::value, "");
30  
31  struct ridiculous_range
32  {
beginridiculous_range33      int * begin() { return nullptr; }
endridiculous_range34      double end() { return 1.3; }
35  };
36  
37  // iterator_t
38  static_assert(std::is_same<
39                    v1_dtl::iterator_t<std::vector<double>>,
40                    std::vector<double>::iterator>::value, "");
41  static_assert(std::is_same<
42                    v1_dtl::iterator_t<std::list<double>>,
43                    std::list<double>::iterator>::value, "");
44  static_assert(std::is_same<v1_dtl::iterator_t<ridiculous_range>, int *>::value, "");
45  
46  // sentinel_t
47  static_assert(std::is_same<
48                    v1_dtl::sentinel_t<std::vector<double>>,
49                    std::vector<double>::iterator>::value, "");
50  static_assert(std::is_same<
51                    v1_dtl::sentinel_t<std::list<double>>,
52                    std::list<double>::iterator>::value, "");
53  static_assert(std::is_same<v1_dtl::sentinel_t<ridiculous_range>, double>::value, "");
54  
55  // range_difference_t
56  static_assert(
57      std::is_same<
58          v1_dtl::range_difference_t<std::vector<double>>,
59          std::iterator_traits<std::vector<double>::iterator>::difference_type>::value, "");
60  static_assert(
61      std::is_same<
62          v1_dtl::range_difference_t<std::list<double>>,
63          std::iterator_traits<std::list<double>::iterator>::difference_type>::value, "");
64  static_assert(std::is_same<
65                    v1_dtl::range_difference_t<ridiculous_range>,
66                    std::ptrdiff_t>::value, "");
67  
68  // common_range
69  static_assert(v1_dtl::common_range<std::vector<double>>::value, "");
70  static_assert(v1_dtl::common_range<std::list<double>>::value, "");
71  static_assert(!v1_dtl::common_range<ridiculous_range>::value, "");
72  
73  
74  struct no_clear
75  {};
76  
main()77  int main()
78  {
79  
80  {
81      {
82          no_clear nc;
83          v1_dtl::clear_impl<no_clear>::call(nc);
84      }
85      {
86          std::vector<int> vec(10);
87          v1_dtl::clear_impl<std::vector<int>>::call(vec);
88          BOOST_TEST(vec.empty());
89      }
90  }
91  
92  
93  {
94      std::array<int, 5> ints = {{0, 1, 2, 3, 4}};
95      int const new_value = 6;
96      detail::n_iter<int, int> first = detail::make_n_iter(new_value, 3);
97      detail::n_iter<int, int> last = detail::make_n_iter_end(new_value, 3);
98      std::copy(first, last, &ints[1]);
99      BOOST_TEST(ints == (std::array<int, 5>{{0, 6, 6, 6, 4}}));
100  }
101  
102      return boost::report_errors();
103  }
104