diff options
Diffstat (limited to 'boost/histogram/unsafe_access.hpp')
-rw-r--r-- | boost/histogram/unsafe_access.hpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/boost/histogram/unsafe_access.hpp b/boost/histogram/unsafe_access.hpp new file mode 100644 index 0000000000..9cff0ea99e --- /dev/null +++ b/boost/histogram/unsafe_access.hpp @@ -0,0 +1,74 @@ +// Copyright 2018 Hans Dembinski +// +// Distributed under the Boost Software License, Version 1.0. +// (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) + +#ifndef BOOST_HISTOGRAM_UNSAFE_ACCESS_HPP +#define BOOST_HISTOGRAM_UNSAFE_ACCESS_HPP + +#include <boost/histogram/detail/axes.hpp> +#include <type_traits> + +namespace boost { +namespace histogram { + +/// Unsafe read/write access to classes that potentially break consistency +struct unsafe_access { + /** + Get axes. + @param hist histogram. + */ + template <class Histogram> + static auto& axes(Histogram& hist) { + return hist.axes_; + } + + /// @copydoc axes() + template <class Histogram> + static const auto& axes(const Histogram& hist) { + return hist.axes_; + } + + /** + Get mutable axis reference with compile-time number. + @param hist histogram. + @tparam I axis index (optional, default: 0). + */ + template <class Histogram, unsigned I = 0> + static decltype(auto) axis(Histogram& hist, std::integral_constant<unsigned, I> = {}) { + detail::axis_index_is_valid(hist.axes_, I); + return detail::axis_get<I>(hist.axes_); + } + + /** + Get mutable axis reference with run-time number. + @param hist histogram. + @param i axis index. + */ + template <class Histogram> + static decltype(auto) axis(Histogram& hist, unsigned i) { + detail::axis_index_is_valid(hist.axes_, i); + return detail::axis_get(hist.axes_, i); + } + + /** + Get storage. + @param hist histogram. + */ + template <class Histogram> + static auto& storage(Histogram& hist) { + return hist.storage_; + } + + /// @copydoc storage() + template <class Histogram> + static const auto& storage(const Histogram& hist) { + return hist.storage_; + } +}; + +} // namespace histogram +} // namespace boost + +#endif |