File indexing completed on 2025-01-18 09:38:09
0001
0002
0003
0004
0005
0006
0007 #ifndef BOOST_HISTOGRAM_AXIS_BOOLEAN_HPP
0008 #define BOOST_HISTOGRAM_AXIS_BOOLEAN_HPP
0009
0010 #include <boost/core/nvp.hpp>
0011 #include <boost/histogram/axis/iterator.hpp>
0012 #include <boost/histogram/axis/metadata_base.hpp>
0013 #include <boost/histogram/axis/option.hpp>
0014 #include <boost/histogram/detail/relaxed_equal.hpp>
0015 #include <boost/histogram/detail/replace_type.hpp>
0016 #include <boost/histogram/fwd.hpp>
0017 #include <string>
0018
0019 namespace boost {
0020 namespace histogram {
0021 namespace axis {
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 template <class MetaData>
0034 class boolean : public iterator_mixin<boolean<MetaData>>,
0035 public metadata_base_t<MetaData> {
0036 using value_type = bool;
0037 using metadata_base = metadata_base_t<MetaData>;
0038 using metadata_type = typename metadata_base::metadata_type;
0039
0040 public:
0041
0042
0043
0044
0045
0046
0047 explicit boolean(metadata_type meta = {}) noexcept(
0048 std::is_nothrow_move_constructible<metadata_type>::value)
0049 : metadata_base(std::move(meta)) {}
0050
0051
0052 index_type index(value_type x) const noexcept { return static_cast<index_type>(x); }
0053
0054
0055 value_type value(index_type i) const noexcept { return static_cast<value_type>(i); }
0056
0057
0058 value_type bin(index_type i) const noexcept { return value(i); }
0059
0060
0061 index_type size() const noexcept { return 2; }
0062
0063
0064 static constexpr bool inclusive() noexcept { return true; }
0065
0066
0067 static constexpr unsigned options() noexcept { return option::none_t::value; }
0068
0069 template <class M>
0070 bool operator==(const boolean<M>& o) const noexcept {
0071 return detail::relaxed_equal{}(this->metadata(), o.metadata());
0072 }
0073
0074 template <class M>
0075 bool operator!=(const boolean<M>& o) const noexcept {
0076 return !operator==(o);
0077 }
0078
0079 template <class Archive>
0080 void serialize(Archive& ar, unsigned ) {
0081 ar& make_nvp("meta", this->metadata());
0082 }
0083
0084 private:
0085 template <class M>
0086 friend class boolean;
0087 };
0088
0089 #if __cpp_deduction_guides >= 201606
0090
0091 boolean()->boolean<null_type>;
0092
0093 template <class M>
0094 boolean(M) -> boolean<detail::replace_type<std::decay_t<M>, const char*, std::string>>;
0095
0096 #endif
0097
0098 }
0099 }
0100 }
0101
0102 #endif