]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/histogram/axis/option.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / histogram / axis / option.hpp
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
7 #ifndef BOOST_HISTOGRAM_AXIS_OPTION_HPP
8 #define BOOST_HISTOGRAM_AXIS_OPTION_HPP
9
10 #include <type_traits>
11
12 /**
13 \file option.hpp Options for builtin axis types.
14
15 Options `circular` and `growth` are mutually exclusive.
16 Options `circular` and `underflow` are mutually exclusive.
17 */
18
19 namespace boost {
20 namespace histogram {
21 namespace axis {
22 namespace option {
23
24 /// Holder of axis options.
25 template <unsigned Bits>
26 struct bitset : std::integral_constant<unsigned, Bits> {
27
28 /// Returns true if all option flags in the argument are set and false otherwise.
29 template <unsigned B>
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))>{};
33 }
34 };
35
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)>{};
40 }
41
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)>{};
46 }
47
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)>{};
52 }
53
54 /**
55 Single option flag.
56
57 @tparam Pos position of the bit in the set.
58 */
59 template <unsigned Pos>
60 struct bit : bitset<(1 << Pos)> {};
61
62 /// All options off.
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>;
72
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`.
78
79 } // namespace option
80 } // namespace axis
81 } // namespace histogram
82 } // namespace boost
83
84 #endif