unsafe_access.hpp 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. // Copyright 2018 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_UNSAFE_ACCESS_HPP
  7. #define BOOST_HISTOGRAM_UNSAFE_ACCESS_HPP
  8. #include <boost/histogram/detail/axes.hpp>
  9. #include <type_traits>
  10. namespace boost {
  11. namespace histogram {
  12. /// Unsafe read/write access to classes that potentially break consistency
  13. struct unsafe_access {
  14. /**
  15. Get axes.
  16. @param hist histogram.
  17. */
  18. template <class Histogram>
  19. static auto& axes(Histogram& hist) {
  20. return hist.axes_;
  21. }
  22. /// @copydoc axes()
  23. template <class Histogram>
  24. static const auto& axes(const Histogram& hist) {
  25. return hist.axes_;
  26. }
  27. /**
  28. Get mutable axis reference with compile-time number.
  29. @param hist histogram.
  30. @tparam I axis index (optional, default: 0).
  31. */
  32. template <class Histogram, unsigned I = 0>
  33. static decltype(auto) axis(Histogram& hist, std::integral_constant<unsigned, I> = {}) {
  34. detail::axis_index_is_valid(hist.axes_, I);
  35. return detail::axis_get<I>(hist.axes_);
  36. }
  37. /**
  38. Get mutable axis reference with run-time number.
  39. @param hist histogram.
  40. @param i axis index.
  41. */
  42. template <class Histogram>
  43. static decltype(auto) axis(Histogram& hist, unsigned i) {
  44. detail::axis_index_is_valid(hist.axes_, i);
  45. return detail::axis_get(hist.axes_, i);
  46. }
  47. /**
  48. Get storage.
  49. @param hist histogram.
  50. */
  51. template <class Histogram>
  52. static auto& storage(Histogram& hist) {
  53. return hist.storage_;
  54. }
  55. /// @copydoc storage()
  56. template <class Histogram>
  57. static const auto& storage(const Histogram& hist) {
  58. return hist.storage_;
  59. }
  60. };
  61. } // namespace histogram
  62. } // namespace boost
  63. #endif