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
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>
21 namespace boost{ namespace icl
25 BOOST_MPL_HAS_XXX_TRAIT_DEF(difference_type)
28 //--------------------------------------------------------------------------
30 struct has_difference_type
31 : mpl::bool_<detail::has_difference_type<Type>::value>
34 //--------------------------------------------------------------------------
35 template<class Type> // type_of(T-T)==T
36 struct is_subtraction_closed
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> >
48 //--------------------------------------------------------------------------
52 typedef has_difference type;
53 BOOST_STATIC_CONSTANT(bool,
54 value = (mpl::or_< is_subtraction_closed<Type>
56 , has_difference_type<Type> >::value)
60 //--------------------------------------------------------------------------
61 template <class Type, bool has_difference, bool has_diff_type>
62 struct get_difference_type;
65 struct get_difference_type<Type, false, false>
71 struct get_difference_type<Type*, true, false>
73 typedef std::ptrdiff_t type;
77 struct get_difference_type<Type, true, false>
83 struct get_difference_type<Type, true, true>
85 typedef typename Type::difference_type type;
88 //--------------------------------------------------------------------------
90 struct difference_type_of
93 get_difference_type< Type
94 , has_difference<Type>::value
95 , has_difference_type<Type>::value
99 }} // namespace boost icl