1 // Copyright 2018 Hans Dembinski 2 // 3 // Distributed under the Boost Software License, Version 1.0. 4 // (See accompanying file LICENSE_1_0.txt 5 // or copy at http://www.boost.org/LICENSE_1_0.txt) 6 7 #include <boost/core/lightweight_test.hpp> 8 #include "throw_exception.hpp" 9 #include <sstream> 10 #include <tuple> 11 #include <vector> 12 #include "utility_allocator.hpp" 13 #include "std_ostream.hpp" 14 15 using namespace boost::histogram; 16 main()17 int main() { 18 // vector streaming 19 { 20 std::ostringstream os; 21 std::vector<int> v = {1, 3, 2}; 22 os << v; 23 BOOST_TEST_EQ(os.str(), std::string("[ 1 3 2 ]")); 24 } 25 26 // tuple streaming 27 { 28 std::ostringstream os; 29 auto v = std::make_tuple(1, 2.5, "hi"); 30 os << v; 31 BOOST_TEST_EQ(os.str(), std::string("[ 1 2.5 hi ]")); 32 } 33 34 // tracing_allocator 35 { 36 tracing_allocator_db db; 37 tracing_allocator<char> a(db); 38 auto p1 = a.allocate(2); 39 a.deallocate(p1, 2); 40 tracing_allocator<int> b(a); 41 auto p2 = b.allocate(3); 42 b.deallocate(p2, 3); 43 BOOST_TEST_EQ(db.size(), 2); 44 BOOST_TEST_EQ(db.at<char>().first, 0); 45 BOOST_TEST_EQ(db.at<char>().second, 2); 46 BOOST_TEST_EQ(db.at<int>().first, 0); 47 BOOST_TEST_EQ(db.at<int>().second, 3); 48 BOOST_TEST_EQ(db.first, 0); 49 BOOST_TEST_EQ(db.second, 2 + 3 * sizeof(int)); 50 } 51 52 return boost::report_errors(); 53 } 54