ord_index_args.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /* Copyright 2003-2013 Joaquin M Lopez Munoz.
  2. * Distributed under the Boost Software License, Version 1.0.
  3. * (See accompanying file LICENSE_1_0.txt or copy at
  4. * http://www.boost.org/LICENSE_1_0.txt)
  5. *
  6. * See http://www.boost.org/libs/multi_index for library home page.
  7. */
  8. #ifndef BOOST_MULTI_INDEX_DETAIL_ORD_INDEX_ARGS_HPP
  9. #define BOOST_MULTI_INDEX_DETAIL_ORD_INDEX_ARGS_HPP
  10. #if defined(_MSC_VER)
  11. #pragma once
  12. #endif
  13. #include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */
  14. #include <boost/mpl/aux_/na.hpp>
  15. #include <boost/mpl/eval_if.hpp>
  16. #include <boost/mpl/identity.hpp>
  17. #include <boost/mpl/if.hpp>
  18. #include <boost/multi_index/tag.hpp>
  19. #include <boost/static_assert.hpp>
  20. #include <boost/type_traits/is_same.hpp>
  21. #include <functional>
  22. namespace boost{
  23. namespace multi_index{
  24. namespace detail{
  25. /* Oredered index specifiers can be instantiated in two forms:
  26. *
  27. * (ordered_unique|ordered_non_unique)<
  28. * KeyFromValue,Compare=std::less<KeyFromValue::result_type> >
  29. * (ordered_unique|ordered_non_unique)<
  30. * TagList,KeyFromValue,Compare=std::less<KeyFromValue::result_type> >
  31. *
  32. * index_args implements the machinery to accept this argument-dependent
  33. * polymorphism.
  34. */
  35. template<typename KeyFromValue>
  36. struct index_args_default_compare
  37. {
  38. typedef std::less<typename KeyFromValue::result_type> type;
  39. };
  40. template<typename Arg1,typename Arg2,typename Arg3>
  41. struct ordered_index_args
  42. {
  43. typedef is_tag<Arg1> full_form;
  44. typedef typename mpl::if_<
  45. full_form,
  46. Arg1,
  47. tag< > >::type tag_list_type;
  48. typedef typename mpl::if_<
  49. full_form,
  50. Arg2,
  51. Arg1>::type key_from_value_type;
  52. typedef typename mpl::if_<
  53. full_form,
  54. Arg3,
  55. Arg2>::type supplied_compare_type;
  56. typedef typename mpl::eval_if<
  57. mpl::is_na<supplied_compare_type>,
  58. index_args_default_compare<key_from_value_type>,
  59. mpl::identity<supplied_compare_type>
  60. >::type compare_type;
  61. BOOST_STATIC_ASSERT(is_tag<tag_list_type>::value);
  62. BOOST_STATIC_ASSERT(!mpl::is_na<key_from_value_type>::value);
  63. BOOST_STATIC_ASSERT(!mpl::is_na<compare_type>::value);
  64. };
  65. } /* namespace multi_index::detail */
  66. } /* namespace multi_index */
  67. } /* namespace boost */
  68. #endif