parameter.hpp 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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/align/aligned_allocator.hpp>
  11. #include <boost/core/allocator_access.hpp>
  12. #include <boost/lockfree/detail/prefix.hpp>
  13. #include <boost/lockfree/policies.hpp>
  14. #include <boost/parameter/binding.hpp>
  15. #include <boost/parameter/parameters.hpp>
  16. #include <boost/mpl/void.hpp>
  17. namespace boost {
  18. namespace lockfree {
  19. namespace detail {
  20. namespace mpl = boost::mpl;
  21. template <typename bound_args, typename tag_type>
  22. struct has_arg
  23. {
  24. typedef typename parameter::binding<bound_args, tag_type, mpl::void_>::type type;
  25. static const bool value = mpl::is_not_void_<type>::type::value;
  26. };
  27. template <typename bound_args>
  28. struct extract_capacity
  29. {
  30. static const bool has_capacity = has_arg<bound_args, tag::capacity>::value;
  31. typedef typename mpl::if_c<has_capacity,
  32. typename has_arg<bound_args, tag::capacity>::type,
  33. mpl::size_t< 0 >
  34. >::type capacity_t;
  35. static const std::size_t capacity = capacity_t::value;
  36. };
  37. template <typename bound_args, typename T>
  38. struct extract_allocator
  39. {
  40. static const bool has_allocator = has_arg<bound_args, tag::allocator>::value;
  41. typedef typename mpl::if_c<has_allocator,
  42. typename has_arg<bound_args, tag::allocator>::type,
  43. boost::alignment::aligned_allocator<T, BOOST_LOCKFREE_CACHELINE_BYTES>
  44. >::type allocator_arg;
  45. typedef typename boost::allocator_rebind<allocator_arg, T>::type type;
  46. };
  47. template <typename bound_args, bool default_ = false>
  48. struct extract_fixed_sized
  49. {
  50. static const bool has_fixed_sized = has_arg<bound_args, tag::fixed_sized>::value;
  51. typedef typename mpl::if_c<has_fixed_sized,
  52. typename has_arg<bound_args, tag::fixed_sized>::type,
  53. mpl::bool_<default_>
  54. >::type type;
  55. static const bool value = type::value;
  56. };
  57. } /* namespace detail */
  58. } /* namespace lockfree */
  59. } /* namespace boost */
  60. #endif /* BOOST_LOCKFREE_DETAIL_PARAMETER_HPP */