diff --git a/build/CMakeLists.txt b/build/CMakeLists.txt index c16c1d2d..52d95818 100644 --- a/build/CMakeLists.txt +++ b/build/CMakeLists.txt @@ -119,10 +119,15 @@ add_executable(axis_test target_link_libraries(axis_test ${LIBRARIES}) add_test(axis_test axis_test) -add_executable(dynamic_storage_test - ../test/dynamic_storage_test.cpp) -target_link_libraries(dynamic_storage_test ${LIBRARIES}) -add_test(dynamic_storage_test dynamic_storage_test) +add_executable(adaptive_storage_test + ../test/adaptive_storage_test.cpp) +target_link_libraries(adaptive_storage_test ${LIBRARIES}) +add_test(adaptive_storage_test dynamic_storage_test) + +add_executable(container_storage_test + ../test/container_storage_test.cpp) +target_link_libraries(container_storage_test ${LIBRARIES}) +add_test(container_storage_test dynamic_storage_test) add_executable(detail_test ../test/detail_test.cpp) diff --git a/include/boost/histogram/detail/mpl.hpp b/include/boost/histogram/detail/meta.hpp similarity index 54% rename from include/boost/histogram/detail/mpl.hpp rename to include/boost/histogram/detail/meta.hpp index 133d6ae2..e13b831e 100644 --- a/include/boost/histogram/detail/mpl.hpp +++ b/include/boost/histogram/detail/meta.hpp @@ -4,8 +4,8 @@ // (See accompanying file LICENSE_1_0.txt // or copy at http://www.boost.org/LICENSE_1_0.txt) -#ifndef _BOOST_HISTOGRAM_DETAIL_MPL_HPP_ -#define _BOOST_HISTOGRAM_DETAIL_MPL_HPP_ +#ifndef _BOOST_HISTOGRAM_DETAIL_META_HPP_ +#define _BOOST_HISTOGRAM_DETAIL_META_HPP_ #include #include @@ -19,6 +19,13 @@ namespace boost { namespace histogram { namespace detail { +template ().size()), + typename = decltype(std::declval().increase(0)), + typename = decltype(std::declval().value(0)), + typename = decltype(std::declval().variance(0))> +struct is_storage {}; + template ()), typename = decltype(++std::declval())> @@ -50,38 +57,25 @@ struct intersection { >::type; }; -template -struct is_dynamic_storage { - typedef char one; - typedef long two; - - template().increase(0, 0.0))> - struct BetterMatch {}; - template static one Test(BetterMatch*); - template static two Test(...); - static constexpr bool value = sizeof(Test(0)) == sizeof(one); -}; - -// prefer dynamic over static storage, choose -// static_storage with larger capacity -template -struct select_storage { - using type = typename std::conditional< - (is_dynamic_storage::value || - is_dynamic_storage::value), - typename std::conditional< - is_dynamic_storage::value, - Storage1, Storage2 - >::type, - typename std::conditional< - (std::numeric_limits::max() > - std::numeric_limits::max()), - Storage1, Storage2 - >::type - >::type; -}; +// // prefer dynamic over static storage, choose +// // static_storage with larger capacity +// template +// struct select_storage { +// using type = typename std::conditional< +// (is_dynamic_storage::value || +// is_dynamic_storage::value), +// typename std::conditional< +// is_dynamic_storage::value, +// Storage1, Storage2 +// >::type, +// typename std::conditional< +// (std::numeric_limits::max() > +// std::numeric_limits::max()), +// Storage1, Storage2 +// >::type +// >::type; +// }; } } diff --git a/include/boost/histogram/dynamic_histogram.hpp b/include/boost/histogram/dynamic_histogram.hpp index 4af62ea8..d3ca86c8 100644 --- a/include/boost/histogram/dynamic_histogram.hpp +++ b/include/boost/histogram/dynamic_histogram.hpp @@ -13,41 +13,37 @@ #include #include #include -#include -#include #include -#include +#include #include #include +#include #include -#include #include #include #include #include -#include #include namespace boost { namespace histogram { -template +template class dynamic_histogram { static_assert(!mpl::empty::value, "at least one axis required"); public: - using axis_t = typename make_variant_over::type; - using axes_t = std::vector; - using value_t = typename Storage::value_t; - using variance_t = typename Storage::variance_t; + using axis_type = typename make_variant_over::type; + using axes_type = std::vector; + using value_type = typename Storage::value_type; dynamic_histogram() = default; template explicit dynamic_histogram(const Axes1&... axes) : - axes_({axis_t(axes)...}) + axes_({axis_type(axes)...}) { storage_ = Storage(field_count()); } @@ -61,31 +57,31 @@ public: } explicit - dynamic_histogram(const axes_t& axes) : + dynamic_histogram(const axes_type& axes) : axes_(axes) { storage_ = Storage(field_count()); } explicit - dynamic_histogram(axes_t&& axes) : + dynamic_histogram(axes_type&& axes) : axes_(std::move(axes)) { storage_ = Storage(field_count()); } - template - dynamic_histogram(const dynamic_histogram& other) : + template + dynamic_histogram(const dynamic_histogram& other) : axes_(other.axes_.begin(), other.axes_.end()), storage_(other.storage_) {} - template - dynamic_histogram(dynamic_histogram&& other) : + template + dynamic_histogram(dynamic_histogram&& other) : axes_(std::move(other.axes_)), storage_(std::move(other.storage_)) {} - template - dynamic_histogram& operator=(const dynamic_histogram& other) + template + dynamic_histogram& operator=(const dynamic_histogram& other) { if (static_cast(this) != static_cast(&other)) { axes_ = other.axes_; @@ -94,16 +90,16 @@ public: return *this; } - template - dynamic_histogram& operator=(dynamic_histogram&& other) + template + dynamic_histogram& operator=(dynamic_histogram&& other) { axes_ = std::move(other.axes_); storage_ = std::move(other.storage_); return *this; } - template - bool operator==(const dynamic_histogram& other) const + template + bool operator==(const dynamic_histogram& other) const { if (mpl::empty< typename detail::intersection::type @@ -118,8 +114,8 @@ public: return true; } - template - dynamic_histogram& operator+=(const dynamic_histogram& other) + template