]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/icl/include/boost/icl/type_traits/difference_type_of.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / icl / include / boost / icl / type_traits / difference_type_of.hpp
1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2008-2009: Joachim Faulhaber
3 +------------------------------------------------------------------------------+
4 Distributed under the Boost Software License, Version 1.0.
5 (See accompanying file LICENCE.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 +-----------------------------------------------------------------------------*/
8 #ifndef BOOST_ICL_TYPE_TRAITS_DIFFERENCE_TYPE_OF_HPP_JOFA_080911
9 #define BOOST_ICL_TYPE_TRAITS_DIFFERENCE_TYPE_OF_HPP_JOFA_080911
10
11 #include <boost/config.hpp> // For macro BOOST_STATIC_CONSTANT
12 #include <boost/type_traits/is_pointer.hpp>
13 #include <boost/mpl/has_xxx.hpp>
14 #include <boost/mpl/or.hpp>
15 #include <boost/mpl/and.hpp>
16 #include <boost/mpl/not.hpp>
17 #include <boost/icl/type_traits/no_type.hpp>
18 #include <boost/icl/type_traits/is_numeric.hpp>
19 #include <boost/icl/type_traits/rep_type_of.hpp>
20
21 namespace boost{ namespace icl
22 {
23 namespace detail
24 {
25 BOOST_MPL_HAS_XXX_TRAIT_DEF(difference_type)
26 }
27
28 //--------------------------------------------------------------------------
29 template <class Type>
30 struct has_difference_type
31 : mpl::bool_<detail::has_difference_type<Type>::value>
32 {};
33
34 //--------------------------------------------------------------------------
35 template<class Type> // type_of(T-T)==T
36 struct is_subtraction_closed
37 {
38 typedef is_subtraction_closed type;
39 BOOST_STATIC_CONSTANT(bool,
40 value = (mpl::or_< is_numeric<Type>
41 , mpl::and_< has_rep_type<Type>
42 , mpl::not_<has_difference_type<Type> >
43 >
44 >::value)
45 );
46 };
47
48 //--------------------------------------------------------------------------
49 template<class Type>
50 struct has_difference
51 {
52 typedef has_difference type;
53 BOOST_STATIC_CONSTANT(bool,
54 value = (mpl::or_< is_subtraction_closed<Type>
55 , is_pointer<Type>
56 , has_difference_type<Type> >::value)
57 );
58 };
59
60 //--------------------------------------------------------------------------
61 template <class Type, bool has_difference, bool has_diff_type>
62 struct get_difference_type;
63
64 template <class Type>
65 struct get_difference_type<Type, false, false>
66 {
67 typedef no_type type;
68 };
69
70 template <class Type>
71 struct get_difference_type<Type*, true, false>
72 {
73 typedef std::ptrdiff_t type;
74 };
75
76 template <class Type>
77 struct get_difference_type<Type, true, false>
78 {
79 typedef Type type;
80 };
81
82 template <class Type>
83 struct get_difference_type<Type, true, true>
84 {
85 typedef typename Type::difference_type type;
86 };
87
88 //--------------------------------------------------------------------------
89 template<class Type>
90 struct difference_type_of
91 {
92 typedef typename
93 get_difference_type< Type
94 , has_difference<Type>::value
95 , has_difference_type<Type>::value
96 >::type type;
97 };
98
99 }} // namespace boost icl
100
101 #endif
102
103