Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Copyright 2015-2019 Hans Dembinski
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_OPTION_HPP
0008 #define BOOST_HISTOGRAM_AXIS_OPTION_HPP
0009 
0010 #include <type_traits>
0011 
0012 /**
0013   \file option.hpp Options for builtin axis types.
0014 
0015   Options `circular` and `growth` are mutually exclusive.
0016   Options `circular` and `underflow` are mutually exclusive.
0017 */
0018 
0019 namespace boost {
0020 namespace histogram {
0021 namespace axis {
0022 namespace option {
0023 
0024 /// Holder of axis options.
0025 template <unsigned Bits>
0026 struct bitset : std::integral_constant<unsigned, Bits> {
0027 
0028   /// Returns true if all option flags in the argument are set and false otherwise.
0029   template <unsigned B>
0030   static constexpr auto test(bitset<B>) {
0031     // B + 0 needed to avoid false positive -Wtautological-compare in gcc-6
0032     return std::integral_constant<bool, static_cast<bool>((Bits & B) == (B + 0))>{};
0033   }
0034 };
0035 
0036 /// Set union of the axis option arguments.
0037 template <unsigned B1, unsigned B2>
0038 constexpr auto operator|(bitset<B1>, bitset<B2>) {
0039   return bitset<(B1 | B2)>{};
0040 }
0041 
0042 /// Set intersection of the option arguments.
0043 template <unsigned B1, unsigned B2>
0044 constexpr auto operator&(bitset<B1>, bitset<B2>) {
0045   return bitset<(B1 & B2)>{};
0046 }
0047 
0048 /// Set difference of the option arguments.
0049 template <unsigned B1, unsigned B2>
0050 constexpr auto operator-(bitset<B1>, bitset<B2>) {
0051   return bitset<(B1 & ~B2)>{};
0052 }
0053 
0054 /**
0055   Single option flag.
0056 
0057   @tparam Pos position of the bit in the set.
0058 */
0059 template <unsigned Pos>
0060 #ifndef BOOST_HISTOGRAM_DOXYGEN_INVOKED
0061 using bit = bitset<(1 << Pos)>;
0062 #else
0063 struct bit;
0064 #endif
0065 
0066 /// All options off.
0067 using none_t = bitset<0>;
0068 /// Axis has an underflow bin. Mutually exclusive with `circular`.
0069 using underflow_t = bit<0>;
0070 /// Axis has overflow bin.
0071 using overflow_t = bit<1>;
0072 /// Axis is circular. Mutually exclusive with `growth` and `underflow`.
0073 using circular_t = bit<2>;
0074 /// Axis can grow. Mutually exclusive with `circular`.
0075 using growth_t = bit<3>;
0076 
0077 constexpr none_t none{};           ///< Instance of `none_t`.
0078 constexpr underflow_t underflow{}; ///< Instance of `underflow_t`.
0079 constexpr overflow_t overflow{};   ///< Instance of `overflow_t`.
0080 constexpr circular_t circular{};   ///< Instance of `circular_t`.
0081 constexpr growth_t growth{};       ///< Instance of `growth_t`.
0082 
0083 } // namespace option
0084 } // namespace axis
0085 } // namespace histogram
0086 } // namespace boost
0087 
0088 #endif