1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- #ifndef BOOST_UNORDERED_DETAIL_ALLOCATOR_CONSTRUCTED_HPP
- #define BOOST_UNORDERED_DETAIL_ALLOCATOR_CONSTRUCTED_HPP
- #include <boost/core/allocator_traits.hpp>
- #include <boost/unordered/detail/opt_storage.hpp>
- namespace boost {
- namespace unordered {
- namespace detail {
- struct allocator_policy
- {
- template <class Allocator, class T, class... Args>
- static void construct(Allocator& a, T* p, Args&&... args)
- {
- boost::allocator_construct(a, p, std::forward<Args>(args)...);
- }
- template <class Allocator, class T>
- static void destroy(Allocator& a, T* p)
- {
- boost::allocator_destroy(a, p);
- }
- };
-
- template <class Allocator, class T, class Policy = allocator_policy>
- class allocator_constructed
- {
- opt_storage<T> storage;
- Allocator alloc;
- public:
- template <class... Args>
- allocator_constructed(Allocator const& alloc_, Args&&... args)
- : alloc(alloc_)
- {
- Policy::construct(
- alloc, storage.address(), std::forward<Args>(args)...);
- }
- ~allocator_constructed() { Policy::destroy(alloc, storage.address()); }
- T& value() { return *storage.address(); }
- };
- }
- }
- }
- #endif
|