weight.hpp 1021 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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. #ifndef BOOST_HISTOGRAM_WEIGHT_HPP
  7. #define BOOST_HISTOGRAM_WEIGHT_HPP
  8. #include <utility>
  9. namespace boost {
  10. namespace histogram {
  11. /** Weight holder and type envelope.
  12. You should not construct these directly, use the weight() helper function.
  13. @tparam Underlying arithmetic type.
  14. */
  15. template <class T>
  16. struct weight_type {
  17. /// Access underlying value.
  18. T value;
  19. /// Allow implicit conversions of types when the underlying value type allows them.
  20. template <class U>
  21. operator weight_type<U>() const {
  22. return weight_type<U>{static_cast<U>(value)};
  23. }
  24. };
  25. /** Helper function to mark argument as weight.
  26. @param t argument to be forward to the histogram.
  27. */
  28. template <class T>
  29. auto weight(T&& t) noexcept {
  30. return weight_type<T>{std::forward<T>(t)};
  31. }
  32. } // namespace histogram
  33. } // namespace boost
  34. #endif