parameter.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. // boost lockfree
  2. //
  3. // Copyright (C) 2011, 2016 Tim Blechmann
  4. //
  5. // Distributed under the Boost Software License, Version 1.0. (See
  6. // accompanying file LICENSE_1_0.txt or copy at
  7. // http://www.boost.org/LICENSE_1_0.txt)
  8. #ifndef BOOST_LOCKFREE_DETAIL_PARAMETER_HPP
  9. #define BOOST_LOCKFREE_DETAIL_PARAMETER_HPP
  10. #include <boost/lockfree/policies.hpp>
  11. #include <boost/parameter/parameters.hpp>
  12. #include <boost/parameter/binding.hpp>
  13. #include <boost/mpl/void.hpp>
  14. #include <boost/lockfree/detail/allocator_rebind_helper.hpp>
  15. namespace boost {
  16. namespace lockfree {
  17. namespace detail {
  18. namespace mpl = boost::mpl;
  19. template <typename bound_args, typename tag_type>
  20. struct has_arg
  21. {
  22. typedef typename parameter::binding<bound_args, tag_type, mpl::void_>::type type;
  23. static const bool value = mpl::is_not_void_<type>::type::value;
  24. };
  25. template <typename bound_args>
  26. struct extract_capacity
  27. {
  28. static const bool has_capacity = has_arg<bound_args, tag::capacity>::value;
  29. typedef typename mpl::if_c<has_capacity,
  30. typename has_arg<bound_args, tag::capacity>::type,
  31. mpl::size_t< 0 >
  32. >::type capacity_t;
  33. static const std::size_t capacity = capacity_t::value;
  34. };
  35. template <typename bound_args, typename T>
  36. struct extract_allocator
  37. {
  38. static const bool has_allocator = has_arg<bound_args, tag::allocator>::value;
  39. typedef typename mpl::if_c<has_allocator,
  40. typename has_arg<bound_args, tag::allocator>::type,
  41. std::allocator<T>
  42. >::type allocator_arg;
  43. typedef typename detail::allocator_rebind_helper<allocator_arg, T>::type type;
  44. };
  45. template <typename bound_args, bool default_ = false>
  46. struct extract_fixed_sized
  47. {
  48. static const bool has_fixed_sized = has_arg<bound_args, tag::fixed_sized>::value;
  49. typedef typename mpl::if_c<has_fixed_sized,
  50. typename has_arg<bound_args, tag::fixed_sized>::type,
  51. mpl::bool_<default_>
  52. >::type type;
  53. static const bool value = type::value;
  54. };
  55. } /* namespace detail */
  56. } /* namespace lockfree */
  57. } /* namespace boost */
  58. #endif /* BOOST_LOCKFREE_DETAIL_PARAMETER_HPP */