mirror of
https://github.com/boostorg/histogram.git
synced 2025-05-11 13:14:06 +00:00
deduction guides for histogram
This commit is contained in:
parent
12a79e5197
commit
d96f749a52
@ -145,8 +145,8 @@ if (TEST_RANGE_SUPPORT) # test support for external boost::range
|
||||
endif()
|
||||
|
||||
if (cxx_std_17 IN_LIST CMAKE_CXX_COMPILE_FEATURES) # test support for optional C++17 features
|
||||
compiled_test(test/axis_deduction_guide_test.cpp)
|
||||
target_compile_features(axis_deduction_guide_test PRIVATE cxx_std_17)
|
||||
compiled_test(test/deduction_guides_test.cpp)
|
||||
target_compile_features(deduction_guides_test PRIVATE cxx_std_17)
|
||||
endif()
|
||||
|
||||
if (BUILD_BENCHMARKS)
|
||||
|
@ -191,6 +191,17 @@ private:
|
||||
friend struct unsafe_access;
|
||||
};
|
||||
|
||||
#if __cpp_deduction_guides >= 201606
|
||||
|
||||
template <class Axes>
|
||||
histogram(Axes&& axes)->histogram<detail::unqual<Axes>, default_storage>;
|
||||
|
||||
template <class Axes, class Storage>
|
||||
histogram(Axes&& axes, Storage&& storage)
|
||||
->histogram<detail::unqual<Axes>, detail::unqual<Storage>>;
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace histogram
|
||||
} // namespace boost
|
||||
|
||||
|
@ -6,8 +6,9 @@
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <boost/histogram/axis.hpp>
|
||||
#include <boost/histogram.hpp>
|
||||
#include <boost/histogram/axis/ostream_operators.hpp>
|
||||
#include <boost/histogram/ostream_operators.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace boost::histogram;
|
||||
@ -82,6 +83,19 @@ int main() {
|
||||
BOOST_TEST_TRAIT_TRUE(
|
||||
(std::is_same<decltype(i), axis::variable<double, axis::null_type>>));
|
||||
}
|
||||
|
||||
{
|
||||
auto a = histogram(std::make_tuple(axis::regular(3, -1, 1), axis::integer(0, 4)));
|
||||
BOOST_TEST_EQ(a.rank(), 2);
|
||||
BOOST_TEST_EQ(a.axis(0), axis::regular(3, -1, 1));
|
||||
BOOST_TEST_EQ(a.axis(1), axis::integer(0, 4));
|
||||
|
||||
std::vector<axis::regular<>> axes{{axis::regular(3, -1, 1), axis::regular(5, 0, 5)}};
|
||||
auto b = histogram(axes, weighted_storage());
|
||||
BOOST_TEST_EQ(b.rank(), 2);
|
||||
BOOST_TEST_EQ(b.axis(0), axis::regular(3, -1, 1));
|
||||
BOOST_TEST_EQ(b.axis(1), axis::regular(5, 0, 5));
|
||||
}
|
||||
#endif
|
||||
return boost::report_errors();
|
||||
}
|
||||
|
87
test/deduction_guides_test.cpp
Normal file
87
test/deduction_guides_test.cpp
Normal file
@ -0,0 +1,87 @@
|
||||
// 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)
|
||||
|
||||
#include <boost/core/lightweight_test.hpp>
|
||||
#include <boost/core/lightweight_test_trait.hpp>
|
||||
#include <boost/histogram/axis.hpp>
|
||||
#include <boost/histogram/axis/ostream_operators.hpp>
|
||||
#include <type_traits>
|
||||
|
||||
using namespace boost::histogram;
|
||||
namespace tr = axis::transform;
|
||||
|
||||
// tests requires a C++17 compatible compiler
|
||||
|
||||
int main() {
|
||||
#if __cpp_deduction_guides >= 201611
|
||||
{
|
||||
axis::regular a(1, 0.0, 1.0);
|
||||
axis::regular b(1, 0, 1);
|
||||
axis::regular c(1, 0.0f, 1.0f);
|
||||
axis::regular d(1, 0, 1, "foo");
|
||||
axis::regular e(1, 0, 1, axis::null_type{});
|
||||
axis::regular f(tr::sqrt(), 1, 0, 1);
|
||||
axis::regular g(tr::sqrt(), 1, 0, 1, "foo");
|
||||
axis::regular h(tr::sqrt(), 1, 0, 1, axis::null_type{});
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(a), axis::regular<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(b), axis::regular<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(c), axis::regular<float>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(d), axis::regular<>>));
|
||||
BOOST_TEST_TRAIT_TRUE(
|
||||
(std::is_same<decltype(e), axis::regular<double, tr::id, axis::null_type>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(f), axis::regular<double, tr::sqrt>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(g), axis::regular<double, tr::sqrt>>));
|
||||
BOOST_TEST_TRAIT_TRUE(
|
||||
(std::is_same<decltype(h), axis::regular<double, tr::sqrt, axis::null_type>>));
|
||||
}
|
||||
|
||||
{
|
||||
axis::integer a(1, 2);
|
||||
axis::integer b(1l, 2l);
|
||||
axis::integer c(1.0, 2.0);
|
||||
axis::integer d(1.0f, 2.0f);
|
||||
axis::integer e(1, 2, "foo");
|
||||
axis::integer f(1, 2, axis::null_type{});
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(a), axis::integer<int>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(b), axis::integer<int>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(c), axis::integer<double>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(d), axis::integer<float>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(e), axis::integer<int>>));
|
||||
BOOST_TEST_TRAIT_TRUE(
|
||||
(std::is_same<decltype(f), axis::integer<int, axis::null_type>>));
|
||||
}
|
||||
|
||||
{
|
||||
axis::variable a{-1, 1};
|
||||
axis::variable b{-1.f, 1.f};
|
||||
axis::variable c{-1.0, 1.0};
|
||||
axis::variable d({-1, 1}, "foo");
|
||||
axis::variable e({-1, 1}, axis::null_type{});
|
||||
|
||||
std::vector<int> vi{{-1, 1}};
|
||||
std::vector<float> vf{{-1.f, 1.f}};
|
||||
axis::variable f(vi);
|
||||
axis::variable g(vf);
|
||||
axis::variable h(vi, "foo");
|
||||
axis::variable i(vi, axis::null_type{});
|
||||
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(a), axis::variable<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(b), axis::variable<float>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(c), axis::variable<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(d), axis::variable<>>));
|
||||
BOOST_TEST_TRAIT_TRUE(
|
||||
(std::is_same<decltype(e), axis::variable<double, axis::null_type>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(f), axis::variable<>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(g), axis::variable<float>>));
|
||||
BOOST_TEST_TRAIT_TRUE((std::is_same<decltype(h), axis::variable<>>));
|
||||
BOOST_TEST_TRAIT_TRUE(
|
||||
(std::is_same<decltype(i), axis::variable<double, axis::null_type>>));
|
||||
}
|
||||
#endif
|
||||
return boost::report_errors();
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user