option.hpp 2.3 KB

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