// Copyright 2015-2017 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 #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "throw_exception.hpp" #include "utility_allocator.hpp" #include "std_ostream.hpp" using namespace boost::histogram; using namespace boost::histogram::detail; int main() { // has_method_value* { struct A {}; struct B { A value(int) const { return {}; } }; struct C { char value(int) const { return 0; } }; BOOST_TEST_TRAIT_FALSE((has_method_value)); BOOST_TEST_TRAIT_TRUE((has_method_value)); BOOST_TEST_TRAIT_TRUE((has_method_value)); } // has_method_options { struct A {}; struct B { void options() {} }; BOOST_TEST_TRAIT_FALSE((has_method_options)); BOOST_TEST_TRAIT_TRUE((has_method_options)); } // has_method_metadata { struct A {}; struct B { void metadata(); }; BOOST_TEST_TRAIT_FALSE((has_method_metadata)); BOOST_TEST_TRAIT_TRUE((has_method_metadata)); } // has_method_update { struct A {}; struct B { void update(int) {} }; using C = axis::integer; BOOST_TEST_TRAIT_FALSE((has_method_update)); BOOST_TEST_TRAIT_TRUE((has_method_update)); BOOST_TEST_TRAIT_TRUE((has_method_update)); } // has_method_resize { struct A {}; using B = std::vector; using C = std::map; BOOST_TEST_TRAIT_FALSE((has_method_resize)); BOOST_TEST_TRAIT_TRUE((has_method_resize)); BOOST_TEST_TRAIT_FALSE((has_method_resize)); } // has_method_size { struct A {}; using B = std::vector; using C = std::map; BOOST_TEST_TRAIT_FALSE((has_method_size)); BOOST_TEST_TRAIT_TRUE((has_method_size)); BOOST_TEST_TRAIT_TRUE((has_method_size)); } // has_method_clear { struct A {}; using B = std::vector; using C = std::map; using D = std::array; BOOST_TEST_TRAIT_FALSE((has_method_clear)); BOOST_TEST_TRAIT_TRUE((has_method_clear)); BOOST_TEST_TRAIT_TRUE((has_method_clear)); BOOST_TEST_TRAIT_FALSE((has_method_clear)); } // has_allocator { struct A {}; using B = std::vector; using C = std::map; using D = std::array; BOOST_TEST_TRAIT_FALSE((has_method_clear)); BOOST_TEST_TRAIT_TRUE((has_method_clear)); BOOST_TEST_TRAIT_TRUE((has_method_clear)); BOOST_TEST_TRAIT_FALSE((has_method_clear)); } // is_storage { struct A {}; using B = std::vector; using C = unlimited_storage<>; BOOST_TEST_TRAIT_FALSE((is_storage)); BOOST_TEST_TRAIT_FALSE((is_storage)); BOOST_TEST_TRAIT_TRUE((is_storage)); } // is_indexable { struct A {}; using B = std::vector; using C = std::map; using D = std::map; BOOST_TEST_TRAIT_FALSE((is_indexable)); BOOST_TEST_TRAIT_TRUE((is_indexable)); BOOST_TEST_TRAIT_TRUE((is_indexable)); BOOST_TEST_TRAIT_FALSE((is_indexable)); } // is_transform { struct A {}; struct B { double forward(double); double inverse(double); }; BOOST_TEST_TRAIT_FALSE((is_transform)); BOOST_TEST_TRAIT_TRUE((is_transform)); } // is_vector_like { struct A {}; using B = std::vector; using C = std::array; using D = std::map; using E = std::deque; BOOST_TEST_TRAIT_FALSE((is_vector_like)); BOOST_TEST_TRAIT_TRUE((is_vector_like)); BOOST_TEST_TRAIT_FALSE((is_vector_like)); BOOST_TEST_TRAIT_FALSE((is_vector_like)); BOOST_TEST_TRAIT_TRUE((is_vector_like)); } // is_array_like { struct A {}; using B = std::vector; using C = std::array; using D = std::map; BOOST_TEST_TRAIT_FALSE((is_array_like)); BOOST_TEST_TRAIT_FALSE((is_array_like)); BOOST_TEST_TRAIT_TRUE((is_array_like)); BOOST_TEST_TRAIT_FALSE((is_array_like)); } // is_map_like { struct A {}; using B = std::vector; using C = std::array; using D = std::map; using E = std::unordered_map; BOOST_TEST_TRAIT_FALSE((is_map_like)); BOOST_TEST_TRAIT_FALSE((is_map_like)); BOOST_TEST_TRAIT_FALSE((is_map_like)); BOOST_TEST_TRAIT_TRUE((is_map_like)); BOOST_TEST_TRAIT_TRUE((is_map_like)); } // is_axis { struct A {}; struct B { int index(double); int size() const; }; struct C { int index(double); }; struct D { int size(); }; using E = axis::variant>; BOOST_TEST_TRAIT_FALSE((is_axis)); BOOST_TEST_TRAIT_TRUE((is_axis)); BOOST_TEST_TRAIT_FALSE((is_axis)); BOOST_TEST_TRAIT_FALSE((is_axis)); BOOST_TEST_TRAIT_FALSE((is_axis)); } // is_iterable { using A = std::vector; using B = int[3]; using C = std::initializer_list; BOOST_TEST_TRAIT_FALSE((is_iterable)); BOOST_TEST_TRAIT_TRUE((is_iterable)); BOOST_TEST_TRAIT_TRUE((is_iterable)); BOOST_TEST_TRAIT_TRUE((is_iterable)); } // is_streamable { struct Foo {}; BOOST_TEST_TRAIT_TRUE((is_streamable)); BOOST_TEST_TRAIT_TRUE((is_streamable)); BOOST_TEST_TRAIT_FALSE((is_streamable)); } // is_axis_variant { struct A {}; BOOST_TEST_TRAIT_FALSE((is_axis_variant)); BOOST_TEST_TRAIT_TRUE((is_axis_variant>)); BOOST_TEST_TRAIT_TRUE((is_axis_variant>>)); } // args_type, arg_type { struct Foo { static int f1(char); int f2(long) const; }; BOOST_TEST_TRAIT_SAME(args_type, std::tuple); BOOST_TEST_TRAIT_SAME(args_type, std::tuple); BOOST_TEST_TRAIT_SAME(arg_type, char); BOOST_TEST_TRAIT_SAME(arg_type, long); } // static_if { struct callable { int operator()() { return 1; }; }; struct not_callable {}; auto fcn = [](auto b, auto x) { return static_if([](auto x) { return x(); }, [](auto) { return 2; }, x); }; BOOST_TEST_EQ(fcn(std::true_type(), callable()), 1); BOOST_TEST_EQ(fcn(std::false_type(), not_callable()), 2); } // tuple_slice { auto a = std::make_tuple(1, 2, 3, 4); auto b = tuple_slice<1, 2>(a); BOOST_TEST_EQ(b, std::make_tuple(2, 3)); } // is_sequence_of_axis { using A = std::vector>; using B = std::vector>>; using C = std::vector; auto v = std::vector, axis::integer<>>>(); BOOST_TEST_TRAIT_TRUE((is_sequence_of_any_axis)); BOOST_TEST_TRAIT_TRUE((is_sequence_of_axis)); BOOST_TEST_TRAIT_FALSE((is_sequence_of_axis_variant)); BOOST_TEST_TRAIT_TRUE((is_sequence_of_any_axis)); BOOST_TEST_TRAIT_TRUE((is_sequence_of_axis_variant)); BOOST_TEST_TRAIT_FALSE((is_sequence_of_axis)); BOOST_TEST_TRAIT_FALSE((is_sequence_of_any_axis)); BOOST_TEST_TRAIT_TRUE((is_sequence_of_any_axis)); } // is_weight { struct A {}; using B = int; using C = decltype(weight(1)); BOOST_TEST_TRAIT_FALSE((is_weight)); BOOST_TEST_TRAIT_FALSE((is_weight)); BOOST_TEST_TRAIT_TRUE((is_weight)); } // is_sample { struct A {}; using B = int; using C = decltype(sample(1)); using D = decltype(sample(1, 2.0)); BOOST_TEST_TRAIT_FALSE((is_sample)); BOOST_TEST_TRAIT_FALSE((is_sample)); BOOST_TEST_TRAIT_TRUE((is_sample)); BOOST_TEST_TRAIT_TRUE((is_sample)); } // make_default { struct A {}; auto a = make_default(A()); BOOST_TEST_TRAIT_SAME(decltype(a), A); tracing_allocator_db db; using B = std::vector>; B b = make_default(B(tracing_allocator(db))); b.resize(100); BOOST_TEST_EQ(db.at().first, 100); } // has_operator_equal { struct A {}; struct B { bool operator==(const B&) const { return true; } }; BOOST_TEST_TRAIT_FALSE((has_operator_equal)); BOOST_TEST_TRAIT_FALSE((has_operator_equal)); BOOST_TEST_TRAIT_TRUE((has_operator_equal)); BOOST_TEST_TRAIT_TRUE((has_operator_equal)); } // has_operator_radd { struct A {}; struct B { B& operator+=(const B&) { return *this; } }; BOOST_TEST_TRAIT_FALSE((has_operator_radd)); BOOST_TEST_TRAIT_FALSE((has_operator_radd)); BOOST_TEST_TRAIT_TRUE((has_operator_radd)); BOOST_TEST_TRAIT_TRUE((has_operator_radd)); } return boost::report_errors(); }