X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=ceph%2Fsrc%2Fboost%2Flibs%2Fsmart_ptr%2Ftest%2Fallocate_shared_array_esft_test.cpp;h=1e0afaf616e05237759faeb66082429870800117;hb=b32b81446b3b05102be0267e79203f59329c1d97;hp=30edfffe7ead2dd788a64e7654cb10eaf3f41389;hpb=215dd7151453fae88e6f968c975b6ce309d42dcf;p=ceph.git diff --git a/ceph/src/boost/libs/smart_ptr/test/allocate_shared_array_esft_test.cpp b/ceph/src/boost/libs/smart_ptr/test/allocate_shared_array_esft_test.cpp index 30edfffe7..1e0afaf61 100644 --- a/ceph/src/boost/libs/smart_ptr/test/allocate_shared_array_esft_test.cpp +++ b/ceph/src/boost/libs/smart_ptr/test/allocate_shared_array_esft_test.cpp @@ -1,39 +1,79 @@ /* -(c) 2012-2015 Glen Joseph Fernandes - +Copyright 2012-2015 Glen Joseph Fernandes +(glenjofe@gmail.com) -Distributed under the Boost Software -License, Version 1.0. -http://boost.org/LICENSE_1_0.txt +Distributed under the Boost Software License, Version 1.0. +(http://www.boost.org/LICENSE_1_0.txt) */ #include #include #include -class type +template +struct creator { + typedef T value_type; + + template + struct rebind { + typedef creator other; + }; + + creator() { } + + template + creator(const creator&) { } + + T* allocate(std::size_t size) { + return static_cast(::operator new(sizeof(T) * size)); + } + + void deallocate(T* ptr, std::size_t) { + ::operator delete(ptr); + } +}; + +template +inline bool +operator==(const creator&, const creator&) +{ + return true; +} + +template +inline bool +operator!=(const creator&, const creator&) +{ + return false; +} + +class type : public boost::enable_shared_from_this { public: - static unsigned int instances; - explicit type() { - instances++; + static unsigned instances; + + type() { + ++instances; } + ~type() { - instances--; + --instances; } + private: type(const type&); type& operator=(const type&); }; -unsigned int type::instances = 0; +unsigned type::instances = 0; int main() { BOOST_TEST(type::instances == 0); { - boost::shared_ptr a1 = boost::allocate_shared(std::allocator(), 3); + boost::shared_ptr result = + boost::allocate_shared(creator(), 3); try { - a1[0].shared_from_this(); + result[0].shared_from_this(); BOOST_ERROR("shared_from_this did not throw"); } catch (...) { BOOST_TEST(type::instances == 3); @@ -41,9 +81,10 @@ int main() } BOOST_TEST(type::instances == 0); { - boost::shared_ptr a1 = boost::allocate_shared_noinit(std::allocator(), 3); + boost::shared_ptr result = + boost::allocate_shared_noinit(creator<>(), 3); try { - a1[0].shared_from_this(); + result[0].shared_from_this(); BOOST_ERROR("shared_from_this did not throw"); } catch (...) { BOOST_TEST(type::instances == 3);