Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/unordered/detail/allocator_constructed.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /* Copyright 2024 Braden Ganetsky.
0002  * Distributed under the Boost Software License, Version 1.0.
0003  * (See accompanying file LICENSE_1_0.txt or copy at
0004  * http://www.boost.org/LICENSE_1_0.txt)
0005  *
0006  * See https://www.boost.org/libs/unordered for library home page.
0007  */
0008 
0009 #ifndef BOOST_UNORDERED_DETAIL_ALLOCATOR_CONSTRUCTED_HPP
0010 #define BOOST_UNORDERED_DETAIL_ALLOCATOR_CONSTRUCTED_HPP
0011 
0012 #include <boost/core/allocator_traits.hpp>
0013 #include <boost/unordered/detail/opt_storage.hpp>
0014 
0015 namespace boost {
0016   namespace unordered {
0017     namespace detail {
0018 
0019       struct allocator_policy
0020       {
0021         template <class Allocator, class T, class... Args>
0022         static void construct(Allocator& a, T* p, Args&&... args)
0023         {
0024           boost::allocator_construct(a, p, std::forward<Args>(args)...);
0025         }
0026 
0027         template <class Allocator, class T>
0028         static void destroy(Allocator& a, T* p)
0029         {
0030           boost::allocator_destroy(a, p);
0031         }
0032       };
0033 
0034       /* constructs a stack-based object with the given policy and allocator */
0035       template <class Allocator, class T, class Policy = allocator_policy>
0036       class allocator_constructed
0037       {
0038         opt_storage<T> storage;
0039         Allocator alloc;
0040 
0041       public:
0042         template <class... Args>
0043         allocator_constructed(Allocator const& alloc_, Args&&... args)
0044             : alloc(alloc_)
0045         {
0046           Policy::construct(
0047             alloc, storage.address(), std::forward<Args>(args)...);
0048         }
0049 
0050         ~allocator_constructed() { Policy::destroy(alloc, storage.address()); }
0051 
0052         T& value() { return *storage.address(); }
0053       };
0054 
0055     } /* namespace detail */
0056   }   /* namespace unordered */
0057 } /* namespace boost */
0058 
0059 #endif