MPL11
 All Classes Namespaces Files Typedefs Macros Groups Pages
check_finite_iterable.hpp
Go to the documentation of this file.
1 
7 #ifndef BOOST_MPL11_TEST_CHECK_FINITE_ITERABLE_HPP
8 #define BOOST_MPL11_TEST_CHECK_FINITE_ITERABLE_HPP
9 
12 #include <boost/mpl11/integer.hpp>
13 
14 #include "minimal_iterable.hpp"
15 #include "static_assert.hpp"
16 
17 
18 namespace check_finite_iter_detail {
19  using namespace boost::mpl11;
21 
22  template <typename x, typename y,
23  typename Expected = typename x::type,
24  typename Actual = typename y::type>
25  using assert_eq = static_assert_<equal<x, y>>;
26 
27  template <typename reference, typename iter,
28  typename index = size_t<0>,
30  struct impl;
31 
32  template <typename reference, typename iter>
33  struct impl<reference, iter, size_t<length<reference>::value>, false>
34  : assert_eq<head<reference>, head<iter>>
35  , assert_eq<tail<reference>, tail<iter>>
36  , assert_eq<is_empty<reference>, is_empty<iter>>
37 
38  , assert_eq<last<reference>, last<iter>>
39  , assert_eq<length<reference>, length<iter>>
40  { };
41 
42  template <typename reference, typename iter, typename index>
43  struct impl<reference, iter, index, false>
44  : assert_eq<at<index, reference>, at<index, iter>>
45  , impl<reference, iter, size_t<index::type::value + 1>>
46  { };
47 
48  template <typename reference, typename iter, typename index>
49  struct impl<reference, iter, index, true>
50  : static_assert_<is_empty<iter>>
51  , assert_eq<size_t<0>, length<iter>>
52  { };
53 } // end namespace check_finite_iter_detail
54 
55 
63 template <typename iter, typename ...xs>
65  check_finite_iter_detail::impl<minimal_iterable<xs...>, iter>;
66 
67 #endif // !BOOST_MPL11_TEST_CHECK_FINITE_ITERABLE_HPP
Defines the Integer datatype.
Defines the minimal_iterable helper for unit tests.
Forward declares the Iterable typeclass.
Minimal iterable for testing purposes.
Definition: minimal_iterable.hpp:26
Returns whether the iterable is empty.
Definition: iterable.hpp:101
check_finite_iter_detail::impl< minimal_iterable< xs...>, iter > check_finite_iterable
Generic unit test for finite iterables.
Definition: check_finite_iterable.hpp:65
Alias to integer_c; provided for convenience.
Definition: integer.hpp:122
Forward declares the Comparable typeclass.
Defines the static_assert_ helper for unit tests.
Returns the given boolean expression and statically asserts that its value is true.
Definition: static_assert.hpp:22
Returns the number of elements in a finite iterable.
Definition: iterable.hpp:89