1 // Copyright 2015-2019 Hans Dembinski
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)
7 #ifndef BOOST_HISTOGRAM_AXIS_OPTION_HPP
8 #define BOOST_HISTOGRAM_AXIS_OPTION_HPP
10 #include <type_traits>
13 \file option.hpp Options for builtin axis types.
15 Options `circular` and `growth` are mutually exclusive.
16 Options `circular` and `underflow` are mutually exclusive.
24 /// Holder of axis options.
25 template <unsigned Bits>
26 struct bitset : std::integral_constant<unsigned, Bits> {
28 /// Returns true if all option flags in the argument are set and false otherwise.
30 static constexpr auto test(bitset<B>) {
31 // B + 0 needed to avoid false positive -Wtautological-compare in gcc-6
32 return std::integral_constant<bool, static_cast<bool>((Bits & B) == (B + 0))>{};
36 /// Set union of the axis option arguments.
37 template <unsigned B1, unsigned B2>
38 constexpr auto operator|(bitset<B1>, bitset<B2>) {
39 return bitset<(B1 | B2)>{};
42 /// Set intersection of the option arguments.
43 template <unsigned B1, unsigned B2>
44 constexpr auto operator&(bitset<B1>, bitset<B2>) {
45 return bitset<(B1 & B2)>{};
48 /// Set difference of the option arguments.
49 template <unsigned B1, unsigned B2>
50 constexpr auto operator-(bitset<B1>, bitset<B2>) {
51 return bitset<(B1 & ~B2)>{};
57 @tparam Pos position of the bit in the set.
59 template <unsigned Pos>
60 struct bit : bitset<(1 << Pos)> {};
63 using none_t = bitset<0>;
64 /// Axis has an underflow bin. Mutually exclusive with `circular`.
65 using underflow_t = bit<0>;
66 /// Axis has overflow bin.
67 using overflow_t = bit<1>;
68 /// Axis is circular. Mutually exclusive with `growth` and `underflow`.
69 using circular_t = bit<2>;
70 /// Axis can grow. Mutually exclusive with `circular`.
71 using growth_t = bit<3>;
73 constexpr none_t none{}; ///< Instance of `none_t`.
74 constexpr underflow_t underflow{}; ///< Instance of `underflow_t`.
75 constexpr overflow_t overflow{}; ///< Instance of `overflow_t`.
76 constexpr circular_t circular{}; ///< Instance of `circular_t`.
77 constexpr growth_t growth{}; ///< Instance of `growth_t`.
81 } // namespace histogram