Attempt to represent the S^2->S^3 header reorganisation as a series of "hg rename" operations
1 // See http://www.boost.org/libs/any for Documentation.
3 #ifndef BOOST_ANY_INCLUDED
4 #define BOOST_ANY_INCLUDED
6 // what: variant type boost::any
7 // who: contributed by Kevlin Henney,
8 // with features contributed and bugs found by
9 // Ed Brey, Mark Rodgers, Peter Dimov, and James Curran
11 // where: tested with BCC 5.5, MSVC 6.0, and g++ 2.95
16 #include "boost/config.hpp"
17 #include <boost/type_traits/remove_reference.hpp>
18 #include <boost/type_traits/is_reference.hpp>
19 #include <boost/throw_exception.hpp>
20 #include <boost/static_assert.hpp>
33 template<typename ValueType>
34 any(const ValueType & value)
35 : content(new holder<ValueType>(value))
39 any(const any & other)
40 : content(other.content ? other.content->clone() : 0)
53 std::swap(content, rhs.content);
57 template<typename ValueType>
58 any & operator=(const ValueType & rhs)
64 any & operator=(const any & rhs)
77 const std::type_info & type() const
79 return content ? content->type() : typeid(void);
82 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
85 public: // types (public so any_cast can be non-friend)
92 virtual ~placeholder()
98 virtual const std::type_info & type() const = 0;
100 virtual placeholder * clone() const = 0;
104 template<typename ValueType>
105 class holder : public placeholder
109 holder(const ValueType & value)
116 virtual const std::type_info & type() const
118 return typeid(ValueType);
121 virtual placeholder * clone() const
123 return new holder(held);
126 public: // representation
132 #ifndef BOOST_NO_MEMBER_TEMPLATE_FRIENDS
134 private: // representation
136 template<typename ValueType>
137 friend ValueType * any_cast(any *);
139 template<typename ValueType>
140 friend ValueType * unsafe_any_cast(any *);
144 public: // representation (public so any_cast can be non-friend)
148 placeholder * content;
152 class bad_any_cast : public std::bad_cast
155 virtual const char * what() const throw()
157 return "boost::bad_any_cast: "
158 "failed conversion using boost::any_cast";
162 template<typename ValueType>
163 ValueType * any_cast(any * operand)
165 return operand && operand->type() == typeid(ValueType)
166 ? &static_cast<any::holder<ValueType> *>(operand->content)->held
170 template<typename ValueType>
171 const ValueType * any_cast(const any * operand)
173 return any_cast<ValueType>(const_cast<any *>(operand));
176 template<typename ValueType>
177 ValueType any_cast(const any & operand)
179 typedef BOOST_DEDUCED_TYPENAME remove_reference<ValueType>::type nonref;
181 #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
182 // If 'nonref' is still reference type, it means the user has not
183 // specialized 'remove_reference'.
185 // Please use BOOST_BROKEN_COMPILER_TYPE_TRAITS_SPECIALIZATION macro
186 // to generate specialization of remove_reference for your class
187 // See type traits library documentation for details
188 BOOST_STATIC_ASSERT(!is_reference<nonref>::value);
191 const nonref * result = any_cast<nonref>(&operand);
193 boost::throw_exception(bad_any_cast());
197 template<typename ValueType>
198 ValueType any_cast(any & operand)
200 typedef BOOST_DEDUCED_TYPENAME remove_reference<ValueType>::type nonref;
202 #ifdef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
203 // The comment in the above version of 'any_cast' explains when this
204 // assert is fired and what to do.
205 BOOST_STATIC_ASSERT(!is_reference<nonref>::value);
208 nonref * result = any_cast<nonref>(&operand);
210 boost::throw_exception(bad_any_cast());
214 // Note: The "unsafe" versions of any_cast are not part of the
215 // public interface and may be removed at any time. They are
216 // required where we know what type is stored in the any and can't
217 // use typeid() comparison, e.g., when our types may travel across
218 // different shared libraries.
219 template<typename ValueType>
220 inline ValueType * unsafe_any_cast(any * operand)
222 return &static_cast<any::holder<ValueType> *>(operand->content)->held;
225 template<typename ValueType>
226 inline const ValueType * unsafe_any_cast(const any * operand)
228 return unsafe_any_cast<ValueType>(const_cast<any *>(operand));
232 // Copyright Kevlin Henney, 2000, 2001, 2002. All rights reserved.
234 // Distributed under the Boost Software License, Version 1.0. (See
235 // accompanying file LICENSE_1_0.txt or copy at
236 // http://www.boost.org/LICENSE_1_0.txt)