]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/statechart/detail/memory.hpp
import new upstream nautilus stable release 14.2.8
[ceph.git] / ceph / src / boost / boost / statechart / detail / memory.hpp
CommitLineData
7c673cae
FG
1#ifndef BOOST_STATECHART_DETAIL_MEMORY_HPP_INCLUDED
2#define BOOST_STATECHART_DETAIL_MEMORY_HPP_INCLUDED
3//////////////////////////////////////////////////////////////////////////////
4// Copyright 2005-2006 Andreas Huber Doenni
5// Distributed under the Boost Software License, Version 1.0. (See accompany-
6// ing file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7//////////////////////////////////////////////////////////////////////////////
8
9
10
11#include <boost/statechart/detail/avoid_unused_warning.hpp>
12
13#include <boost/assert.hpp>
14#include <boost/detail/allocator_utilities.hpp>
15
16#include <cstddef> // std::size_t
92f5a8d4 17#include <memory> // std::allocator_traits
7c673cae
FG
18
19
20namespace boost
21{
22namespace statechart
23{
92f5a8d4
TL
24
25#ifdef BOOST_NO_CXX11_ALLOCATOR
26typedef void none;
27#else
28// The specialization std::allocator<void> doesn't satisfy C++17's
29// allocator completeness requirements. Therefore it is deprecated
30// and should no longer be used. Supply a replacement type for all
31// the allocator default template arguments in the library.
32struct none {};
33#endif
34
7c673cae
FG
35namespace detail
36{
37
38
39
92f5a8d4
TL
40// defect: 'allocate' and 'deallocate' cannot handle stateful allocators!
41
7c673cae
FG
42template< class MostDerived, class Allocator >
43void * allocate( std::size_t size )
44{
45 avoid_unused_warning( size );
46 // The assert below fails when memory is allocated for an event<>,
47 // simple_state<> or state<> subtype object, *and* the first template
48 // parameter passed to one of these templates is not equal to the most-
49 // derived object being constructed.
50 // The following examples apply to all these subtypes:
51 // // Example 1
52 // struct A {};
53 // struct B : sc::simple_state< A, /* ... */ >
54 // // Above, the first template parameter must be equal to the most-
55 // // derived type
56 //
57 // // Example 2
58 // struct A : sc::event< A >
59 // struct B : A { /* ... */ };
60 // void f() { delete new B(); }
61 // // Above the most-derived type being constructed is B, but A was passed
62 // // as the most-derived type to event<>.
63 BOOST_ASSERT( size == sizeof( MostDerived ) );
92f5a8d4 64 typedef typename boost::detail::allocator::rebind_to<
7c673cae 65 Allocator, MostDerived
92f5a8d4
TL
66 >::type md_allocator;
67 md_allocator alloc;
68#ifdef BOOST_NO_CXX11_ALLOCATOR
69 return alloc.allocate( 1, static_cast< MostDerived * >( 0 ) );
70#else
71 typedef std::allocator_traits<md_allocator> md_traits;
72 return md_traits::allocate( alloc, 1, static_cast< MostDerived * >( 0 ) );
73#endif
7c673cae
FG
74}
75
76template< class MostDerived, class Allocator >
77void deallocate( void * pObject )
78{
92f5a8d4 79 typedef typename boost::detail::allocator::rebind_to<
7c673cae 80 Allocator, MostDerived
92f5a8d4
TL
81 >::type md_allocator;
82 md_allocator alloc;
83#ifdef BOOST_NO_CXX11_ALLOCATOR
84 alloc.deallocate( static_cast< MostDerived * >( pObject ), 1 );
85#else
86 typedef std::allocator_traits<md_allocator> md_traits;
87 md_traits::deallocate( alloc, static_cast< MostDerived * >( pObject ), 1 );
88#endif
7c673cae
FG
89}
90
91
92
93} // namespace detail
94} // namespace statechart
95} // namespace boost
96
97
98
99#endif