1 /*-----------------------------------------------------------------------------+
2 Copyright (c) 2008-2011: 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_SUCC_PRED_HPP_JOFA_080913
9 #define BOOST_ICL_TYPE_TRAITS_SUCC_PRED_HPP_JOFA_080913
11 #include <boost/icl/type_traits/is_increasing.hpp>
13 namespace boost{ namespace icl
15 template <class IncrementableT>
16 inline static IncrementableT succ(IncrementableT x) { return ++x; }
18 template <class DecrementableT>
19 inline static DecrementableT pred(DecrementableT x) { return --x; }
23 template <class DomainT, bool increasing = true>
26 template <class DomainT>
27 struct successor<DomainT, true>
29 typedef successor type;
30 inline static DomainT apply(DomainT value){ return ++value; }
33 template <class DomainT>
34 struct successor<DomainT, false>
36 typedef successor type;
37 inline static DomainT apply(DomainT value){ return --value; }
40 template <class DomainT, bool increasing = true>
43 template <class DomainT>
44 struct predecessor<DomainT, true>
46 typedef predecessor type;
47 inline static DomainT apply(DomainT value){ return --value; }
50 template <class DomainT>
51 struct predecessor<DomainT, false>
53 typedef predecessor type;
54 inline static DomainT apply(DomainT value){ return ++value; }
58 //------------------------------------------------------------------------------
59 template <class DomainT, class Compare>
62 inline static DomainT apply(DomainT value)
64 return detail::successor
65 <DomainT, is_increasing<DomainT,Compare>::value>::apply(value);
69 template <class DomainT, class Compare>
72 inline static DomainT apply(DomainT value)
74 return detail::predecessor
75 <DomainT, is_increasing<DomainT,Compare>::value>::apply(value);
79 }} // namespace boost icl