succ_pred.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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
  10. #include <boost/icl/type_traits/is_increasing.hpp>
  11. namespace boost{ namespace icl
  12. {
  13. template <class IncrementableT>
  14. inline static IncrementableT succ(IncrementableT x) { return ++x; }
  15. template <class DecrementableT>
  16. inline static DecrementableT pred(DecrementableT x) { return --x; }
  17. namespace detail
  18. {
  19. template <class DomainT, bool increasing = true>
  20. struct successor;
  21. template <class DomainT>
  22. struct successor<DomainT, true>
  23. {
  24. typedef successor type;
  25. inline static DomainT apply(DomainT value){ return ++value; }
  26. };
  27. template <class DomainT>
  28. struct successor<DomainT, false>
  29. {
  30. typedef successor type;
  31. inline static DomainT apply(DomainT value){ return --value; }
  32. };
  33. template <class DomainT, bool increasing = true>
  34. struct predecessor;
  35. template <class DomainT>
  36. struct predecessor<DomainT, true>
  37. {
  38. typedef predecessor type;
  39. inline static DomainT apply(DomainT value){ return --value; }
  40. };
  41. template <class DomainT>
  42. struct predecessor<DomainT, false>
  43. {
  44. typedef predecessor type;
  45. inline static DomainT apply(DomainT value){ return ++value; }
  46. };
  47. } // namespace detail
  48. //------------------------------------------------------------------------------
  49. template <class DomainT, class Compare>
  50. struct successor
  51. {
  52. inline static DomainT apply(DomainT value)
  53. {
  54. return detail::successor
  55. <DomainT, is_increasing<DomainT,Compare>::value>::apply(value);
  56. }
  57. };
  58. template <class DomainT, class Compare>
  59. struct predecessor
  60. {
  61. inline static DomainT apply(DomainT value)
  62. {
  63. return detail::predecessor
  64. <DomainT, is_increasing<DomainT,Compare>::value>::apply(value);
  65. }
  66. };
  67. }} // namespace boost icl
  68. #endif