]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/type_erasure/include/boost/type_erasure/detail/storage.hpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / type_erasure / include / boost / type_erasure / detail / storage.hpp
1 // Boost.TypeErasure library
2 //
3 // Copyright 2011 Steven Watanabe
4 //
5 // Distributed under the Boost Software License Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //
9 // $Id$
10
11 #ifndef BOOST_TYPE_ERASURE_DETAIL_STORAGE_HPP_INCLUDED
12 #define BOOST_TYPE_ERASURE_DETAIL_STORAGE_HPP_INCLUDED
13
14 #include <boost/config.hpp>
15 #include <boost/type_traits/remove_reference.hpp>
16 #include <boost/type_traits/remove_cv.hpp>
17
18 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
19 # include <utility> // for std::forward, std::move
20 #endif
21
22 #ifdef BOOST_MSVC
23 #pragma warning(push)
24 #pragma warning(disable:4521)
25 #endif
26
27 namespace boost {
28 namespace type_erasure {
29 namespace detail {
30
31 struct storage
32 {
33 storage() {}
34 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
35 storage(storage& other) : data(other.data) {}
36 storage(const storage& other) : data(other.data) {}
37 storage(storage&& other) : data(other.data) {}
38 storage& operator=(const storage& other) { data = other.data; return *this; }
39 template<class T>
40 explicit storage(T&& arg) : data(new typename remove_cv<
41 typename remove_reference<T>::type>::type(std::forward<T>(arg))) {}
42 #else
43 template<class T>
44 explicit storage(const T& arg) : data(new T(arg)) {}
45 #endif
46 void* data;
47 };
48
49
50 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
51
52 template<class T>
53 T extract(T arg) { return std::forward<T>(arg); }
54
55 #else
56
57 template<class T>
58 T extract(T arg) { return arg; }
59
60 #endif
61
62 template<class T>
63 T extract(storage& arg)
64 {
65 return *static_cast<typename ::boost::remove_reference<T>::type*>(arg.data);
66 }
67
68 template<class T>
69 T extract(const storage& arg)
70 {
71 return *static_cast<const typename ::boost::remove_reference<T>::type*>(arg.data);
72 }
73
74 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
75
76 template<class T>
77 T extract(storage&& arg)
78 {
79 return std::move(*static_cast<typename ::boost::remove_reference<T>::type*>(arg.data));
80 }
81
82 #endif
83
84 }
85 }
86 }
87
88 #ifdef BOOST_MSVC
89 #pragma warning(pop)
90 #endif
91
92 #endif