]> git.sesse.net Git - casparcg/blob - dependencies/boost/boost/units/detail/push_front_or_add.hpp
Manually merged pull request #222
[casparcg] / dependencies / boost / boost / units / detail / push_front_or_add.hpp
1 // Boost.Units - A C++ library for zero-overhead dimensional analysis and 
2 // unit/quantity manipulation and conversion
3 //
4 // Copyright (C) 2003-2008 Matthias Christian Schabel
5 // Copyright (C) 2008 Steven Watanabe
6 //
7 // Distributed under the Boost Software License, Version 1.0. (See
8 // accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11 #ifndef BOOST_UNITS_DETAIL_PUSH_FRONT_OR_ADD_HPP
12 #define BOOST_UNITS_DETAIL_PUSH_FRONT_OR_ADD_HPP
13
14 #include <boost/mpl/plus.hpp>
15 #include <boost/mpl/front.hpp>
16 #include <boost/mpl/push_front.hpp>
17 #include <boost/mpl/pop_front.hpp>
18 #include <boost/type_traits/is_same.hpp>
19
20 #include <boost/units/units_fwd.hpp>
21 #include <boost/units/detail/push_front_if.hpp>
22
23 namespace boost {
24
25 namespace units {
26
27 template<class Item, class Next>
28 struct list;
29
30 namespace detail {
31
32 template<class T>
33 struct is_empty_dim;
34
35 /// add an instantiation of dim to Sequence.
36 template<bool>
37 struct push_front_or_add_impl;
38
39 template<>
40 struct push_front_or_add_impl<true>
41 {
42     template<typename Sequence, typename T>
43     struct apply
44     {
45         typedef typename mpl::plus<T, typename Sequence::item>::type item;
46         typedef typename push_front_if<!is_empty_dim<item>::value>::template apply<
47             typename Sequence::next,
48             item
49         > type;
50     };
51 };
52
53 template<>
54 struct push_front_or_add_impl<false>
55 {
56     template<typename Sequence, typename T>
57     struct apply
58     {
59         typedef list<T, Sequence> type;
60     };
61 };
62
63 template<typename Sequence, typename T>
64 struct push_front_or_add
65 {
66     typedef typename push_front_or_add_impl<boost::is_same<typename T::tag_type, typename Sequence::item::tag_type>::value>::template apply<
67         Sequence,
68         T
69     >::type type;
70 };
71
72 template<typename T>
73 struct push_front_or_add<dimensionless_type, T>
74 {
75     typedef list<T, dimensionless_type> type;
76 };
77
78 } // namespace detail
79
80 } // namespace units
81
82 } // namespace boost
83
84 #endif