From ed5af698bc7271fe04895e4014f4030725f5bb20 Mon Sep 17 00:00:00 2001 From: Hans Dembinski Date: Thu, 24 Jan 2019 21:35:17 +0100 Subject: [PATCH] use std::enable_if_t for check, to get better error messages --- include/boost/histogram/detail/meta.hpp | 24 +++++------ include/boost/histogram/make_histogram.hpp | 44 ++++++++++----------- include/boost/histogram/storage_adaptor.hpp | 10 +++-- test/utility_meta.hpp | 2 +- 4 files changed, 41 insertions(+), 39 deletions(-) diff --git a/include/boost/histogram/detail/meta.hpp b/include/boost/histogram/detail/meta.hpp index 68d2b99b..b3d4f946 100644 --- a/include/boost/histogram/detail/meta.hpp +++ b/include/boost/histogram/detail/meta.hpp @@ -201,6 +201,9 @@ BOOST_HISTOGRAM_DETECT(is_axis, (&T::size, &T::operator())); BOOST_HISTOGRAM_DETECT(is_iterable, (std::begin(std::declval()), std::end(std::declval()))); +BOOST_HISTOGRAM_DETECT(is_iterator, + (typename std::iterator_traits::iterator_category())); + BOOST_HISTOGRAM_DETECT(is_streamable, (std::declval() << std::declval())); @@ -269,34 +272,31 @@ template using is_sample = is_sample_impl>; // poor-mans concept checks -template -using requires = std::enable_if_t; - -template (), ++std::declval())> +template >::value>> struct requires_iterator {}; -template >>> +template >::value>> struct requires_iterable {}; -template >>> +template >::value>> struct requires_axis {}; -template >>> +template >::value>> struct requires_any_axis {}; -template >>> +template >::value>> struct requires_sequence_of_axis {}; -template >>> +template >::value>> struct requires_sequence_of_axis_variant {}; -template >>> +template >::value>> struct requires_sequence_of_any_axis {}; -template >>>> +template >>::value>> struct requires_axes {}; -template >> +template ::value>> struct requires_convertible {}; template diff --git a/include/boost/histogram/make_histogram.hpp b/include/boost/histogram/make_histogram.hpp index d22d1b5c..688c8369 100644 --- a/include/boost/histogram/make_histogram.hpp +++ b/include/boost/histogram/make_histogram.hpp @@ -26,17 +26,17 @@ namespace histogram { /** Make histogram from compile-time axis configuration and custom storage. - @param s Storage or container with standard interface (any vector, array, or map). + @param storage Storage or container with standard interface (any vector, array, or map). @param axis First axis instance. @param axes Other axis instances. */ -template > -auto make_histogram_with(StorageOrContainer&& s, T&& axis, Ts&&... axes) { +auto make_histogram_with(Storage&& storage, T&& axis, Ts&&... axes) { auto a = std::make_tuple(std::forward(axis), std::forward(axes)...); - using U = detail::naked; + using U = detail::naked; using S = mp11::mp_if, U, storage_adaptor>; - return histogram(std::move(a), S(std::forward(s))); + return histogram(std::move(a), S(std::forward(storage))); } /** @@ -63,50 +63,50 @@ auto make_weighted_histogram(T&& axis, Ts&&... axes) { /** Make histogram from iterable range and custom storage. - @param s Storage or container with standard interface (any vector, array, or map). - @param c Iterable range of axis objects. + @param storage Storage or container with standard interface (any vector, array, or map). + @param iterable Iterable range of axis objects. */ -template > -auto make_histogram_with(StorageOrContainer&& s, Iterable&& c) { - using U = detail::naked; +auto make_histogram_with(Storage&& storage, Iterable&& iterable) { + using U = detail::naked; using S = mp11::mp_if, U, storage_adaptor>; using It = detail::naked; using A = mp11::mp_if, It, boost::container::vector>>; - return histogram(std::forward(c), - S(std::forward(s))); + return histogram(std::forward(iterable), + S(std::forward(storage))); } /** Make histogram from iterable range and default storage. - @param c Iterable range of axis objects. + @param iterable Iterable range of axis objects. */ template > -auto make_histogram(Iterable&& c) { - return make_histogram_with(default_storage(), std::forward(c)); +auto make_histogram(Iterable&& iterable) { + return make_histogram_with(default_storage(), std::forward(iterable)); } /** Make histogram from iterable range and weight-counting storage. - @param c Iterable range of axis objects. + @param iterable Iterable range of axis objects. */ template > -auto make_weighted_histogram(Iterable&& c) { - return make_histogram_with(weight_storage(), std::forward(c)); +auto make_weighted_histogram(Iterable&& iterable) { + return make_histogram_with(weight_storage(), std::forward(iterable)); } /** Make histogram from iterator interval and custom storage. - @param s Storage or container with standard interface (any vector, array, or map). + @param storage Storage or container with standard interface (any vector, array, or map). @param begin Iterator to range of axis objects. @param end Iterator to range of axis objects. */ -template > -auto make_histogram_with(StorageOrContainer&& s, Iterator begin, Iterator end) { +auto make_histogram_with(Storage&& storage, Iterator begin, Iterator end) { using T = detail::naked; - return make_histogram_with(std::forward(s), + return make_histogram_with(std::forward(storage), boost::container::vector(begin, end)); } diff --git a/include/boost/histogram/storage_adaptor.hpp b/include/boost/histogram/storage_adaptor.hpp index 70f22b0a..ff030fab 100644 --- a/include/boost/histogram/storage_adaptor.hpp +++ b/include/boost/histogram/storage_adaptor.hpp @@ -122,7 +122,8 @@ struct map_impl : T { return *this; } - template >> + template ::value>> reference& operator+=(U&& u) { auto it = map->find(idx); if (it != static_cast(map)->end()) @@ -132,7 +133,8 @@ struct map_impl : T { return *this; } - template >> + template ::value>> reference& operator++() { auto it = map->find(idx); if (it != static_cast(map)->end()) @@ -147,7 +149,7 @@ struct map_impl : T { return map->operator[](idx)(std::forward(args)...); } - template >> + template ::value>> reference& operator*=(double x) { auto it = map->find(idx); if (it != static_cast(map)->end()) it->second *= x; @@ -264,7 +266,7 @@ public: } template >> + class = std::enable_if_t::value>> storage_adaptor& operator*=(double v) { for (auto&& x : *this) x *= v; return *this; diff --git a/test/utility_meta.hpp b/test/utility_meta.hpp index e6cc53b1..957047b7 100644 --- a/test/utility_meta.hpp +++ b/test/utility_meta.hpp @@ -25,7 +25,7 @@ ostream& operator<<(ostream& os, const vector& v) { } template , void>> + class = std::enable_if_t::value>> ostream& operator<<(ostream& os, const T& t) { os << "[ "; ::boost::mp11::tuple_for_each(t, [&os](const auto& x) { os << x << " "; });