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_ANY_HPP_INCLUDED
12 #define BOOST_TYPE_ERASURE_ANY_HPP_INCLUDED
15 #include <boost/config.hpp>
16 #include <boost/utility/enable_if.hpp>
17 #include <boost/utility/addressof.hpp>
18 #include <boost/utility/declval.hpp>
19 #include <boost/mpl/bool.hpp>
20 #include <boost/mpl/or.hpp>
21 #include <boost/mpl/pair.hpp>
22 #include <boost/mpl/map.hpp>
23 #include <boost/mpl/fold.hpp>
24 #include <boost/type_traits/remove_reference.hpp>
25 #include <boost/type_traits/remove_const.hpp>
26 #include <boost/type_traits/is_same.hpp>
27 #include <boost/type_traits/is_const.hpp>
28 #include <boost/preprocessor/cat.hpp>
29 #include <boost/preprocessor/iteration/iterate.hpp>
30 #include <boost/preprocessor/repetition/enum_params.hpp>
31 #include <boost/preprocessor/repetition/enum_binary_params.hpp>
32 #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
33 #include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
34 #include <boost/type_erasure/detail/access.hpp>
35 #include <boost/type_erasure/detail/any_base.hpp>
36 #include <boost/type_erasure/detail/normalize.hpp>
37 #include <boost/type_erasure/detail/storage.hpp>
38 #include <boost/type_erasure/detail/instantiate.hpp>
39 #include <boost/type_erasure/config.hpp>
40 #include <boost/type_erasure/binding.hpp>
41 #include <boost/type_erasure/static_binding.hpp>
42 #include <boost/type_erasure/concept_interface.hpp>
43 #include <boost/type_erasure/call.hpp>
44 #include <boost/type_erasure/relaxed.hpp>
45 #include <boost/type_erasure/param.hpp>
48 namespace type_erasure {
56 template<class T, class U>
61 template<class Derived, class Concept, class T>
64 typedef typename ::boost::mpl::fold<
65 typename ::boost::type_erasure::detail::collect_concepts<
68 ::boost::type_erasure::any_base<Derived>,
69 ::boost::type_erasure::concept_interface<
78 T make(T*) { return T(); }
80 // This dance is necessary to avoid errors calling
81 // an ellipsis function with a non-trivially-copyable
85 struct yes { no dummy[2]; };
88 yes check_overload(const Op*);
89 no check_overload(const void*);
94 fallback make_fallback(const T&, boost::mpl::false_)
100 const T& make_fallback(const T& arg, boost::mpl::true_)
106 struct is_any : ::boost::mpl::false_ {};
108 template<class Concept, class T>
109 struct is_any<any<Concept, T> > : ::boost::mpl::true_ {};
114 #pragma warning(push)
115 #pragma warning(disable:4355)
116 #pragma warning(disable:4521)
120 * The class template @ref any can store any object that
121 * models a specific \Concept. It dispatches all
122 * the functions defined by the \Concept to the contained type
125 * \tparam Concept The \Concept that the stored type should model.
126 * \tparam T A @ref placeholder specifying which type this is.
128 * \see concept_of, placeholder_of, \any_cast, \is_empty, \binding_of, \typeid_of
130 template<class Concept, class T = _self>
132 public ::boost::type_erasure::detail::compute_bases<
133 ::boost::type_erasure::any<Concept, T>,
138 typedef ::boost::type_erasure::binding<Concept> table_type;
141 typedef Concept _boost_type_erasure_concept_type;
143 any(const ::boost::type_erasure::detail::storage& data_arg, const table_type& table_arg)
147 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
149 any(::boost::type_erasure::detail::storage&& data_arg, const table_type& table_arg)
155 * Constructs an empty @ref any.
157 * Except as otherwise noted, all operations on an
158 * empty @ref any result in a @ref bad_function_call exception.
159 * The copy-constructor of an empty @ref any creates another
160 * null @ref any. The destructor of an empty @ref any is a no-op.
161 * Comparison operators treat all empty @ref any "anys" as equal.
162 * \typeid_of applied to an empty @ref any returns @c typeid(void).
164 * An @ref any which does not include @ref relaxed in its
165 * \Concept can never be null.
167 * \pre @ref relaxed must be in @c Concept.
175 BOOST_MPL_ASSERT((::boost::type_erasure::is_relaxed<Concept>));
179 #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
182 any(const U& data_arg)
184 BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, U),
185 ::boost::type_erasure::make_binding<
186 ::boost::mpl::map< ::boost::mpl::pair<T, U> >
191 template<class U, class Map>
192 any(const U& data_arg, const static_binding<Map>& binding_arg)
194 BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
199 BOOST_MPL_ASSERT((::boost::is_same<
200 typename ::boost::mpl::at<Map, T>::type, U>));
206 * Constructs an @ref any to hold a copy of @c data.
207 * The @c Concept will be instantiated with the
208 * placeholder @c T bound to U.
210 * \param data The object to store in the @ref any.
212 * \pre @c U is a model of @c Concept.
213 * \pre @c U must be \CopyConstructible.
214 * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
216 * \throws std::bad_alloc or whatever that the copy
217 * constructor of @c U throws.
219 * \note This constructor never matches if the argument is
220 * an @ref any, @ref binding, or @ref static_binding.
225 BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, typename ::boost::remove_cv<typename ::boost::remove_reference<U>::type>::type),
226 ::boost::type_erasure::make_binding<
227 ::boost::mpl::map< ::boost::mpl::pair<T, typename ::boost::remove_cv<typename ::boost::remove_reference<U>::type>::type> >
230 data(std::forward<U>(data_arg))
233 * Constructs an @ref any to hold a copy of @c data
234 * with explicitly specified placeholder bindings.
236 * \param data The object to store in the @ref any.
237 * \param binding Specifies the types that
238 * all the placeholders should bind to.
240 * \pre @c U is a model of @c Concept.
241 * \pre @c U must be \CopyConstructible.
242 * \pre @c Map is an MPL map with an entry for every
243 * non-deduced placeholder referred to by @c Concept.
244 * \pre @c @c T must map to @c U in @c Map.
246 * \throws std::bad_alloc or whatever that the copy
247 * constructor of @c U throws.
249 * \note This constructor never matches if the argument is an @ref any.
251 template<class U, class Map>
252 any(U&& data_arg, const static_binding<Map>& binding_arg)
254 BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
257 data(std::forward<U>(data_arg))
259 BOOST_MPL_ASSERT((::boost::is_same<
260 typename ::boost::mpl::at<Map, T>::type, typename ::boost::remove_cv<typename ::boost::remove_reference<U>::type>::type>));
265 // Handle array/function-to-pointer decay
270 BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, U*),
271 ::boost::type_erasure::make_binding<
272 ::boost::mpl::map< ::boost::mpl::pair<T, U*> >
278 template<class U, class Map>
279 any(U* data_arg, const static_binding<Map>& binding_arg)
281 BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
286 BOOST_MPL_ASSERT((::boost::is_same<
287 typename ::boost::mpl::at<Map, T>::type, U*>));
290 * Copies an @ref any.
292 * \param other The object to make a copy of.
294 * \pre @c Concept must contain @ref constructible "constructible<T(const T&)>".
295 * (This is included in @ref copy_constructible "copy_constructible<T>")
297 * \throws std::bad_alloc or whatever that the copy
298 * constructor of the contained type throws.
300 any(const any& other)
301 : table(other.table),
302 data(::boost::type_erasure::call(constructible<T(const T&)>(), other))
305 * Upcasts from an @ref any with stricter requirements to
306 * an @ref any with weaker requirements.
308 * \param other The object to make a copy of.
310 * \pre @c Concept must contain @ref constructible<T(const T&)>.
311 * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
312 * \pre After substituting @c T for @c Tag2, the requirements of
313 * @c Concept2 must be a superset of the requirements of
316 * \throws std::bad_alloc or whatever that the copy
317 * constructor of the contained type throws.
319 template<class Concept2, class Tag2>
320 any(const any<Concept2, Tag2>& other)
322 ::boost::type_erasure::detail::access::table(other),
326 typename ::boost::remove_const<
327 typename ::boost::remove_reference<Tag2>::type
332 data(::boost::type_erasure::call(
334 typename ::boost::remove_const<
335 typename boost::remove_reference<Tag2>::type
336 >::type(const typename boost::remove_reference<Tag2>::type&)
341 * Constructs an @ref any from another @ref any.
343 * \param other The object to make a copy of.
344 * \param binding Specifies the mapping between the placeholders
345 * used by the two concepts.
347 * \pre @c Concept must contain @ref constructible<T(const T&)>.
348 * \pre @c Map must be an MPL map with keys for all the non-deduced
349 * placeholders used by @c Concept and values for the corresponding
350 * placeholders in @c Concept2.
351 * \pre After substituting placeholders according to @c Map, the
352 * requirements of @c Concept2 must be a superset of the
353 * requirements of @c Concept.
355 * \throws std::bad_alloc or whatever that the copy
356 * constructor of the contained type throws.
358 template<class Concept2, class Tag2, class Map>
359 any(const any<Concept2, Tag2>& other, const static_binding<Map>& binding_arg)
360 : table(::boost::type_erasure::detail::access::table(other), binding_arg),
361 data(::boost::type_erasure::call(
363 typename ::boost::remove_const<
364 typename boost::remove_reference<Tag2>::type
365 >::type(const typename boost::remove_reference<Tag2>::type&)
370 * Constructs an @ref any from another @ref any.
372 * \param other The object to make a copy of.
373 * \param binding Specifies the bindings of placeholders to actual types.
375 * \pre @c Concept must contain @ref constructible<T(const T&)>.
376 * \pre The type stored in @c other must match the type expected by
379 * \post binding_of(*this) == @c binding
381 * \throws std::bad_alloc or whatever that the copy
382 * constructor of the contained type throws.
384 * \warning This constructor is potentially dangerous, as it cannot
385 * check at compile time whether the arguments match.
387 template<class Concept2, class Tag2>
388 any(const any<Concept2, Tag2>& other, const binding<Concept>& binding_arg)
389 : table(binding_arg),
390 data(::boost::type_erasure::call(
392 typename ::boost::remove_const<
393 typename boost::remove_reference<Tag2>::type
394 >::type(const typename boost::remove_reference<Tag2>::type&)
399 #ifdef BOOST_TYPE_ERASURE_DOXYGEN
402 * Calls a constructor of the contained type. The bindings
403 * will be deduced from the arguments.
405 * \param arg The arguments to be passed to the underlying constructor.
407 * \pre @c Concept must contain an instance of @ref constructible which
408 * can be called with these arguments.
409 * \pre At least one of the arguments must by an @ref any with the
410 * same @c Concept as this.
411 * \pre The bindings of all the arguments that are @ref any's, must
414 * \throws std::bad_alloc or whatever that the
415 * constructor of the contained type throws.
417 * \note This constructor is never chosen if any other constructor
418 * can be called instead.
421 explicit any(U&&... arg);
424 * Calls a constructor of the contained type.
426 * \param binding Specifies the bindings of placeholders to actual types.
427 * \param arg The arguments to be passed to the underlying constructor.
429 * \pre @c Concept must contain a matching instance of @ref constructible.
430 * \pre The contained type of every argument that is an @ref any, must
431 * be the same as that specified by @c binding.
433 * \post binding_of(*this) == @c binding
435 * \throws std::bad_alloc or whatever that the
436 * constructor of the contained type throws.
439 explicit any(const binding<Concept>& binding_arg, U&&... arg)
440 : table(binding_arg),
442 ::boost::type_erasure::detail::make(
443 false? this->_boost_type_erasure_deduce_constructor(arg...) : 0
449 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
451 : table(::boost::type_erasure::detail::access::table(other)),
452 data(::boost::type_erasure::call(
453 ::boost::type_erasure::detail::make(
454 false? this->_boost_type_erasure_deduce_constructor(std::move(other)) : 0
459 : table(::boost::type_erasure::detail::access::table(other)),
460 data(::boost::type_erasure::call(
461 ::boost::type_erasure::detail::make(
462 false? this->_boost_type_erasure_deduce_constructor(other) : 0
466 template<class Concept2, class Tag2>
467 any(any<Concept2, Tag2>& other)
469 ::boost::type_erasure::detail::access::table(other),
473 typename ::boost::remove_const<
474 typename ::boost::remove_reference<Tag2>::type
479 data(::boost::type_erasure::call(
480 ::boost::type_erasure::detail::make(
481 false? other._boost_type_erasure_deduce_constructor(other) : 0
485 template<class Concept2, class Tag2>
486 any(any<Concept2, Tag2>&& other)
488 ::boost::type_erasure::detail::access::table(other),
492 typename ::boost::remove_const<
493 typename ::boost::remove_reference<Tag2>::type
498 data(::boost::type_erasure::call(
499 ::boost::type_erasure::detail::make(
500 false? other._boost_type_erasure_deduce_constructor(std::move(other)) : 0
505 // construction from a reference
506 any(const any<Concept, T&>& other)
507 : table(::boost::type_erasure::detail::access::table(other)),
508 data(::boost::type_erasure::call(
509 ::boost::type_erasure::detail::make(
510 false? this->_boost_type_erasure_deduce_constructor(other) : 0
514 any(any<Concept, T&>& other)
515 : table(::boost::type_erasure::detail::access::table(other)),
516 data(::boost::type_erasure::call(
517 ::boost::type_erasure::detail::make(
518 false? this->_boost_type_erasure_deduce_constructor(other) : 0
522 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
523 any(any<Concept, T&>&& other)
524 : table(::boost::type_erasure::detail::access::table(other)),
525 data(::boost::type_erasure::call(
526 ::boost::type_erasure::detail::make(
527 false? this->_boost_type_erasure_deduce_constructor(other) : 0
532 any(const any<Concept, const T&>& other)
533 : table(::boost::type_erasure::detail::access::table(other)),
534 data(::boost::type_erasure::call(
535 ::boost::type_erasure::detail::make(
536 false? this->_boost_type_erasure_deduce_constructor(other) : 0
540 any(any<Concept, const T&>& other)
541 : table(::boost::type_erasure::detail::access::table(other)),
542 data(::boost::type_erasure::call(
543 ::boost::type_erasure::detail::make(
544 false? this->_boost_type_erasure_deduce_constructor(other) : 0
548 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
549 any(any<Concept, const T&>&& other)
550 : table(::boost::type_erasure::detail::access::table(other)),
551 data(::boost::type_erasure::call(
552 ::boost::type_erasure::detail::make(
553 false? this->_boost_type_erasure_deduce_constructor(other) : 0
559 // disambiguating overloads
560 template<class U, class Map>
561 any(U* data_arg, static_binding<Map>& binding_arg)
563 BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
568 BOOST_MPL_ASSERT((::boost::is_same<
569 typename ::boost::mpl::at<Map, T>::type, U*>));
571 #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
572 template<class U, class Map>
573 any(U& data_arg, static_binding<Map>& binding_arg)
575 BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
580 BOOST_MPL_ASSERT((::boost::is_same<
581 typename ::boost::mpl::at<Map, T>::type, U>));
583 template<class U, class Map>
584 any(const U& data_arg, static_binding<Map>& binding_arg)
586 BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
591 BOOST_MPL_ASSERT((::boost::is_same<
592 typename ::boost::mpl::at<Map, T>::type, U>));
594 template<class U, class Map>
595 any(U& data_arg, const static_binding<Map>& binding_arg)
597 BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
602 BOOST_MPL_ASSERT((::boost::is_same<
603 typename ::boost::mpl::at<Map, T>::type, U>));
606 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
607 template<class U, class Map>
608 any(U* data_arg, static_binding<Map>&& binding_arg)
610 BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
615 BOOST_MPL_ASSERT((::boost::is_same<
616 typename ::boost::mpl::at<Map, T>::type, U*>));
618 template<class U, class Map>
619 any(U&& data_arg, static_binding<Map>& binding_arg)
621 BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
626 BOOST_MPL_ASSERT((::boost::is_same<
627 typename ::boost::mpl::at<Map, T>::type, typename ::boost::remove_cv<typename ::boost::remove_reference<U>::type>::type>));
629 template<class U, class Map>
630 any(U&& data_arg, static_binding<Map>&& binding_arg)
632 BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
637 BOOST_MPL_ASSERT((::boost::is_same<
638 typename ::boost::mpl::at<Map, T>::type, typename ::boost::remove_cv<typename ::boost::remove_reference<U>::type>::type>));
641 template<class Concept2, class Tag2, class Map>
642 any(any<Concept2, Tag2>& other, static_binding<Map>& binding_arg)
643 : table(::boost::type_erasure::detail::access::table(other), binding_arg),
644 data(::boost::type_erasure::call(
646 typename ::boost::remove_const<
647 typename boost::remove_reference<Tag2>::type
648 >::type(const typename boost::remove_reference<Tag2>::type&)
652 template<class Concept2, class Tag2, class Map>
653 any(any<Concept2, Tag2>& other, const static_binding<Map>& binding_arg)
654 : table(::boost::type_erasure::detail::access::table(other), binding_arg),
655 data(::boost::type_erasure::call(
657 typename ::boost::remove_const<
658 typename boost::remove_reference<Tag2>::type
659 >::type(const typename boost::remove_reference<Tag2>::type&)
663 template<class Concept2, class Tag2, class Map>
664 any(const any<Concept2, Tag2>& other, static_binding<Map>& binding_arg)
665 : table(::boost::type_erasure::detail::access::table(other), binding_arg),
666 data(::boost::type_erasure::call(
668 typename ::boost::remove_const<
669 typename boost::remove_reference<Tag2>::type
670 >::type(const typename boost::remove_reference<Tag2>::type&)
674 template<class Concept2, class Tag2>
675 any(any<Concept2, Tag2>& other, binding<Concept>& binding_arg)
676 : table(binding_arg),
677 data(::boost::type_erasure::call(
679 typename ::boost::remove_const<
680 typename boost::remove_reference<Tag2>::type
681 >::type(const typename boost::remove_reference<Tag2>::type&)
685 template<class Concept2, class Tag2>
686 any(any<Concept2, Tag2>& other, const binding<Concept>& binding_arg)
687 : table(binding_arg),
688 data(::boost::type_erasure::call(
690 typename ::boost::remove_const<
691 typename boost::remove_reference<Tag2>::type
692 >::type(const typename boost::remove_reference<Tag2>::type&)
696 template<class Concept2, class Tag2>
697 any(const any<Concept2, Tag2>& other, binding<Concept>& binding_arg)
698 : table(binding_arg),
699 data(::boost::type_erasure::call(
701 typename ::boost::remove_const<
702 typename boost::remove_reference<Tag2>::type
703 >::type(const typename boost::remove_reference<Tag2>::type&)
708 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
709 template<class Concept2, class Tag2, class Map>
710 any(any<Concept2, Tag2>& other, static_binding<Map>&& binding_arg)
711 : table(::boost::type_erasure::detail::access::table(other), binding_arg),
712 data(::boost::type_erasure::call(
714 typename ::boost::remove_const<
715 typename boost::remove_reference<Tag2>::type
716 >::type(const typename boost::remove_reference<Tag2>::type&)
720 template<class Concept2, class Tag2, class Map>
721 any(const any<Concept2, Tag2>& other, static_binding<Map>&& binding_arg)
722 : table(::boost::type_erasure::detail::access::table(other), binding_arg),
723 data(::boost::type_erasure::call(
725 typename ::boost::remove_const<
726 typename boost::remove_reference<Tag2>::type
727 >::type(const typename boost::remove_reference<Tag2>::type&)
731 template<class Concept2, class Tag2, class Map>
732 any(any<Concept2, Tag2>&& other, static_binding<Map>&& binding_arg)
733 : table(::boost::type_erasure::detail::access::table(other), binding_arg),
734 data(::boost::type_erasure::call(
736 typename ::boost::remove_const<
737 typename boost::remove_reference<Tag2>::type
738 >::type(const typename boost::remove_reference<Tag2>::type&)
739 >(), std::move(other))
742 template<class Concept2, class Tag2, class Map>
743 any(any<Concept2, Tag2>&& other, static_binding<Map>& binding_arg)
744 : table(::boost::type_erasure::detail::access::table(other), binding_arg),
745 data(::boost::type_erasure::call(
747 typename ::boost::remove_const<
748 typename boost::remove_reference<Tag2>::type
749 >::type(const typename boost::remove_reference<Tag2>::type&)
750 >(), std::move(other))
753 template<class Concept2, class Tag2, class Map>
754 any(any<Concept2, Tag2>&& other, const static_binding<Map>& binding_arg)
755 : table(::boost::type_erasure::detail::access::table(other), binding_arg),
756 data(::boost::type_erasure::call(
758 typename ::boost::remove_const<
759 typename boost::remove_reference<Tag2>::type
760 >::type(const typename boost::remove_reference<Tag2>::type&)
761 >(), std::move(other))
764 template<class Concept2, class Tag2>
765 any(any<Concept2, Tag2>& other, binding<Concept>&& binding_arg)
766 : table(binding_arg),
767 data(::boost::type_erasure::call(
769 typename ::boost::remove_const<
770 typename boost::remove_reference<Tag2>::type
771 >::type(const typename boost::remove_reference<Tag2>::type&)
775 template<class Concept2, class Tag2>
776 any(const any<Concept2, Tag2>& other, binding<Concept>&& binding_arg)
777 : table(binding_arg),
778 data(::boost::type_erasure::call(
780 typename ::boost::remove_const<
781 typename boost::remove_reference<Tag2>::type
782 >::type(const typename boost::remove_reference<Tag2>::type&)
786 template<class Concept2, class Tag2>
787 any(any<Concept2, Tag2>&& other, binding<Concept>&& binding_arg)
788 : table(binding_arg),
789 data(::boost::type_erasure::call(
791 typename ::boost::remove_const<
792 typename boost::remove_reference<Tag2>::type
793 >::type(const typename boost::remove_reference<Tag2>::type&)
794 >(), std::move(other))
797 template<class Concept2, class Tag2>
798 any(any<Concept2, Tag2>&& other, binding<Concept>& binding_arg)
799 : table(binding_arg),
800 data(::boost::type_erasure::call(
802 typename ::boost::remove_const<
803 typename boost::remove_reference<Tag2>::type
804 >::type(const typename boost::remove_reference<Tag2>::type&)
805 >(), std::move(other))
808 template<class Concept2, class Tag2>
809 any(any<Concept2, Tag2>&& other, const binding<Concept>& binding_arg)
810 : table(binding_arg),
811 data(::boost::type_erasure::call(
813 typename ::boost::remove_const<
814 typename boost::remove_reference<Tag2>::type
815 >::type(const typename boost::remove_reference<Tag2>::type&)
816 >(), std::move(other))
821 // One argument is a special case. The argument must be an any
822 // and the constructor must be explicit.
824 explicit any(const any<Concept, Tag2>& other)
825 : table(::boost::type_erasure::detail::access::table(other)),
826 data(::boost::type_erasure::call(
827 ::boost::type_erasure::detail::make(
828 false? this->_boost_type_erasure_deduce_constructor(other) : 0
833 explicit any(any<Concept, Tag2>& other)
834 : table(::boost::type_erasure::detail::access::table(other)),
835 data(::boost::type_erasure::call(
836 ::boost::type_erasure::detail::make(
837 false? this->_boost_type_erasure_deduce_constructor(other) : 0
842 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
844 explicit any(any<Concept, Tag2>&& other)
845 : table(::boost::type_erasure::detail::access::table(other)),
846 data(::boost::type_erasure::call(
847 ::boost::type_erasure::detail::make(
848 false? this->_boost_type_erasure_deduce_constructor(std::move(other)) : 0
854 explicit any(const binding<Concept>& binding_arg)
855 : table(binding_arg),
857 ::boost::type_erasure::call(
859 ::boost::type_erasure::constructible<T()>()
863 explicit any(binding<Concept>& binding_arg)
864 : table(binding_arg),
866 ::boost::type_erasure::call(
868 ::boost::type_erasure::constructible<T()>()
873 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
875 explicit any(binding<Concept>&& binding_arg)
876 : table(binding_arg),
878 ::boost::type_erasure::call(
880 ::boost::type_erasure::constructible<T()>()
887 #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
889 template<class R, class... A, class... U>
890 const table_type& _boost_type_erasure_extract_table(
891 ::boost::type_erasure::constructible<R(A...)>*,
894 return *::boost::type_erasure::detail::extract_table(static_cast<void(*)(A...)>(0), u...);
897 template<class U0, class U1, class... U>
898 any(U0&& u0, U1&& u1, U&&... u)
900 _boost_type_erasure_extract_table(
901 false? this->_boost_type_erasure_deduce_constructor(std::forward<U0>(u0), std::forward<U1>(u1), std::forward<U>(u)...) : 0,
902 std::forward<U0>(u0), std::forward<U1>(u1), std::forward<U>(u)...
906 ::boost::type_erasure::call(
907 ::boost::type_erasure::detail::make(
908 false? this->_boost_type_erasure_deduce_constructor(std::forward<U0>(u0), std::forward<U1>(u1), std::forward<U>(u)...) : 0
910 std::forward<U0>(u0), std::forward<U1>(u1), std::forward<U>(u)...
915 template<class U0, class... U>
916 any(const binding<Concept>& binding_arg, U0&& u0, U&&... u)
917 : table(binding_arg),
919 ::boost::type_erasure::call(
921 ::boost::type_erasure::detail::make(
922 false? this->_boost_type_erasure_deduce_constructor(std::forward<U0>(u0), std::forward<U>(u)...) : 0
924 std::forward<U0>(u0), std::forward<U>(u)...
930 template<class U0, class... U>
931 any(binding<Concept>& binding_arg, U0&& u0, U&&... u)
932 : table(binding_arg),
934 ::boost::type_erasure::call(
936 ::boost::type_erasure::detail::make(
937 false? this->_boost_type_erasure_deduce_constructor(std::forward<U0>(u0), std::forward<U>(u)...) : 0
939 std::forward<U0>(u0), std::forward<U>(u)...
943 template<class U0, class... U>
944 any(binding<Concept>&& binding_arg, U0&& u0, U&&... u)
945 : table(binding_arg),
947 ::boost::type_erasure::call(
949 ::boost::type_erasure::detail::make(
950 false? this->_boost_type_erasure_deduce_constructor(std::forward<U0>(u0), std::forward<U>(u)...) : 0
952 std::forward<U0>(u0), std::forward<U>(u)...
959 #include <boost/type_erasure/detail/construct.hpp>
966 * Assigns to an @ref any.
968 * If an appropriate overload of @ref assignable is not available
969 * and @ref relaxed is in @c Concept, falls back on
970 * constructing from @c other.
972 * \throws Whatever the assignment operator of the contained
973 * type throws. When falling back on construction,
974 * throws @c std::bad_alloc or whatever the copy
975 * constructor of the contained type throws. In
976 * this case assignment provides the strong exception
977 * guarantee. When calling the assignment operator
978 * of the contained type, the exception guarantee is
979 * whatever the contained type provides.
981 any& operator=(const any& other)
983 _boost_type_erasure_resolve_assign(other);
987 * Assigns to an @ref any.
989 * If an appropriate overload of @ref assignable is not available
990 * and @ref relaxed is in @c Concept, falls back on
991 * constructing from @c other.
993 * \throws Whatever the assignment operator of the contained
994 * type throws. When falling back on construction,
995 * throws @c std::bad_alloc or whatever the copy
996 * constructor of the contained type throws. In
997 * this case assignment provides the strong exception
998 * guarantee. When calling an assignment operator
999 * of the contained type, the exception guarantee is
1000 * whatever the contained type provides.
1003 any& operator=(const U& other)
1005 _boost_type_erasure_resolve_assign(other);
1009 * \pre @c Concept includes @ref destructible "destructible<T>".
1013 table.template find<destructible<T> >()(data);
1016 #ifndef BOOST_NO_FUNCTION_REFERENCE_QUALIFIERS
1017 /** INTERNAL ONLY */
1018 operator param<Concept, T&>() & { return param<Concept, T&>(data, table); }
1019 /** INTERNAL ONLY */
1020 operator param<Concept, T&&>() && { return param<Concept, T&&>(data, table); }
1023 /** INTERNAL ONLY */
1024 void _boost_type_erasure_swap(any& other)
1026 ::std::swap(data, other.data);
1027 ::std::swap(table, other.table);
1029 /** INTERNAL ONLY */
1030 template<class Other>
1031 void _boost_type_erasure_resolve_assign(const Other& other)
1033 _boost_type_erasure_assign_impl(
1035 false? this->_boost_type_erasure_deduce_assign(
1036 ::boost::type_erasure::detail::make_fallback(
1038 ::boost::mpl::bool_<
1040 ::boost::type_erasure::detail::check_overload(
1041 ::boost::declval<any&>().
1042 _boost_type_erasure_deduce_assign(other)
1044 ) == sizeof(::boost::type_erasure::detail::yes)
1048 ::boost::type_erasure::is_relaxed<Concept>()
1051 /** INTERNAL ONLY */
1052 template<class Other, class U>
1053 void _boost_type_erasure_assign_impl(
1055 const assignable<T, U>*,
1056 ::boost::mpl::false_)
1058 ::boost::type_erasure::call(assignable<T, U>(), *this, other);
1060 /** INTERNAL ONLY */
1061 template<class Other, class U>
1062 void _boost_type_erasure_assign_impl(
1064 const assignable<T, U>*,
1065 ::boost::mpl::true_)
1067 ::boost::type_erasure::call(assignable<T, U>(), *this, other);
1069 /** INTERNAL ONLY */
1070 template<class Other>
1071 void _boost_type_erasure_assign_impl(
1074 ::boost::mpl::true_)
1077 _boost_type_erasure_swap(temp);
1079 /** INTERNAL ONLY */
1080 template<class Concept2, class Tag2>
1081 void _boost_type_erasure_resolve_assign(const any<Concept2, Tag2>& other)
1083 _boost_type_erasure_assign_impl(
1085 false? this->_boost_type_erasure_deduce_assign(
1086 ::boost::type_erasure::detail::make_fallback(
1088 ::boost::mpl::bool_<
1090 ::boost::type_erasure::detail::check_overload(
1091 ::boost::declval<any&>().
1092 _boost_type_erasure_deduce_assign(other)
1094 ) == sizeof(::boost::type_erasure::detail::yes)
1098 false? this->_boost_type_erasure_deduce_constructor(
1099 ::boost::type_erasure::detail::make_fallback(
1101 ::boost::mpl::bool_<
1103 ::boost::type_erasure::detail::check_overload(
1104 ::boost::declval<any&>().
1105 _boost_type_erasure_deduce_constructor(other)
1107 ) == sizeof(::boost::type_erasure::detail::yes)
1111 ::boost::type_erasure::is_relaxed<Concept>()
1114 /** INTERNAL ONLY */
1115 template<class Other, class U>
1116 void _boost_type_erasure_assign_impl(
1118 const assignable<T, U>*,
1120 ::boost::mpl::false_)
1122 ::boost::type_erasure::call(assignable<T, U>(), *this, other);
1124 /** INTERNAL ONLY */
1125 template<class Other, class U>
1126 void _boost_type_erasure_assign_impl(
1128 const assignable<T, U>*,
1130 ::boost::mpl::true_)
1132 ::boost::type_erasure::call(assignable<T, U>(), *this, other);
1134 /** INTERNAL ONLY */
1135 template<class Other, class Sig>
1136 void _boost_type_erasure_assign_impl(
1139 const constructible<Sig>*,
1140 ::boost::mpl::true_)
1143 _boost_type_erasure_swap(temp);
1145 /** INTERNAL ONLY */
1146 template<class Other, class U, class Sig>
1147 void _boost_type_erasure_assign_impl(
1149 const assignable<T, U>*,
1150 const constructible<Sig>*,
1151 ::boost::mpl::true_)
1153 if(::boost::type_erasure::check_match(assignable<T, U>(), *this, other))
1155 ::boost::type_erasure::unchecked_call(assignable<T, U>(), *this, other);
1160 _boost_type_erasure_swap(temp);
1163 friend struct ::boost::type_erasure::detail::access;
1164 // The table has to be initialized first for exception
1165 // safety in some constructors.
1167 ::boost::type_erasure::detail::storage data;
1170 template<class Concept, class T>
1171 class any<Concept, T&> :
1172 public ::boost::type_erasure::detail::compute_bases<
1173 ::boost::type_erasure::any<Concept, T&>,
1178 typedef ::boost::type_erasure::binding<Concept> table_type;
1180 /** INTERNAL ONLY */
1181 typedef Concept _boost_type_erasure_concept_type;
1182 /** INTERNAL ONLY */
1183 any(const ::boost::type_erasure::detail::storage& data_arg,
1184 const table_type& table_arg)
1189 * Constructs an @ref any from a reference.
1191 * \param arg The object to bind the reference to.
1193 * \pre @c U is a model of @c Concept.
1194 * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
1200 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
1201 , typename ::boost::disable_if<
1203 ::boost::is_const<U>,
1204 ::boost::type_erasure::detail::is_any<U>
1210 BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, U),
1211 ::boost::type_erasure::make_binding<
1212 ::boost::mpl::map< ::boost::mpl::pair<T, U> >
1216 data.data = ::boost::addressof(arg);
1219 * Constructs an @ref any from a reference.
1221 * \param arg The object to bind the reference to.
1222 * \param binding Specifies the actual types that
1223 * all the placeholders should bind to.
1225 * \pre @c U is a model of @c Concept.
1226 * \pre @c Map is an MPL map with an entry for every
1227 * non-deduced placeholder referred to by @c Concept.
1231 template<class U, class Map>
1232 any(U& arg, const static_binding<Map>& binding_arg)
1234 BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
1238 BOOST_MPL_ASSERT((::boost::is_same<
1239 typename ::boost::mpl::at<Map, T>::type, U>));
1240 data.data = ::boost::addressof(arg);
1243 * Constructs an @ref any from another reference.
1245 * \param other The reference to copy.
1249 any(const any& other)
1253 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
1260 * Constructs an @ref any from another @ref any.
1262 * \param other The object to bind the reference to.
1266 any(any<Concept, T>& other)
1267 : data(::boost::type_erasure::detail::access::data(other)),
1268 table(::boost::type_erasure::detail::access::table(other))
1271 * Constructs an @ref any from another reference.
1273 * \param other The reference to copy.
1275 * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
1276 * \pre After substituting @c T for @c Tag2, the requirements of
1277 * @c Concept2 must be a superset of the requirements of
1280 * \throws std::bad_alloc
1282 template<class Concept2, class Tag2>
1283 any(const any<Concept2, Tag2&>& other
1284 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
1285 , typename ::boost::disable_if<
1287 ::boost::is_same<Concept, Concept2>,
1288 ::boost::is_const<Tag2>
1293 : data(::boost::type_erasure::detail::access::data(other)),
1295 ::boost::type_erasure::detail::access::table(other),
1304 * Constructs an @ref any from another @ref any.
1306 * \param other The object to bind the reference to.
1308 * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
1309 * \pre After substituting @c T for @c Tag2, the requirements of
1310 * @c Concept2 must be a superset of the requirements of
1313 * \throws std::bad_alloc
1315 template<class Concept2, class Tag2>
1316 any(any<Concept2, Tag2>& other
1317 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
1318 , typename ::boost::disable_if<
1320 ::boost::is_same<Concept, Concept2>,
1321 ::boost::is_const<typename ::boost::remove_reference<Tag2>::type>
1326 : data(::boost::type_erasure::detail::access::data(other)),
1328 ::boost::type_erasure::detail::access::table(other),
1332 typename ::boost::remove_reference<Tag2>::type
1337 * Constructs an @ref any from another reference.
1339 * \param other The reference to copy.
1340 * \param binding Specifies the mapping between the two concepts.
1342 * \pre @c Map must be an MPL map with keys for all the non-deduced
1343 * placeholders used by @c Concept and values for the corresponding
1344 * placeholders in @c Concept2.
1345 * \pre After substituting placeholders according to @c Map, the
1346 * requirements of @c Concept2 must be a superset of the
1347 * requirements of @c Concept.
1349 * \throws std::bad_alloc
1351 template<class Concept2, class Tag2, class Map>
1352 any(const any<Concept2, Tag2&>& other, const static_binding<Map>& binding_arg
1353 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
1354 , typename ::boost::disable_if< ::boost::is_const<Tag2> >::type* = 0
1357 : data(::boost::type_erasure::detail::access::data(other)),
1358 table(::boost::type_erasure::detail::access::table(other), binding_arg)
1361 * Constructs an @ref any from another @ref any.
1363 * \param other The object to bind the reference to.
1364 * \param binding Specifies the mapping between the two concepts.
1366 * \pre @c Map must be an MPL map with keys for all the non-deduced
1367 * placeholders used by @c Concept and values for the corresponding
1368 * placeholders in @c Concept2.
1369 * \pre After substituting placeholders according to @c Map, the
1370 * requirements of @c Concept2 must be a superset of the
1371 * requirements of @c Concept.
1373 * \throws std::bad_alloc
1375 template<class Concept2, class Tag2, class Map>
1376 any(any<Concept2, Tag2>& other, const static_binding<Map>& binding_arg
1377 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
1378 , typename ::boost::disable_if<
1379 ::boost::is_const<typename ::boost::remove_reference<Tag2>::type>
1383 : data(::boost::type_erasure::detail::access::data(other)),
1384 table(::boost::type_erasure::detail::access::table(other), binding_arg)
1387 * Constructs an @ref any from another reference.
1389 * \param other The reference to copy.
1390 * \param binding Specifies the bindings of placeholders to actual types.
1392 * \pre The type stored in @c other must match the type expected by
1395 * \post binding_of(*this) == @c binding
1399 template<class Concept2, class Tag2>
1400 any(const any<Concept2, Tag2&>& other, const binding<Concept>& binding_arg
1401 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
1402 , typename ::boost::disable_if<
1403 ::boost::is_const<Tag2>
1407 : data(::boost::type_erasure::detail::access::data(other)),
1411 * Constructs an @ref any from another @ref any.
1413 * \param other The object to bind the reference to.
1414 * \param binding Specifies the bindings of placeholders to actual types.
1416 * \pre The type stored in @c other must match the type expected by
1419 * \post binding_of(*this) == @c binding
1423 template<class Concept2, class Tag2>
1424 any(any<Concept2, Tag2>& other, const binding<Concept>& binding_arg
1425 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
1426 , typename ::boost::disable_if<
1427 ::boost::is_const<typename ::boost::remove_reference<Tag2>::type>
1431 : data(::boost::type_erasure::detail::access::data(other)),
1436 * Assigns to an @ref any.
1438 * If an appropriate overload of @ref assignable is not available
1439 * and @ref relaxed is in @c Concept, falls back on
1440 * constructing from @c other.
1442 * \throws Whatever the assignment operator of the contained
1443 * type throws. When falling back on construction,
1444 * throws @c std::bad_alloc. In this case assignment
1445 * provides the strong exception guarantee. When
1446 * calling the assignment operator of the contained type,
1447 * the exception guarantee is whatever the contained type provides.
1449 any& operator=(const any& other)
1451 _boost_type_erasure_resolve_assign(other);
1456 * Assigns to an @ref any.
1458 * If an appropriate overload of @ref assignable is not available
1459 * and @ref relaxed is in @c Concept, falls back on
1460 * constructing from @c other.
1462 * \throws Whatever the assignment operator of the contained
1463 * type throws. When falling back on construction,
1464 * throws @c std::bad_alloc. In this case assignment
1465 * provides the strong exception guarantee. When
1466 * calling the assignment operator of the contained type,
1467 * the exception guarantee is whatever the contained type provides.
1470 any& operator=(U& other)
1472 _boost_type_erasure_resolve_assign(other);
1477 * Assigns to an @ref any.
1479 * If an appropriate overload of @ref assignable is not available
1480 * and @ref relaxed is in @c Concept, falls back on
1481 * constructing from @c other.
1483 * \throws Whatever the assignment operator of the contained
1484 * type throws. When falling back on construction,
1485 * throws @c std::bad_alloc. In this case assignment
1486 * provides the strong exception guarantee. When
1487 * calling the assignment operator of the contained type,
1488 * the exception guarantee is whatever the contained type provides.
1491 any& operator=(const U& other)
1493 _boost_type_erasure_resolve_assign(other);
1497 #ifndef BOOST_NO_FUNCTION_REFERENCE_QUALIFIERS
1498 /** INTERNAL ONLY */
1499 operator param<Concept, T&>() const { return param<Concept, T&>(data, table); }
1503 /** INTERNAL ONLY */
1504 void _boost_type_erasure_swap(any& other)
1506 ::std::swap(data, other.data);
1507 ::std::swap(table, other.table);
1509 /** INTERNAL ONLY */
1510 template<class Other>
1511 void _boost_type_erasure_resolve_assign(Other& other)
1513 _boost_type_erasure_assign_impl(
1515 false? this->_boost_type_erasure_deduce_assign(
1516 ::boost::type_erasure::detail::make_fallback(
1518 ::boost::mpl::bool_<
1520 ::boost::type_erasure::detail::check_overload(
1521 ::boost::declval<any&>().
1522 _boost_type_erasure_deduce_assign(other)
1524 ) == sizeof(::boost::type_erasure::detail::yes)
1528 ::boost::type_erasure::is_relaxed<Concept>()
1531 /** INTERNAL ONLY */
1532 template<class Other, class U>
1533 void _boost_type_erasure_assign_impl(
1535 const assignable<T, U>*,
1536 ::boost::mpl::false_)
1538 ::boost::type_erasure::call(assignable<T, U>(), *this, other);
1540 /** INTERNAL ONLY */
1541 template<class Other, class U>
1542 void _boost_type_erasure_assign_impl(
1544 const assignable<T, U>*,
1545 ::boost::mpl::true_)
1547 if(::boost::type_erasure::check_match(assignable<T, U>(), *this, other)) {
1548 ::boost::type_erasure::unchecked_call(assignable<T, U>(), *this, other);
1551 _boost_type_erasure_swap(temp);
1554 /** INTERNAL ONLY */
1555 template<class Other>
1556 void _boost_type_erasure_assign_impl(
1559 ::boost::mpl::true_)
1562 _boost_type_erasure_swap(temp);
1565 friend struct ::boost::type_erasure::detail::access;
1566 ::boost::type_erasure::detail::storage data;
1571 #pragma warning(pop)
1574 template<class Concept, class T>
1575 class any<Concept, const T&> :
1576 public ::boost::type_erasure::detail::compute_bases<
1577 ::boost::type_erasure::any<Concept, const T&>,
1582 typedef ::boost::type_erasure::binding<Concept> table_type;
1584 /** INTERNAL ONLY */
1585 typedef Concept _boost_type_erasure_concept_type;
1586 /** INTERNAL ONLY */
1587 any(const ::boost::type_erasure::detail::storage& data_arg,
1588 const table_type& table_arg)
1593 * Constructs an @ref any from a reference.
1595 * \param arg The object to bind the reference to.
1597 * \pre @c U is a model of @c Concept.
1598 * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
1605 BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, U),
1606 ::boost::type_erasure::make_binding<
1607 ::boost::mpl::map< ::boost::mpl::pair<T, U> >
1611 data.data = const_cast<void*>(static_cast<const void*>(::boost::addressof(arg)));
1614 * Constructs an @ref any from a reference.
1616 * \param arg The object to bind the reference to.
1617 * \param binding Specifies the actual types that
1618 * all the placeholders should bind to.
1620 * \pre @c U is a model of @c Concept.
1621 * \pre @c Map is an MPL map with an entry for every
1622 * non-deduced placeholder referred to by @c Concept.
1626 template<class U, class Map>
1627 any(const U& arg, const static_binding<Map>& binding_arg)
1629 BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
1633 BOOST_MPL_ASSERT((::boost::is_same<
1634 typename ::boost::mpl::at<Map, T>::type, U>));
1635 data.data = const_cast<void*>(static_cast<const void*>(::boost::addressof(arg)));
1638 * Constructs an @ref any from another @ref any.
1640 * \param other The reference to copy.
1644 any(const any& other)
1649 * Constructs an @ref any from another @ref any.
1651 * \param other The reference to copy.
1655 any(const any<Concept, T&>& other)
1656 : data(::boost::type_erasure::detail::access::data(other)),
1657 table(::boost::type_erasure::detail::access::table(other))
1660 * Constructs an @ref any from another @ref any.
1662 * \param other The object to bind the reference to.
1666 any(const any<Concept, T>& other)
1667 : data(::boost::type_erasure::detail::access::data(other)),
1668 table(::boost::type_erasure::detail::access::table(other))
1670 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
1672 * Constructs an @ref any from another @ref any.
1674 * \param other The object to bind the reference to.
1678 any(const any<Concept, T&&>& other)
1679 : data(::boost::type_erasure::detail::access::data(other)),
1680 table(::boost::type_erasure::detail::access::table(other))
1684 * Constructs an @ref any from another @ref any.
1686 * \param other The object to bind the reference to.
1688 * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
1689 * \pre After substituting @c T for @c Tag2, the requirements of
1690 * @c Concept2 must be a superset of the requirements of
1693 * \throws std::bad_alloc
1695 template<class Concept2, class Tag2>
1696 any(const any<Concept2, Tag2>& other
1697 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
1698 , typename ::boost::disable_if< ::boost::is_same<Concept, Concept2> >::type* = 0
1701 : data(::boost::type_erasure::detail::access::data(other)),
1703 ::boost::type_erasure::detail::access::table(other),
1707 typename ::boost::remove_const<
1708 typename ::boost::remove_reference<Tag2>::type
1714 * Constructs an @ref any from another @ref any.
1716 * \param other The object to bind the reference to.
1717 * \param binding Specifies the mapping between the two concepts.
1719 * \pre @c Map must be an MPL map with keys for all the non-deduced
1720 * placeholders used by @c Concept and values for the corresponding
1721 * placeholders in @c Concept2.
1722 * \pre After substituting placeholders according to @c Map, the
1723 * requirements of @c Concept2 must be a superset of the
1724 * requirements of @c Concept.
1726 * \throws std::bad_alloc
1728 template<class Concept2, class Tag2, class Map>
1729 any(const any<Concept2, Tag2>& other, const static_binding<Map>& binding_arg)
1730 : data(::boost::type_erasure::detail::access::data(other)),
1731 table(::boost::type_erasure::detail::access::table(other), binding_arg)
1734 * Constructs an @ref any from another @ref any.
1736 * \param other The object to bind the reference to.
1737 * \param binding Specifies the bindings of placeholders to actual types.
1739 * \pre The type stored in @c other must match the type expected by
1742 * \post binding_of(*this) == @c binding
1746 template<class Concept2, class Tag2>
1747 any(const any<Concept2, Tag2>& other, const binding<Concept>& binding_arg)
1748 : data(::boost::type_erasure::detail::access::data(other)),
1754 * Assigns to an @ref any.
1756 * \pre @ref relaxed is in @c Concept.
1760 any& operator=(const any& other)
1762 BOOST_MPL_ASSERT((::boost::type_erasure::is_relaxed<Concept>));
1764 _boost_type_erasure_swap(temp);
1768 * Assigns to an @ref any.
1770 * \pre @ref relaxed is in @c Concept.
1772 * \throws std::bad_alloc. Provides the strong exception guarantee.
1775 any& operator=(const U& other)
1777 BOOST_MPL_ASSERT((::boost::type_erasure::is_relaxed<Concept>));
1779 _boost_type_erasure_swap(temp);
1783 #ifndef BOOST_NO_FUNCTION_REFERENCE_QUALIFIERS
1784 /** INTERNAL ONLY */
1785 operator param<Concept, const T&>() const { return param<Concept, const T&>(data, table); }
1788 /** INTERNAL ONLY */
1789 void _boost_type_erasure_swap(any& other)
1791 ::std::swap(data, other.data);
1792 ::std::swap(table, other.table);
1794 friend struct ::boost::type_erasure::detail::access;
1795 ::boost::type_erasure::detail::storage data;
1799 #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
1801 template<class Concept, class T>
1802 class any<Concept, T&&> :
1803 public ::boost::type_erasure::detail::compute_bases<
1804 ::boost::type_erasure::any<Concept, T&&>,
1809 typedef ::boost::type_erasure::binding<Concept> table_type;
1811 /** INTERNAL ONLY */
1812 typedef Concept _boost_type_erasure_concept_type;
1813 /** INTERNAL ONLY */
1814 any(const ::boost::type_erasure::detail::storage& data_arg,
1815 const table_type& table_arg)
1820 * Constructs an @ref any from a reference.
1822 * \param arg The object to bind the reference to.
1824 * \pre @c U is a model of @c Concept.
1825 * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
1831 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
1832 , typename ::boost::disable_if<
1834 ::boost::is_reference<U>,
1835 ::boost::is_const<U>,
1836 ::boost::type_erasure::detail::is_any<U>
1842 BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, U),
1843 ::boost::type_erasure::make_binding<
1844 ::boost::mpl::map< ::boost::mpl::pair<T, U> >
1848 data.data = ::boost::addressof(arg);
1851 * Constructs an @ref any from a reference.
1853 * \param arg The object to bind the reference to.
1854 * \param binding Specifies the actual types that
1855 * all the placeholders should bind to.
1857 * \pre @c U is a model of @c Concept.
1858 * \pre @c Map is an MPL map with an entry for every
1859 * non-deduced placeholder referred to by @c Concept.
1863 template<class U, class Map>
1864 any(U&& arg, const static_binding<Map>& binding_arg)
1866 BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
1870 BOOST_MPL_ASSERT((::boost::is_same<
1871 typename ::boost::mpl::at<Map, T>::type, U>));
1872 data.data = ::boost::addressof(arg);
1875 * Constructs an @ref any from another rvalue reference.
1877 * \param other The reference to copy.
1881 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
1884 table(std::move(other.table))
1886 any(const any& other)
1892 * Constructs an @ref any from another @ref any.
1894 * \param other The object to bind the reference to.
1898 any(any<Concept, T>&& other)
1899 : data(::boost::type_erasure::detail::access::data(other)),
1900 table(std::move(::boost::type_erasure::detail::access::table(other)))
1903 * Constructs an @ref any from another rvalue reference.
1905 * \param other The reference to copy.
1907 * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
1908 * \pre After substituting @c T for @c Tag2, the requirements of
1909 * @c Concept2 must be a superset of the requirements of
1912 * \throws std::bad_alloc
1914 template<class Concept2, class Tag2>
1915 any(any<Concept2, Tag2&&>&& other
1916 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
1917 , typename ::boost::disable_if<
1919 ::boost::is_reference<Tag2>,
1920 ::boost::is_same<Concept, Concept2>,
1921 ::boost::is_const<Tag2>
1926 : data(::boost::type_erasure::detail::access::data(other)),
1928 std::move(::boost::type_erasure::detail::access::table(other)),
1937 * Constructs an @ref any from another @ref any.
1939 * \param other The object to bind the reference to.
1941 * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
1942 * \pre After substituting @c T for @c Tag2, the requirements of
1943 * @c Concept2 must be a superset of the requirements of
1946 * \throws std::bad_alloc
1948 template<class Concept2, class Tag2>
1949 any(any<Concept2, Tag2>&& other
1950 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
1951 , typename ::boost::disable_if<
1953 ::boost::is_same<Concept, Concept2>,
1954 ::boost::is_const<typename ::boost::remove_reference<Tag2>::type>
1959 : data(::boost::type_erasure::detail::access::data(other)),
1961 std::move(::boost::type_erasure::detail::access::table(other)),
1965 typename ::boost::remove_reference<Tag2>::type
1970 * Constructs an @ref any from another reference.
1972 * \param other The reference to copy.
1973 * \param binding Specifies the mapping between the two concepts.
1975 * \pre @c Map must be an MPL map with keys for all the non-deduced
1976 * placeholders used by @c Concept and values for the corresponding
1977 * placeholders in @c Concept2.
1978 * \pre After substituting placeholders according to @c Map, the
1979 * requirements of @c Concept2 must be a superset of the
1980 * requirements of @c Concept.
1982 * \throws std::bad_alloc
1984 template<class Concept2, class Tag2, class Map>
1985 any(const any<Concept2, Tag2&&>& other, const static_binding<Map>& binding_arg
1986 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
1987 , typename ::boost::disable_if< ::boost::is_const<Tag2> >::type* = 0
1990 : data(::boost::type_erasure::detail::access::data(other)),
1991 table(std::move(::boost::type_erasure::detail::access::table(other)), binding_arg)
1994 * Constructs an @ref any from another @ref any.
1996 * \param other The object to bind the reference to.
1997 * \param binding Specifies the mapping between the two concepts.
1999 * \pre @c Map must be an MPL map with keys for all the non-deduced
2000 * placeholders used by @c Concept and values for the corresponding
2001 * placeholders in @c Concept2.
2002 * \pre After substituting placeholders according to @c Map, the
2003 * requirements of @c Concept2 must be a superset of the
2004 * requirements of @c Concept.
2006 * \throws std::bad_alloc
2008 template<class Concept2, class Tag2, class Map>
2009 any(any<Concept2, Tag2>&& other, const static_binding<Map>& binding_arg
2010 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
2011 , typename ::boost::disable_if<
2012 ::boost::is_const<typename ::boost::remove_reference<Tag2>::type>
2016 : data(::boost::type_erasure::detail::access::data(other)),
2017 table(::boost::type_erasure::detail::access::table(other), binding_arg)
2020 * Constructs an @ref any from another rvalue reference.
2022 * \param other The reference to copy.
2023 * \param binding Specifies the bindings of placeholders to actual types.
2025 * \pre The type stored in @c other must match the type expected by
2028 * \post binding_of(*this) == @c binding
2032 template<class Concept2, class Tag2>
2033 any(const any<Concept2, Tag2&&>& other, const binding<Concept>& binding_arg
2034 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
2035 , typename ::boost::disable_if<
2036 ::boost::is_const<Tag2>
2040 : data(::boost::type_erasure::detail::access::data(other)),
2044 * Constructs an @ref any from another @ref any.
2046 * \param other The object to bind the reference to.
2047 * \param binding Specifies the bindings of placeholders to actual types.
2049 * \pre The type stored in @c other must match the type expected by
2052 * \post binding_of(*this) == @c binding
2056 template<class Concept2, class Tag2>
2057 any(any<Concept2, Tag2>&& other, const binding<Concept>& binding_arg
2058 #ifndef BOOST_TYPE_ERASURE_DOXYGEN
2059 , typename ::boost::disable_if<
2060 ::boost::is_const<typename ::boost::remove_reference<Tag2>::type>
2064 : data(::boost::type_erasure::detail::access::data(other)),
2069 * Assigns to an @ref any.
2071 * If an appropriate overload of @ref assignable is not available
2072 * and @ref relaxed is in @c Concept, falls back on
2073 * constructing from @c other.
2075 * \throws Whatever the assignment operator of the contained
2076 * type throws. When falling back on construction,
2077 * throws @c std::bad_alloc. In this case assignment
2078 * provides the strong exception guarantee. When
2079 * calling the assignment operator of the contained type,
2080 * the exception guarantee is whatever the contained type provides.
2082 any& operator=(const any& other)
2084 _boost_type_erasure_resolve_assign(other);
2089 * Assigns to an @ref any.
2091 * If an appropriate overload of @ref assignable is not available
2092 * and @ref relaxed is in @c Concept, falls back on
2093 * constructing from @c other.
2095 * \throws Whatever the assignment operator of the contained
2096 * type throws. When falling back on construction,
2097 * throws @c std::bad_alloc. In this case assignment
2098 * provides the strong exception guarantee. When
2099 * calling the assignment operator of the contained type,
2100 * the exception guarantee is whatever the contained type provides.
2103 any& operator=(U& other)
2105 _boost_type_erasure_resolve_assign(other);
2110 * Assigns to an @ref any.
2112 * If an appropriate overload of @ref assignable is not available
2113 * and @ref relaxed is in @c Concept, falls back on
2114 * constructing from @c other.
2116 * \throws Whatever the assignment operator of the contained
2117 * type throws. When falling back on construction,
2118 * throws @c std::bad_alloc. In this case assignment
2119 * provides the strong exception guarantee. When
2120 * calling the assignment operator of the contained type,
2121 * the exception guarantee is whatever the contained type provides.
2124 any& operator=(const U& other)
2126 _boost_type_erasure_resolve_assign(other);
2130 #ifndef BOOST_NO_FUNCTION_REFERENCE_QUALIFIERS
2131 /** INTERNAL ONLY */
2132 operator param<Concept, T&&>() const { return param<Concept, T&&>(data, table); }
2136 /** INTERNAL ONLY */
2137 void _boost_type_erasure_swap(any& other)
2139 ::std::swap(data, other.data);
2140 ::std::swap(table, other.table);
2142 /** INTERNAL ONLY */
2143 template<class Other>
2144 void _boost_type_erasure_resolve_assign(Other& other)
2146 _boost_type_erasure_assign_impl(
2148 false? this->_boost_type_erasure_deduce_assign(
2149 ::boost::type_erasure::detail::make_fallback(
2151 ::boost::mpl::bool_<
2153 ::boost::type_erasure::detail::check_overload(
2154 ::boost::declval<any&>().
2155 _boost_type_erasure_deduce_assign(other)
2157 ) == sizeof(::boost::type_erasure::detail::yes)
2161 ::boost::type_erasure::is_relaxed<Concept>()
2164 /** INTERNAL ONLY */
2165 template<class Other, class U>
2166 void _boost_type_erasure_assign_impl(
2168 const assignable<T, U>*,
2169 ::boost::mpl::false_)
2171 ::boost::type_erasure::call(assignable<T, U>(), *this, other);
2173 /** INTERNAL ONLY */
2174 template<class Other, class U>
2175 void _boost_type_erasure_assign_impl(
2177 const assignable<T, U>*,
2178 ::boost::mpl::true_)
2180 if(::boost::type_erasure::check_match(assignable<T, U>(), *this, other)) {
2181 ::boost::type_erasure::unchecked_call(assignable<T, U>(), *this, other);
2184 _boost_type_erasure_swap(temp);
2187 /** INTERNAL ONLY */
2188 template<class Other>
2189 void _boost_type_erasure_assign_impl(
2192 ::boost::mpl::true_)
2195 _boost_type_erasure_swap(temp);
2198 friend struct ::boost::type_erasure::detail::access;
2199 ::boost::type_erasure::detail::storage data;