// Copyright Hans Dembinski 2020 // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) #ifndef BOOST_HISTOGRAM_AXIS_BOOLEAN_HPP #define BOOST_HISTOGRAM_AXIS_BOOLEAN_HPP #include #include #include #include #include #include #include #include namespace boost { namespace histogram { namespace axis { /** Discrete axis for boolean data. Binning is a pass-though operation with zero cost, making this the fastest possible axis. The axis has no internal state apart from the optional metadata state. The axis has no under- and overflow bins. It cannot grow and cannot be reduced. @tparam MetaData type to store meta data. */ template class boolean : public iterator_mixin>, public metadata_base_t { using value_type = bool; using metadata_base = metadata_base_t; using metadata_type = typename metadata_base::metadata_type; public: /** Construct a boolean axis. @param meta description of the axis. The constructor is nothrow if meta is nothrow move constructible. */ explicit boolean(metadata_type meta = {}) noexcept( std::is_nothrow_move_constructible::value) : metadata_base(std::move(meta)) {} /// Return index for value argument. index_type index(value_type x) const noexcept { return static_cast(x); } /// Return value for index argument. value_type value(index_type i) const noexcept { return static_cast(i); } /// Return bin for index argument. value_type bin(index_type i) const noexcept { return value(i); } /// Returns the number of bins, without over- or underflow. index_type size() const noexcept { return 2; } /// Whether the axis is inclusive (see axis::traits::is_inclusive). static constexpr bool inclusive() noexcept { return true; } /// Returns the options. static constexpr unsigned options() noexcept { return option::none_t::value; } template bool operator==(const boolean& o) const noexcept { return detail::relaxed_equal{}(this->metadata(), o.metadata()); } template bool operator!=(const boolean& o) const noexcept { return !operator==(o); } template void serialize(Archive& ar, unsigned /* version */) { ar& make_nvp("meta", this->metadata()); } private: template friend class boolean; }; #if __cpp_deduction_guides >= 201606 boolean()->boolean; template boolean(M) -> boolean, const char*, std::string>>; #endif } // namespace axis } // namespace histogram } // namespace boost #endif // BOOST_HISTOGRAM_AXIS_BOOLEAN_HPP