• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2019 Hans Dembinski
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_WEIGHT_HPP
8 #define BOOST_HISTOGRAM_WEIGHT_HPP
9 
10 #include <utility>
11 
12 namespace boost {
13 namespace histogram {
14 
15 /** Weight holder and type envelope.
16 
17   You should not construct these directly, use the weight() helper function.
18 
19   @tparam Underlying arithmetic type.
20 */
21 template <class T>
22 struct weight_type {
23   /// Access underlying value.
24   T value;
25 
26   /// Allow implicit conversions of types when the underlying value type allows them.
27   template <class U>
operator weight_type<U>boost::histogram::weight_type28   operator weight_type<U>() const {
29     return weight_type<U>{static_cast<U>(value)};
30   }
31 };
32 
33 /** Helper function to mark argument as weight.
34 
35   @param t argument to be forward to the histogram.
36 */
37 template <class T>
weight(T && t)38 auto weight(T&& t) noexcept {
39   return weight_type<T>{std::forward<T>(t)};
40 }
41 
42 } // namespace histogram
43 } // namespace boost
44 
45 #endif
46