option.hpp 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Copyright 2015-2019 Hans Dembinski
  2. //
  3. // Distributed under the Boost Software License, Version 1.0.
  4. // (See accompanying file LICENSE_1_0.txt
  5. // or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_HISTOGRAM_AXIS_OPTION_HPP
  7. #define BOOST_HISTOGRAM_AXIS_OPTION_HPP
  8. #include <boost/mp11.hpp>
  9. #include <type_traits>
  10. /**
  11. \file option.hpp Options for builtin axis types.
  12. Options `circular` and `growth` are mutually exclusive.
  13. Options `circular` and `underflow` are mutually exclusive.
  14. */
  15. namespace boost {
  16. namespace histogram {
  17. namespace axis {
  18. namespace option {
  19. /// Holder of axis options.
  20. template <unsigned Bits>
  21. struct bitset : std::integral_constant<unsigned, Bits> {
  22. /// Returns true if all option flags in the argument are set and false otherwise.
  23. template <unsigned B>
  24. static constexpr auto test(bitset<B>) {
  25. return std::integral_constant<bool, static_cast<bool>(Bits & B)>{};
  26. }
  27. };
  28. /// Set union of the axis option arguments.
  29. template <unsigned B1, unsigned B2>
  30. constexpr auto operator|(bitset<B1>, bitset<B2>) {
  31. return bitset<(B1 | B2)>{};
  32. }
  33. /// Set intersection of the option arguments.
  34. template <unsigned B1, unsigned B2>
  35. constexpr auto operator&(bitset<B1>, bitset<B2>) {
  36. return bitset<(B1 & B2)>{};
  37. }
  38. /// Set difference of the option arguments.
  39. template <unsigned B1, unsigned B2>
  40. constexpr auto operator-(bitset<B1>, bitset<B2>) {
  41. return bitset<(B1 & ~B2)>{};
  42. }
  43. /**
  44. Single option flag.
  45. @tparam Pos position of the bit in the set.
  46. */
  47. template <unsigned Pos>
  48. struct bit : bitset<(1 << Pos)> {};
  49. /// All options off.
  50. using none_t = bitset<0>;
  51. constexpr none_t none{}; ///< Instance of `none_t`.
  52. /// Axis has an underflow bin. Mutually exclusive with `circular`.
  53. using underflow_t = bit<0>;
  54. constexpr underflow_t underflow{}; ///< Instance of `underflow_t`.
  55. /// Axis has overflow bin.
  56. using overflow_t = bit<1>;
  57. constexpr overflow_t overflow{}; ///< Instance of `overflow_t`.
  58. /// Axis is circular. Mutually exclusive with `growth` and `underflow`.
  59. using circular_t = bit<2>;
  60. constexpr circular_t circular{}; ///< Instance of `circular_t`.
  61. /// Axis can grow. Mutually exclusive with `circular`.
  62. using growth_t = bit<3>;
  63. constexpr growth_t growth{}; ///< Instance of `growth_t`.
  64. } // namespace option
  65. } // namespace axis
  66. } // namespace histogram
  67. } // namespace boost
  68. #endif