Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:09

0001 // Copyright Hans Dembinski 2020
0002 //
0003 // Distributed under the Boost Software License, Version 1.0.
0004 // (See accompanying file LICENSE_1_0.txt
0005 // or copy at http://www.boost.org/LICENSE_1_0.txt)
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   Discrete axis for boolean data.
0025 
0026   Binning is a pass-though operation with zero cost, making this the
0027   fastest possible axis. The axis has no internal state apart from the
0028   optional metadata state. The axis has no under- and overflow bins.
0029   It cannot grow and cannot be reduced.
0030 
0031   @tparam MetaData type to store meta data.
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   /** Construct a boolean axis.
0042 
0043     @param meta description of the axis.
0044 
0045     The constructor is nothrow if meta is nothrow move constructible.
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   /// Return index for value argument.
0052   index_type index(value_type x) const noexcept { return static_cast<index_type>(x); }
0053 
0054   /// Return value for index argument.
0055   value_type value(index_type i) const noexcept { return static_cast<value_type>(i); }
0056 
0057   /// Return bin for index argument.
0058   value_type bin(index_type i) const noexcept { return value(i); }
0059 
0060   /// Returns the number of bins, without over- or underflow.
0061   index_type size() const noexcept { return 2; }
0062 
0063   /// Whether the axis is inclusive (see axis::traits::is_inclusive).
0064   static constexpr bool inclusive() noexcept { return true; }
0065 
0066   /// Returns the options.
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 /* version */) {
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 } // namespace axis
0099 } // namespace histogram
0100 } // namespace boost
0101 
0102 #endif // BOOST_HISTOGRAM_AXIS_BOOLEAN_HPP