sample.hpp 858 B

123456789101112131415161718192021222324252627282930313233343536373839
  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_SAMPLE_HPP
  7. #define BOOST_HISTOGRAM_SAMPLE_HPP
  8. #include <tuple>
  9. #include <utility>
  10. namespace boost {
  11. namespace histogram {
  12. /** Sample holder and type envelope.
  13. You should not construct these directly, use the sample() helper function.
  14. @tparam Underlying type.
  15. */
  16. template <class T>
  17. struct sample_type {
  18. T value;
  19. };
  20. /** Helper function to mark arguments as sample.
  21. @param ts arguments to be forwarded to the accumulator.
  22. */
  23. template <class... Ts>
  24. auto sample(Ts&&... ts) noexcept {
  25. return sample_type<std::tuple<Ts...>>{std::forward_as_tuple(std::forward<Ts>(ts)...)};
  26. }
  27. } // namespace histogram
  28. } // namespace boost
  29. #endif