]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/histogram/axis/boolean.hpp
import quincy beta 17.1.0
[ceph.git] / ceph / src / boost / boost / histogram / axis / boolean.hpp
1 // Copyright Hans Dembinski 2020
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_BOOLEAN_HPP
8 #define BOOST_HISTOGRAM_AXIS_BOOLEAN_HPP
9
10 #include <boost/core/nvp.hpp>
11 #include <boost/histogram/axis/iterator.hpp>
12 #include <boost/histogram/axis/metadata_base.hpp>
13 #include <boost/histogram/axis/option.hpp>
14 #include <boost/histogram/detail/relaxed_equal.hpp>
15 #include <boost/histogram/detail/replace_type.hpp>
16 #include <boost/histogram/fwd.hpp>
17 #include <string>
18
19 namespace boost {
20 namespace histogram {
21 namespace axis {
22
23 /**
24 Discrete axis for boolean data.
25
26 Binning is a pass-though operation with zero cost, making this the
27 fastest possible axis. The axis has no internal state apart from the
28 optional metadata state. The axis has no under- and overflow bins.
29 It cannot grow and cannot be reduced.
30
31 @tparam MetaData type to store meta data.
32 */
33 template <class MetaData>
34 class boolean : public iterator_mixin<boolean<MetaData>>,
35 public metadata_base_t<MetaData> {
36 using value_type = bool;
37 using metadata_base = metadata_base_t<MetaData>;
38 using metadata_type = typename metadata_base::metadata_type;
39
40 public:
41 /** Construct a boolean axis.
42 *
43 * \param meta description of the axis.
44 */
45 explicit boolean(metadata_type meta = {}) : metadata_base(std::move(meta)) {}
46
47 /// Return index for value argument.
48 index_type index(value_type x) const noexcept { return static_cast<index_type>(x); }
49
50 /// Return value for index argument.
51 value_type value(index_type i) const noexcept { return static_cast<value_type>(i); }
52
53 /// Return bin for index argument.
54 value_type bin(index_type i) const noexcept { return value(i); }
55
56 /// Returns the number of bins, without over- or underflow.
57 index_type size() const noexcept { return 2; }
58
59 /// Whether the axis is inclusive (see axis::traits::is_inclusive).
60 static constexpr bool inclusive() noexcept { return true; }
61
62 /// Returns the options.
63 static constexpr unsigned options() noexcept { return option::none_t::value; }
64
65 template <class M>
66 bool operator==(const boolean<M>& o) const noexcept {
67 return detail::relaxed_equal{}(this->metadata(), o.metadata());
68 }
69
70 template <class M>
71 bool operator!=(const boolean<M>& o) const noexcept {
72 return !operator==(o);
73 }
74
75 template <class Archive>
76 void serialize(Archive& ar, unsigned /* version */) {
77 ar& make_nvp("meta", this->metadata());
78 }
79
80 private:
81 template <class M>
82 friend class boolean;
83 };
84
85 #if __cpp_deduction_guides >= 201606
86
87 boolean()->boolean<null_type>;
88
89 template <class M>
90 boolean(M) -> boolean<detail::replace_type<std::decay_t<M>, const char*, std::string>>;
91
92 #endif
93
94 } // namespace axis
95 } // namespace histogram
96 } // namespace boost
97
98 #endif // BOOST_HISTOGRAM_AXIS_BOOLEAN_HPP