// 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 using namespace boost::histogram::detail; template struct allocator_with_state { using value_type = T; allocator_with_state(int s = 0) : state(s) {} template allocator_with_state(const allocator_with_state& o) : state(o.state) {} value_type* allocate(std::size_t n) { return static_cast(::operator new(n * sizeof(T))); } void deallocate(value_type* ptr, std::size_t) { ::operator delete(static_cast(ptr)); } template bool operator==(const allocator_with_state&) const { return true; } template bool operator!=(const allocator_with_state&) const { return false; } int state; }; int main() { using V = std::vector>; V a(3, 0, allocator_with_state{42}); V b = make_default(a); V c; BOOST_TEST_EQ(a.size(), 3); BOOST_TEST_EQ(b.size(), 0); BOOST_TEST_EQ(c.size(), 0); BOOST_TEST_EQ(a.get_allocator().state, 42); BOOST_TEST_EQ(b.get_allocator().state, 42); BOOST_TEST_EQ(c.get_allocator().state, 0); return boost::report_errors(); }