1 // Boost.TypeErasure library
3 // Copyright 2011 Steven Watanabe
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)
11 #ifndef BOOST_TYPE_ERASURE_DETAIL_STORAGE_HPP_INCLUDED
12 #define BOOST_TYPE_ERASURE_DETAIL_STORAGE_HPP_INCLUDED
14 #include <boost/config.hpp>
15 #include <boost/type_traits/remove_reference.hpp>
16 #include <boost/type_traits/remove_cv.hpp>
20 #pragma warning(disable:4521)
24 namespace type_erasure {
30 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
31 storage(storage& other) : data(other.data) {}
32 storage(const storage& other) : data(other.data) {}
33 storage(storage&& other) : data(other.data) {}
34 storage& operator=(const storage& other) { data = other.data; return *this; }
36 storage(T&& arg) : data(new typename remove_cv<
37 typename remove_reference<T>::type>::type(std::forward<T>(arg))) {}
40 storage(const T& arg) : data(new T(arg)) {}
46 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
49 T extract(T arg) { return std::forward<T>(arg); }
54 T extract(T arg) { return arg; }
59 T extract(storage& arg)
61 return *static_cast<typename ::boost::remove_reference<T>::type*>(arg.data);
65 T extract(const storage& arg)
67 return *static_cast<const typename ::boost::remove_reference<T>::type*>(arg.data);
70 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
73 T extract(storage&& arg)
75 return std::move(*static_cast<typename ::boost::remove_reference<T>::type*>(arg.data));