parameter.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // boost lockfree
  2. //
  3. // Copyright (C) 2011 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. namespace boost {
  12. namespace lockfree {
  13. namespace detail {
  14. namespace mpl = boost::mpl;
  15. template <typename bound_args, typename tag_type>
  16. struct has_arg
  17. {
  18. typedef typename parameter::binding<bound_args, tag_type, mpl::void_>::type type;
  19. static const bool value = mpl::is_not_void_<type>::type::value;
  20. };
  21. template <typename bound_args>
  22. struct extract_capacity
  23. {
  24. static const bool has_capacity = has_arg<bound_args, tag::capacity>::value;
  25. typedef typename mpl::if_c<has_capacity,
  26. typename has_arg<bound_args, tag::capacity>::type,
  27. mpl::size_t< 0 >
  28. >::type capacity_t;
  29. static const std::size_t capacity = capacity_t::value;
  30. };
  31. template <typename bound_args, typename T>
  32. struct extract_allocator
  33. {
  34. static const bool has_allocator = has_arg<bound_args, tag::allocator>::value;
  35. typedef typename mpl::if_c<has_allocator,
  36. typename has_arg<bound_args, tag::allocator>::type,
  37. std::allocator<T>
  38. >::type allocator_arg;
  39. typedef typename allocator_arg::template rebind<T>::other type;
  40. };
  41. template <typename bound_args, bool default_ = false>
  42. struct extract_fixed_sized
  43. {
  44. static const bool has_fixed_sized = has_arg<bound_args, tag::fixed_sized>::value;
  45. typedef typename mpl::if_c<has_fixed_sized,
  46. typename has_arg<bound_args, tag::fixed_sized>::type,
  47. mpl::bool_<default_>
  48. >::type type;
  49. static const bool value = type::value;
  50. };
  51. } /* namespace detail */
  52. } /* namespace lockfree */
  53. } /* namespace boost */
  54. #endif /* BOOST_LOCKFREE_DETAIL_PARAMETER_HPP */