1
2// Copyright 2015 Peter Dimov.
3//
4// Distributed under the Boost Software License, Version 1.0.
5//
6// See accompanying file LICENSE_1_0.txt or copy at
7// http://www.boost.org/LICENSE_1_0.txt
8
9
10#include <boost/mp11/detail/config.hpp>
11
12#if BOOST_MP11_MSVC
13# pragma warning( disable: 4503 ) // decorated name length exceeded
14#endif
15
16#include <boost/mp11/algorithm.hpp>
17#include <boost/mp11/list.hpp>
18#include <boost/mp11/integral.hpp>
19#include <boost/core/lightweight_test_trait.hpp>
20#include <type_traits>
21#include <tuple>
22#include <utility>
23
24struct X1 {};
25struct X2 {};
26struct X3 {};
27
28int main()
29{
30 using boost::mp11::mp_list;
31 using boost::mp11::mp_count;
32 using boost::mp11::mp_size_t;
33
34 {
35 using L1 = mp_list<>;
36
37 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L1, void>, mp_size_t<0>>));
38
39 using L2 = mp_list<X1, X2, X3, X2, X3, X3>;
40
41 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L2, void>, mp_size_t<0>>));
42 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L2, X1>, mp_size_t<1>>));
43 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L2, X2>, mp_size_t<2>>));
44 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L2, X3>, mp_size_t<3>>));
45 }
46
47 {
48 using L3 = std::tuple<>;
49
50 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L3, void>, mp_size_t<0>>));
51
52 using L4 = std::tuple<X1, X2, X3, X2, X3, X3>;
53
54 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L4, void>, mp_size_t<0>>));
55 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L4, X1>, mp_size_t<1>>));
56 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L4, X2>, mp_size_t<2>>));
57 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L4, X3>, mp_size_t<3>>));
58 }
59
60 {
61 using L5 = std::pair<X1, X2>;
62
63 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L5, void>, mp_size_t<0>>));
64 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L5, X1>, mp_size_t<1>>));
65 BOOST_TEST_TRAIT_TRUE((std::is_same<mp_count<L5, X2>, mp_size_t<1>>));
66 }
67
68 {
69 using boost::mp11::mp_repeat_c;
70
71 int const N = 1089;
72
73 using L = mp_repeat_c<mp_list<void>, N>;
74 using R = mp_count<L, void>;
75
76 BOOST_TEST_TRAIT_TRUE((std::is_same<R, mp_size_t<N>>));
77 }
78
79 return boost::report_errors();
80}
81

source code of boost/libs/mp11/test/mp_count.cpp