any.hpp 102 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022
  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. #ifndef BOOST_TYPE_ERASURE_ANY_HPP_INCLUDED
  11. #define BOOST_TYPE_ERASURE_ANY_HPP_INCLUDED
  12. #include <algorithm>
  13. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  14. # include <utility> // std::forward, std::move
  15. #endif
  16. #include <boost/config.hpp>
  17. #include <boost/utility/enable_if.hpp>
  18. #include <boost/utility/addressof.hpp>
  19. #include <boost/utility/declval.hpp>
  20. #include <boost/mpl/bool.hpp>
  21. #include <boost/mpl/or.hpp>
  22. #include <boost/mpl/pair.hpp>
  23. #include <boost/mpl/map.hpp>
  24. #include <boost/mpl/reverse_fold.hpp>
  25. #include <boost/type_traits/decay.hpp>
  26. #include <boost/type_traits/remove_reference.hpp>
  27. #include <boost/type_traits/remove_const.hpp>
  28. #include <boost/type_traits/is_same.hpp>
  29. #include <boost/type_traits/is_const.hpp>
  30. #include <boost/preprocessor/cat.hpp>
  31. #include <boost/preprocessor/iteration/iterate.hpp>
  32. #include <boost/preprocessor/repetition/enum_params.hpp>
  33. #include <boost/preprocessor/repetition/enum_binary_params.hpp>
  34. #include <boost/preprocessor/repetition/enum_trailing_params.hpp>
  35. #include <boost/preprocessor/repetition/enum_trailing_binary_params.hpp>
  36. #include <boost/type_erasure/detail/access.hpp>
  37. #include <boost/type_erasure/detail/any_base.hpp>
  38. #include <boost/type_erasure/detail/normalize.hpp>
  39. #include <boost/type_erasure/detail/storage.hpp>
  40. #include <boost/type_erasure/detail/instantiate.hpp>
  41. #include <boost/type_erasure/config.hpp>
  42. #include <boost/type_erasure/binding.hpp>
  43. #include <boost/type_erasure/static_binding.hpp>
  44. #include <boost/type_erasure/concept_interface.hpp>
  45. #include <boost/type_erasure/call.hpp>
  46. #include <boost/type_erasure/relaxed.hpp>
  47. #include <boost/type_erasure/param.hpp>
  48. #ifdef BOOST_MSVC
  49. #pragma warning(push)
  50. #pragma warning(disable:4355)
  51. #pragma warning(disable:4521)
  52. #pragma warning(disable:4522) // multiple assignment operators specified
  53. #endif
  54. namespace boost {
  55. namespace type_erasure {
  56. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  57. template<class Sig>
  58. struct constructible;
  59. template<class T>
  60. struct destructible;
  61. template<class T, class U>
  62. struct assignable;
  63. #endif
  64. namespace detail {
  65. #if defined(BOOST_NO_CXX11_DECLTYPE) || defined(BOOST_NO_CXX11_TEMPLATE_ALIASES)
  66. template<class Concept, class Base, class ID>
  67. struct choose_concept_interface
  68. {
  69. typedef ::boost::type_erasure::concept_interface<Concept, Base, ID> type;
  70. };
  71. #else
  72. struct default_concept_interface
  73. {
  74. template<class Concept, class Base, class ID>
  75. using apply = ::boost::type_erasure::concept_interface<Concept, Base, ID>;
  76. };
  77. default_concept_interface boost_type_erasure_find_interface(...);
  78. template<class Concept, class Base, class ID>
  79. struct choose_concept_interface
  80. {
  81. typedef decltype(boost_type_erasure_find_interface(::boost::declval<Concept>())) finder;
  82. typedef typename finder::template apply<Concept, Base, ID> type;
  83. };
  84. #endif
  85. #ifndef BOOST_TYPE_ERASURE_USE_MP11
  86. template<class Derived, class Concept, class T>
  87. struct compute_bases
  88. {
  89. typedef typename ::boost::mpl::reverse_fold<
  90. typename ::boost::type_erasure::detail::collect_concepts<
  91. Concept
  92. >::type,
  93. ::boost::type_erasure::any_base<Derived>,
  94. ::boost::type_erasure::detail::choose_concept_interface<
  95. ::boost::mpl::_2,
  96. ::boost::mpl::_1,
  97. T
  98. >
  99. >::type type;
  100. };
  101. #else
  102. template<class ID>
  103. struct compute_bases_f
  104. {
  105. template<class Concept, class Base>
  106. using apply = typename ::boost::type_erasure::detail::choose_concept_interface<Concept, Base, ID>::type;
  107. };
  108. template<class Derived, class Concept, class T>
  109. using compute_bases_t =
  110. ::boost::mp11::mp_reverse_fold<
  111. typename ::boost::type_erasure::detail::collect_concepts_t<
  112. Concept
  113. >,
  114. ::boost::type_erasure::any_base<Derived>,
  115. ::boost::type_erasure::detail::compute_bases_f<T>::template apply
  116. >;
  117. template<class Derived, class Concept, class T>
  118. using compute_bases = ::boost::mpl::identity< ::boost::type_erasure::detail::compute_bases_t<Derived, Concept, T> >;
  119. #endif
  120. template<class T>
  121. T make(T*) { return T(); }
  122. // This dance is necessary to avoid errors calling
  123. // an ellipsis function with a non-trivially-copyable
  124. // argument.
  125. typedef char no;
  126. struct yes { no dummy[2]; };
  127. template<class Op>
  128. yes check_overload(const Op*);
  129. no check_overload(const void*);
  130. struct fallback {};
  131. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  132. template<class T>
  133. fallback make_fallback(T&&, boost::mpl::false_)
  134. {
  135. return fallback();
  136. }
  137. template<class T>
  138. T&& make_fallback(T&& arg, boost::mpl::true_)
  139. {
  140. return std::forward<T>(arg);
  141. }
  142. #else
  143. template<class T>
  144. fallback make_fallback(const T&, boost::mpl::false_)
  145. {
  146. return fallback();
  147. }
  148. template<class T>
  149. const T& make_fallback(const T& arg, boost::mpl::true_)
  150. {
  151. return arg;
  152. }
  153. #endif
  154. template<class T>
  155. struct is_any : ::boost::mpl::false_ {};
  156. template<class Concept, class T>
  157. struct is_any<any<Concept, T> > : ::boost::mpl::true_ {};
  158. #ifdef BOOST_TYPE_ERASURE_SFINAE_FRIENDLY_CONSTRUCTORS
  159. template<class Any, class... U>
  160. struct has_constructor :
  161. ::boost::mpl::bool_<
  162. sizeof(
  163. ::boost::type_erasure::detail::check_overload(
  164. ::boost::declval<Any&>().
  165. _boost_type_erasure_deduce_constructor(::boost::declval<U>()...)
  166. )
  167. ) == sizeof(::boost::type_erasure::detail::yes)
  168. >
  169. {};
  170. template<class Any>
  171. using has_copy_constructor =
  172. ::boost::type_erasure::is_subconcept<
  173. ::boost::type_erasure::constructible<
  174. typename ::boost::type_erasure::placeholder_of<Any>::type(typename ::boost::type_erasure::placeholder_of<Any>::type const&)
  175. >,
  176. typename ::boost::type_erasure::concept_of<Any>::type
  177. >;
  178. template<class Any>
  179. using has_move_constructor =
  180. ::boost::type_erasure::is_subconcept<
  181. ::boost::type_erasure::constructible<
  182. typename ::boost::type_erasure::placeholder_of<Any>::type(typename ::boost::type_erasure::placeholder_of<Any>::type &&)
  183. >,
  184. typename ::boost::type_erasure::concept_of<Any>::type
  185. >;
  186. template<class Any>
  187. using has_mutable_copy_constructor =
  188. ::boost::type_erasure::is_subconcept<
  189. ::boost::type_erasure::constructible<
  190. typename ::boost::type_erasure::placeholder_of<Any>::type(typename ::boost::type_erasure::placeholder_of<Any>::type &)
  191. >,
  192. typename ::boost::type_erasure::concept_of<Any>::type
  193. >;
  194. struct empty {};
  195. template<class T>
  196. struct is_binding_arg : ::boost::mpl::false_ {};
  197. template<class T>
  198. struct is_binding_arg<binding<T> > : ::boost::mpl::true_ {};
  199. template<class T>
  200. struct is_binding_arg<binding<T>&&> : ::boost::mpl::true_ {};
  201. template<class T>
  202. struct is_binding_arg<binding<T>&> : ::boost::mpl::true_ {};
  203. template<class T>
  204. struct is_binding_arg<binding<T> const&> : ::boost::mpl::true_ {};
  205. template<class T>
  206. struct is_static_binding_arg : ::boost::mpl::false_ {};
  207. template<class T>
  208. struct is_static_binding_arg<static_binding<T> > : ::boost::mpl::true_ {};
  209. template<class T>
  210. struct is_static_binding_arg<static_binding<T>&&> : ::boost::mpl::true_ {};
  211. template<class T>
  212. struct is_static_binding_arg<static_binding<T>&> : ::boost::mpl::true_ {};
  213. template<class T>
  214. struct is_static_binding_arg<static_binding<T> const&> : ::boost::mpl::true_ {};
  215. template<class T>
  216. struct is_any_arg : ::boost::mpl::false_ {};
  217. template<class Concept, class T>
  218. struct is_any_arg<any<Concept, T> > : ::boost::mpl::true_ {};
  219. template<class Concept, class T>
  220. struct is_any_arg<any<Concept, T>&&> : ::boost::mpl::true_ {};
  221. template<class Concept, class T>
  222. struct is_any_arg<any<Concept, T>&> : ::boost::mpl::true_ {};
  223. template<class Concept, class T>
  224. struct is_any_arg<any<Concept, T> const&> : ::boost::mpl::true_ {};
  225. template<class T>
  226. struct safe_concept_of;
  227. template<class Concept, class T>
  228. struct safe_concept_of<any<Concept, T> > { typedef Concept type; };
  229. template<class Concept, class T>
  230. struct safe_concept_of<any<Concept, T>&&> { typedef Concept type; };
  231. template<class Concept, class T>
  232. struct safe_concept_of<any<Concept, T>&> { typedef Concept type; };
  233. template<class Concept, class T>
  234. struct safe_concept_of<any<Concept, T> const&> { typedef Concept type; };
  235. template<class T>
  236. struct safe_placeholder_of;
  237. template<class Concept, class T>
  238. struct safe_placeholder_of<any<Concept, T> > { typedef T type; };
  239. template<class Concept, class T>
  240. struct safe_placeholder_of<any<Concept, T>&&> { typedef T type; };
  241. template<class Concept, class T>
  242. struct safe_placeholder_of<any<Concept, T>&> { typedef T type; };
  243. template<class Concept, class T>
  244. struct safe_placeholder_of<any<Concept, T> const&> { typedef T type; };
  245. template<class T>
  246. using safe_placeholder_t = ::boost::remove_cv_t< ::boost::remove_reference_t<typename safe_placeholder_of<T>::type> >;
  247. }
  248. // Enables or deletes the copy/move constructors depending on the Concept.
  249. template<class Base, class Enable = void>
  250. struct any_constructor_control : Base
  251. {
  252. using Base::Base;
  253. };
  254. template<class Base>
  255. struct any_constructor_control<
  256. Base,
  257. typename boost::enable_if_c<
  258. !::boost::type_erasure::detail::has_copy_constructor<Base>::value &&
  259. ::boost::type_erasure::detail::has_move_constructor<Base>::value &&
  260. ::boost::type_erasure::detail::has_mutable_copy_constructor<Base>::value
  261. >::type
  262. > : Base
  263. {
  264. using Base::Base;
  265. any_constructor_control() = default;
  266. any_constructor_control(any_constructor_control&) = default;
  267. any_constructor_control(any_constructor_control&&) = default;
  268. any_constructor_control& operator=(any_constructor_control const& other) { static_cast<Base&>(*this) = static_cast<Base const&>(other); return *this; }
  269. any_constructor_control& operator=(any_constructor_control & other) { static_cast<Base&>(*this) = static_cast<Base&>(other); return *this; }
  270. any_constructor_control& operator=(any_constructor_control &&) = default;
  271. };
  272. template<class Base>
  273. struct any_constructor_control<
  274. Base,
  275. typename boost::enable_if_c<
  276. !::boost::type_erasure::detail::has_copy_constructor<Base>::value &&
  277. !::boost::type_erasure::detail::has_move_constructor<Base>::value &&
  278. ::boost::type_erasure::detail::has_mutable_copy_constructor<Base>::value
  279. >::type
  280. > : Base
  281. {
  282. using Base::Base;
  283. any_constructor_control() = default;
  284. any_constructor_control(any_constructor_control&) = default;
  285. any_constructor_control(any_constructor_control&&) = delete;
  286. any_constructor_control& operator=(any_constructor_control const& other) { static_cast<Base&>(*this) = static_cast<Base const&>(other); return *this; }
  287. any_constructor_control& operator=(any_constructor_control & other) { static_cast<Base&>(*this) = static_cast<Base&>(other); return *this; }
  288. any_constructor_control& operator=(any_constructor_control &&) = default;
  289. };
  290. template<class Base>
  291. struct any_constructor_control<
  292. Base,
  293. typename boost::enable_if_c<
  294. !::boost::type_erasure::detail::has_copy_constructor<Base>::value &&
  295. ::boost::type_erasure::detail::has_move_constructor<Base>::value &&
  296. !::boost::type_erasure::detail::has_mutable_copy_constructor<Base>::value
  297. >::type
  298. > : Base
  299. {
  300. using Base::Base;
  301. any_constructor_control() = default;
  302. any_constructor_control(any_constructor_control const&) = delete;
  303. any_constructor_control(any_constructor_control&&) = default;
  304. any_constructor_control& operator=(any_constructor_control const& other) { static_cast<Base&>(*this) = static_cast<Base const&>(other); return *this; }
  305. any_constructor_control& operator=(any_constructor_control & other) { static_cast<Base&>(*this) = static_cast<Base&>(other); return *this; }
  306. any_constructor_control& operator=(any_constructor_control &&) = default;
  307. };
  308. template<class Base>
  309. struct any_constructor_control<
  310. Base,
  311. typename boost::enable_if_c<
  312. !::boost::type_erasure::detail::has_copy_constructor<Base>::value &&
  313. !::boost::type_erasure::detail::has_move_constructor<Base>::value &&
  314. !::boost::type_erasure::detail::has_mutable_copy_constructor<Base>::value
  315. >::type
  316. > : Base
  317. {
  318. using Base::Base;
  319. any_constructor_control() = default;
  320. any_constructor_control(any_constructor_control const&) = delete;
  321. any_constructor_control(any_constructor_control&&) = delete;
  322. any_constructor_control& operator=(any_constructor_control const& other) { static_cast<Base&>(*this) = static_cast<Base const&>(other); return *this; }
  323. any_constructor_control& operator=(any_constructor_control & other) { static_cast<Base&>(*this) = static_cast<Base&>(other); return *this; }
  324. any_constructor_control& operator=(any_constructor_control &&) = default;
  325. };
  326. template<class Concept, class T>
  327. struct any_constructor_impl :
  328. ::boost::type_erasure::detail::compute_bases<
  329. ::boost::type_erasure::any<Concept, T>,
  330. Concept,
  331. T
  332. >::type
  333. {
  334. typedef typename ::boost::type_erasure::detail::compute_bases<
  335. ::boost::type_erasure::any<Concept, T>,
  336. Concept,
  337. T
  338. >::type _boost_type_erasure_base;
  339. // Internal constructors
  340. typedef ::boost::type_erasure::binding<Concept> _boost_type_erasure_table_type;
  341. any_constructor_impl(const ::boost::type_erasure::detail::storage& data_arg, const _boost_type_erasure_table_type& table_arg)
  342. : _boost_type_erasure_table(table_arg),
  343. _boost_type_erasure_data(data_arg)
  344. {}
  345. any_constructor_impl(::boost::type_erasure::detail::storage&& data_arg, const _boost_type_erasure_table_type& table_arg)
  346. : _boost_type_erasure_table(table_arg),
  347. _boost_type_erasure_data(data_arg)
  348. {}
  349. // default constructor
  350. any_constructor_impl()
  351. {
  352. BOOST_MPL_ASSERT((::boost::type_erasure::is_relaxed<Concept>));
  353. _boost_type_erasure_data.data = 0;
  354. }
  355. // capturing constructor
  356. template<class U,
  357. typename ::boost::enable_if_c<
  358. !::boost::type_erasure::detail::is_any_arg<U>::value &&
  359. !::boost::type_erasure::detail::is_binding_arg<U>::value &&
  360. !::boost::type_erasure::detail::is_static_binding_arg<U>::value
  361. >::type* = nullptr
  362. >
  363. any_constructor_impl(U&& data_arg)
  364. : _boost_type_erasure_table((
  365. BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, ::boost::decay_t<U>),
  366. ::boost::type_erasure::make_binding<
  367. ::boost::mpl::map1< ::boost::mpl::pair<T, ::boost::decay_t<U> > >
  368. >()
  369. )),
  370. _boost_type_erasure_data(std::forward<U>(data_arg))
  371. {}
  372. template<class U, class Map,
  373. typename ::boost::enable_if_c<
  374. !::boost::type_erasure::detail::is_any_arg<U>::value &&
  375. !::boost::type_erasure::detail::is_binding_arg<U>::value &&
  376. !::boost::type_erasure::detail::is_static_binding_arg<U>::value
  377. >::type* = nullptr
  378. >
  379. any_constructor_impl(U&& data_arg, const static_binding<Map>& b)
  380. : _boost_type_erasure_table((
  381. BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
  382. b
  383. )),
  384. _boost_type_erasure_data(std::forward<U>(data_arg))
  385. {
  386. BOOST_MPL_ASSERT((::boost::is_same<
  387. typename ::boost::mpl::at<Map, T>::type, ::boost::decay_t<U> >));
  388. }
  389. // converting constructor
  390. template<class U,
  391. typename ::boost::enable_if_c<
  392. ::boost::type_erasure::is_subconcept<
  393. Concept, typename ::boost::type_erasure::detail::safe_concept_of<U>::type,
  394. typename ::boost::mpl::if_c< ::boost::is_same<T, ::boost::type_erasure::detail::safe_placeholder_t<U> >::value,
  395. void,
  396. ::boost::mpl::map1<
  397. ::boost::mpl::pair<T, ::boost::type_erasure::detail::safe_placeholder_t<U> >
  398. >
  399. >::type
  400. >::value
  401. >::type* = nullptr
  402. >
  403. any_constructor_impl(U&& other)
  404. : _boost_type_erasure_table(
  405. ::boost::type_erasure::detail::access::table(other),
  406. typename ::boost::mpl::if_c< ::boost::is_same<T, ::boost::type_erasure::detail::safe_placeholder_t<U> >::value,
  407. #ifndef BOOST_TYPE_ERASURE_USE_MP11
  408. ::boost::type_erasure::detail::substitution_map< ::boost::mpl::map0<> >,
  409. #else
  410. ::boost::type_erasure::detail::make_identity_placeholder_map<Concept>,
  411. #endif
  412. ::boost::mpl::map1<
  413. ::boost::mpl::pair<
  414. T,
  415. ::boost::type_erasure::detail::safe_placeholder_t<U>
  416. >
  417. >
  418. >::type()
  419. ),
  420. _boost_type_erasure_data(::boost::type_erasure::call(
  421. ::boost::type_erasure::detail::make(
  422. false? other._boost_type_erasure_deduce_constructor(std::forward<U>(other)) : 0
  423. ), std::forward<U>(other))
  424. )
  425. {}
  426. template<class U,
  427. typename ::boost::enable_if_c<
  428. ::boost::type_erasure::detail::is_any_arg<U>::value
  429. >::type* = nullptr
  430. >
  431. any_constructor_impl(U&& other, const binding<Concept>& binding_arg)
  432. : _boost_type_erasure_table(binding_arg),
  433. _boost_type_erasure_data(::boost::type_erasure::call(
  434. ::boost::type_erasure::detail::make(
  435. false? other._boost_type_erasure_deduce_constructor(std::forward<U>(other)) : 0
  436. ), std::forward<U>(other))
  437. )
  438. {}
  439. template<class U, class Map,
  440. typename ::boost::enable_if_c<
  441. ::boost::type_erasure::is_subconcept<
  442. Concept, typename ::boost::type_erasure::detail::safe_concept_of<U>::type,
  443. Map
  444. >::value
  445. >::type* = nullptr
  446. >
  447. any_constructor_impl(U&& other, const static_binding<Map>& binding_arg)
  448. : _boost_type_erasure_table(::boost::type_erasure::detail::access::table(other), binding_arg),
  449. _boost_type_erasure_data(::boost::type_erasure::call(
  450. ::boost::type_erasure::detail::make(
  451. false? other._boost_type_erasure_deduce_constructor(std::forward<U>(other)) : 0
  452. ), std::forward<U>(other))
  453. )
  454. {}
  455. // copy and move constructors are a special case of the converting
  456. // constructors, but must be defined separately to keep C++ happy.
  457. any_constructor_impl(const any_constructor_impl& other)
  458. : _boost_type_erasure_table(
  459. ::boost::type_erasure::detail::access::table(other)
  460. ),
  461. _boost_type_erasure_data(::boost::type_erasure::call(
  462. ::boost::type_erasure::detail::make(
  463. false? other._boost_type_erasure_deduce_constructor(
  464. static_cast<typename _boost_type_erasure_base::_boost_type_erasure_derived_type const&>(other)) : 0
  465. ), other)
  466. )
  467. {}
  468. any_constructor_impl(any_constructor_impl& other)
  469. : _boost_type_erasure_table(
  470. ::boost::type_erasure::detail::access::table(other)
  471. ),
  472. _boost_type_erasure_data(::boost::type_erasure::call(
  473. ::boost::type_erasure::detail::make(
  474. false? other._boost_type_erasure_deduce_constructor(
  475. static_cast<typename _boost_type_erasure_base::_boost_type_erasure_derived_type &>(other)) : 0
  476. ), other)
  477. )
  478. {}
  479. any_constructor_impl(any_constructor_impl&& other)
  480. : _boost_type_erasure_table(
  481. ::boost::type_erasure::detail::access::table(other)
  482. ),
  483. _boost_type_erasure_data(::boost::type_erasure::call(
  484. ::boost::type_erasure::detail::make(
  485. false? other._boost_type_erasure_deduce_constructor(
  486. static_cast<typename _boost_type_erasure_base::_boost_type_erasure_derived_type &&>(other)) : 0
  487. ), std::move(other))
  488. )
  489. {}
  490. template<class R, class... A, class... U>
  491. const _boost_type_erasure_table_type& _boost_type_erasure_extract_table(
  492. ::boost::type_erasure::constructible<R(A...)>*,
  493. U&&... u)
  494. {
  495. return *::boost::type_erasure::detail::extract_table(static_cast<void(*)(A...)>(0), u...);
  496. }
  497. // forwarding constructor
  498. template<class... U,
  499. typename ::boost::enable_if_c<
  500. ::boost::type_erasure::detail::has_constructor<any_constructor_impl, U...>::value
  501. >::type* = nullptr
  502. >
  503. explicit any_constructor_impl(U&&... u)
  504. : _boost_type_erasure_table(
  505. _boost_type_erasure_extract_table(
  506. false? this->_boost_type_erasure_deduce_constructor(std::forward<U>(u)...) : 0,
  507. std::forward<U>(u)...
  508. )
  509. ),
  510. _boost_type_erasure_data(
  511. ::boost::type_erasure::call(
  512. ::boost::type_erasure::detail::make(
  513. false? this->_boost_type_erasure_deduce_constructor(std::forward<U>(u)...) : 0
  514. ),
  515. std::forward<U>(u)...
  516. )
  517. )
  518. {}
  519. template<class... U,
  520. typename ::boost::enable_if_c<
  521. ::boost::type_erasure::detail::has_constructor<any_constructor_impl, U...>::value
  522. >::type* = nullptr
  523. >
  524. explicit any_constructor_impl(const binding<Concept>& binding_arg, U&&... u)
  525. : _boost_type_erasure_table(binding_arg),
  526. _boost_type_erasure_data(
  527. ::boost::type_erasure::call(
  528. binding_arg,
  529. ::boost::type_erasure::detail::make(
  530. false? this->_boost_type_erasure_deduce_constructor(std::forward<U>(u)...) : 0
  531. ),
  532. std::forward<U>(u)...
  533. )
  534. )
  535. {}
  536. // The assignment operator and destructor must be defined here rather
  537. // than in any to avoid implicitly deleting the move constructor.
  538. any_constructor_impl& operator=(const any_constructor_impl& other)
  539. {
  540. static_cast<typename _boost_type_erasure_base::_boost_type_erasure_derived_type*>(this)->_boost_type_erasure_resolve_assign(
  541. static_cast<const typename _boost_type_erasure_base::_boost_type_erasure_derived_type&>(other));
  542. return *this;
  543. }
  544. any_constructor_impl& operator=(any_constructor_impl& other)
  545. {
  546. static_cast<typename _boost_type_erasure_base::_boost_type_erasure_derived_type*>(this)->_boost_type_erasure_resolve_assign(
  547. static_cast<typename _boost_type_erasure_base::_boost_type_erasure_derived_type&>(other));
  548. return *this;
  549. }
  550. any_constructor_impl& operator=(any_constructor_impl&& other)
  551. {
  552. static_cast<typename _boost_type_erasure_base::_boost_type_erasure_derived_type*>(this)->_boost_type_erasure_resolve_assign(
  553. static_cast<typename _boost_type_erasure_base::_boost_type_erasure_derived_type&&>(other));
  554. return *this;
  555. }
  556. ~any_constructor_impl()
  557. {
  558. _boost_type_erasure_table.template find<
  559. ::boost::type_erasure::destructible<T>
  560. >()(_boost_type_erasure_data);
  561. }
  562. protected:
  563. friend struct ::boost::type_erasure::detail::access;
  564. _boost_type_erasure_table_type _boost_type_erasure_table;
  565. ::boost::type_erasure::detail::storage _boost_type_erasure_data;
  566. };
  567. namespace detail {
  568. #endif
  569. template<class T>
  570. struct is_rvalue_for_any :
  571. ::boost::mpl::not_<
  572. ::boost::is_lvalue_reference<T>
  573. >
  574. {};
  575. template<class C, class P>
  576. struct is_rvalue_for_any<any<C, P> > :
  577. ::boost::mpl::not_<
  578. ::boost::is_lvalue_reference<P>
  579. >
  580. {};
  581. }
  582. /**
  583. * The class template @ref any can store any object that
  584. * models a specific \Concept. It dispatches all
  585. * the functions defined by the \Concept to the contained type
  586. * at runtime.
  587. *
  588. * \tparam Concept The \Concept that the stored type should model.
  589. * \tparam T A @ref placeholder specifying which type this is.
  590. *
  591. * \see concept_of, placeholder_of, \any_cast, \is_empty, \binding_of, \typeid_of
  592. */
  593. template<class Concept, class T = _self>
  594. class any :
  595. #ifdef BOOST_TYPE_ERASURE_SFINAE_FRIENDLY_CONSTRUCTORS
  596. public ::boost::type_erasure::any_constructor_control<
  597. ::boost::type_erasure::any_constructor_impl<
  598. Concept,
  599. T
  600. >
  601. >
  602. #else
  603. public ::boost::type_erasure::detail::compute_bases<
  604. ::boost::type_erasure::any<Concept, T>,
  605. Concept,
  606. T
  607. >::type
  608. #endif
  609. {
  610. typedef ::boost::type_erasure::binding<Concept> table_type;
  611. public:
  612. /** INTERNAL ONLY */
  613. typedef Concept _boost_type_erasure_concept_type;
  614. #if defined(BOOST_TYPE_ERASURE_SFINAE_FRIENDLY_CONSTRUCTORS)
  615. using _boost_type_erasure_base = ::boost::type_erasure::any_constructor_control<
  616. ::boost::type_erasure::any_constructor_impl<
  617. Concept,
  618. T
  619. >
  620. >;
  621. using _boost_type_erasure_base::_boost_type_erasure_base;
  622. #else
  623. /** INTERNAL ONLY */
  624. any(const ::boost::type_erasure::detail::storage& data_arg, const table_type& table_arg)
  625. : table(table_arg),
  626. data(data_arg)
  627. {}
  628. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  629. /** INTERNAL ONLY */
  630. any(::boost::type_erasure::detail::storage&& data_arg, const table_type& table_arg)
  631. : table(table_arg),
  632. data(data_arg)
  633. {}
  634. #endif
  635. /**
  636. * Constructs an empty @ref any.
  637. *
  638. * Except as otherwise noted, all operations on an
  639. * empty @ref any result in a @ref bad_function_call exception.
  640. * The copy-constructor of an empty @ref any creates another
  641. * null @ref any. The destructor of an empty @ref any is a no-op.
  642. * Comparison operators treat all empty @ref any "anys" as equal.
  643. * \typeid_of applied to an empty @ref any returns @c typeid(void).
  644. *
  645. * An @ref any which does not include @ref relaxed in its
  646. * \Concept can never be null.
  647. *
  648. * \pre @ref relaxed must be in @c Concept.
  649. *
  650. * \throws Nothing.
  651. *
  652. * @see \is_empty
  653. */
  654. any()
  655. {
  656. BOOST_MPL_ASSERT((::boost::type_erasure::is_relaxed<Concept>));
  657. data.data = 0;
  658. }
  659. #if defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  660. template<class U>
  661. any(const U& data_arg)
  662. : table((
  663. BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, U),
  664. ::boost::type_erasure::make_binding<
  665. ::boost::mpl::map1< ::boost::mpl::pair<T, U> >
  666. >()
  667. )),
  668. data(data_arg)
  669. {}
  670. template<class U, class Map>
  671. any(const U& data_arg, const static_binding<Map>& binding_arg)
  672. : table((
  673. BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
  674. binding_arg
  675. )),
  676. data(data_arg)
  677. {
  678. BOOST_MPL_ASSERT((::boost::is_same<
  679. typename ::boost::mpl::at<Map, T>::type, U>));
  680. }
  681. #else
  682. /**
  683. * Constructs an @ref any to hold a copy of @c data.
  684. * The @c Concept will be instantiated with the
  685. * placeholder @c T bound to U.
  686. *
  687. * \param data The object to store in the @ref any.
  688. *
  689. * \pre @c U is a model of @c Concept.
  690. * \pre @c U must be \CopyConstructible.
  691. * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
  692. *
  693. * \throws std::bad_alloc or whatever that the copy
  694. * constructor of @c U throws.
  695. *
  696. * \note This constructor never matches if the argument is
  697. * an @ref any, @ref binding, or @ref static_binding.
  698. */
  699. template<class U>
  700. any(U&& data_arg)
  701. : table((
  702. BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, typename ::boost::remove_cv<typename ::boost::remove_reference<U>::type>::type),
  703. ::boost::type_erasure::make_binding<
  704. ::boost::mpl::map1< ::boost::mpl::pair<T, typename ::boost::remove_cv<typename ::boost::remove_reference<U>::type>::type> >
  705. >()
  706. )),
  707. data(std::forward<U>(data_arg))
  708. {}
  709. /**
  710. * Constructs an @ref any to hold a copy of @c data
  711. * with explicitly specified placeholder bindings.
  712. *
  713. * \param data The object to store in the @ref any.
  714. * \param binding Specifies the types that
  715. * all the placeholders should bind to.
  716. *
  717. * \pre @c U is a model of @c Concept.
  718. * \pre @c U must be \CopyConstructible.
  719. * \pre @c Map is an MPL map with an entry for every
  720. * non-deduced placeholder referred to by @c Concept.
  721. * \pre @c @c T must map to @c U in @c Map.
  722. *
  723. * \throws std::bad_alloc or whatever that the copy
  724. * constructor of @c U throws.
  725. *
  726. * \note This constructor never matches if the argument is an @ref any.
  727. */
  728. template<class U, class Map>
  729. any(U&& data_arg, const static_binding<Map>& binding_arg)
  730. : table((
  731. BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
  732. binding_arg
  733. )),
  734. data(std::forward<U>(data_arg))
  735. {
  736. BOOST_MPL_ASSERT((::boost::is_same<
  737. typename ::boost::mpl::at<Map, T>::type, typename ::boost::remove_cv<typename ::boost::remove_reference<U>::type>::type>));
  738. }
  739. #endif
  740. // Handle array/function-to-pointer decay
  741. /** INTERNAL ONLY */
  742. template<class U>
  743. any(U* data_arg)
  744. : table((
  745. BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, U*),
  746. ::boost::type_erasure::make_binding<
  747. ::boost::mpl::map1< ::boost::mpl::pair<T, U*> >
  748. >()
  749. )),
  750. data(data_arg)
  751. {}
  752. /** INTERNAL ONLY */
  753. template<class U, class Map>
  754. any(U* data_arg, const static_binding<Map>& binding_arg)
  755. : table((
  756. BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
  757. binding_arg
  758. )),
  759. data(data_arg)
  760. {
  761. BOOST_MPL_ASSERT((::boost::is_same<
  762. typename ::boost::mpl::at<Map, T>::type, U*>));
  763. }
  764. /**
  765. * Copies an @ref any.
  766. *
  767. * \param other The object to make a copy of.
  768. *
  769. * \pre @c Concept must contain @ref constructible "constructible<T(const T&)>".
  770. * (This is included in @ref copy_constructible "copy_constructible<T>")
  771. *
  772. * \throws std::bad_alloc or whatever that the copy
  773. * constructor of the contained type throws.
  774. */
  775. any(const any& other)
  776. : table(other.table),
  777. data(::boost::type_erasure::call(constructible<T(const T&)>(), other))
  778. {}
  779. /**
  780. * Upcasts from an @ref any with stricter requirements to
  781. * an @ref any with weaker requirements.
  782. *
  783. * \param other The object to make a copy of.
  784. *
  785. * \pre @c Concept must contain @ref constructible "constructible<T(const T&)>".
  786. * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
  787. * \pre After substituting @c T for @c Tag2, the requirements of
  788. * @c Concept2 must be a superset of the requirements of
  789. * @c Concept.
  790. *
  791. * \throws std::bad_alloc or whatever that the copy
  792. * constructor of the contained type throws.
  793. */
  794. template<class Concept2, class Tag2>
  795. any(const any<Concept2, Tag2>& other)
  796. : table(
  797. ::boost::type_erasure::detail::access::table(other),
  798. ::boost::mpl::map1<
  799. ::boost::mpl::pair<
  800. T,
  801. typename ::boost::remove_const<
  802. typename ::boost::remove_reference<Tag2>::type
  803. >::type
  804. >
  805. >()
  806. ),
  807. data(::boost::type_erasure::call(
  808. constructible<
  809. typename ::boost::remove_const<
  810. typename boost::remove_reference<Tag2>::type
  811. >::type(const typename boost::remove_reference<Tag2>::type&)
  812. >(), other)
  813. )
  814. {}
  815. /**
  816. * Constructs an @ref any from another @ref any.
  817. *
  818. * \param other The object to make a copy of.
  819. * \param binding Specifies the mapping between the placeholders
  820. * used by the two concepts.
  821. *
  822. * \pre @c Concept must contain @ref constructible "constructible<T(const T&)>".
  823. * \pre @c Map must be an MPL map with keys for all the non-deduced
  824. * placeholders used by @c Concept and values for the corresponding
  825. * placeholders in @c Concept2.
  826. * \pre After substituting placeholders according to @c Map, the
  827. * requirements of @c Concept2 must be a superset of the
  828. * requirements of @c Concept.
  829. *
  830. * \throws std::bad_alloc or whatever that the copy
  831. * constructor of the contained type throws.
  832. */
  833. template<class Concept2, class Tag2, class Map>
  834. any(const any<Concept2, Tag2>& other, const static_binding<Map>& binding_arg)
  835. : table(::boost::type_erasure::detail::access::table(other), binding_arg),
  836. data(::boost::type_erasure::call(
  837. constructible<
  838. typename ::boost::remove_const<
  839. typename boost::remove_reference<Tag2>::type
  840. >::type(const typename boost::remove_reference<Tag2>::type&)
  841. >(), other)
  842. )
  843. {}
  844. /**
  845. * Constructs an @ref any from another @ref any.
  846. *
  847. * \param other The object to make a copy of.
  848. * \param binding Specifies the bindings of placeholders to actual types.
  849. *
  850. * \pre @c Concept must contain @ref constructible "constructible<T(const T&)>".
  851. * \pre The type stored in @c other must match the type expected by
  852. * @c binding.
  853. *
  854. * \post binding_of(*this) == @c binding
  855. *
  856. * \throws std::bad_alloc or whatever that the copy
  857. * constructor of the contained type throws.
  858. *
  859. * \warning This constructor is potentially dangerous, as it cannot
  860. * check at compile time whether the arguments match.
  861. */
  862. template<class Concept2, class Tag2>
  863. any(const any<Concept2, Tag2>& other, const binding<Concept>& binding_arg)
  864. : table(binding_arg),
  865. data(::boost::type_erasure::call(
  866. constructible<
  867. typename ::boost::remove_const<
  868. typename boost::remove_reference<Tag2>::type
  869. >::type(const typename boost::remove_reference<Tag2>::type&)
  870. >(), other)
  871. )
  872. {}
  873. #ifdef BOOST_TYPE_ERASURE_DOXYGEN
  874. /**
  875. * Calls a constructor of the contained type. The bindings
  876. * will be deduced from the arguments.
  877. *
  878. * \param arg The arguments to be passed to the underlying constructor.
  879. *
  880. * \pre @c Concept must contain an instance of @ref constructible which
  881. * can be called with these arguments.
  882. * \pre At least one of the arguments must by an @ref any with the
  883. * same @c Concept as this.
  884. * \pre The bindings of all the arguments that are @ref any's, must
  885. * be the same.
  886. *
  887. * \throws std::bad_alloc or whatever that the
  888. * constructor of the contained type throws.
  889. *
  890. * \note This constructor is never chosen if any other constructor
  891. * can be called instead.
  892. */
  893. template<class... U>
  894. explicit any(U&&... arg);
  895. /**
  896. * Calls a constructor of the contained type.
  897. *
  898. * \param binding Specifies the bindings of placeholders to actual types.
  899. * \param arg The arguments to be passed to the underlying constructor.
  900. *
  901. * \pre @c Concept must contain a matching instance of @ref constructible.
  902. * \pre The contained type of every argument that is an @ref any, must
  903. * be the same as that specified by @c binding.
  904. *
  905. * \post binding_of(*this) == @c binding
  906. *
  907. * \throws std::bad_alloc or whatever that the
  908. * constructor of the contained type throws.
  909. */
  910. template<class... U>
  911. explicit any(const binding<Concept>& binding_arg, U&&... arg)
  912. : table(binding_arg),
  913. data(
  914. ::boost::type_erasure::detail::make(
  915. false? this->_boost_type_erasure_deduce_constructor(arg...) : 0
  916. )(arg...)
  917. )
  918. {}
  919. #else
  920. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  921. any(any&& other)
  922. : table(::boost::type_erasure::detail::access::table(other)),
  923. data(::boost::type_erasure::call(
  924. ::boost::type_erasure::detail::make(
  925. false? this->_boost_type_erasure_deduce_constructor(std::move(other)) : 0
  926. ), std::move(other))
  927. )
  928. {}
  929. any(any& other)
  930. : table(::boost::type_erasure::detail::access::table(other)),
  931. data(::boost::type_erasure::call(
  932. ::boost::type_erasure::detail::make(
  933. false? this->_boost_type_erasure_deduce_constructor(other) : 0
  934. ), other)
  935. )
  936. {}
  937. template<class Concept2, class Tag2>
  938. any(any<Concept2, Tag2>& other)
  939. : table(
  940. ::boost::type_erasure::detail::access::table(other),
  941. ::boost::mpl::map1<
  942. ::boost::mpl::pair<
  943. T,
  944. typename ::boost::remove_const<
  945. typename ::boost::remove_reference<Tag2>::type
  946. >::type
  947. >
  948. >()
  949. ),
  950. data(::boost::type_erasure::call(
  951. ::boost::type_erasure::detail::make(
  952. false? other._boost_type_erasure_deduce_constructor(other) : 0
  953. ), other)
  954. )
  955. {}
  956. template<class Concept2, class Tag2>
  957. any(any<Concept2, Tag2>&& other)
  958. : table(
  959. ::boost::type_erasure::detail::access::table(other),
  960. ::boost::mpl::map1<
  961. ::boost::mpl::pair<
  962. T,
  963. typename ::boost::remove_const<
  964. typename ::boost::remove_reference<Tag2>::type
  965. >::type
  966. >
  967. >()
  968. ),
  969. data(::boost::type_erasure::call(
  970. ::boost::type_erasure::detail::make(
  971. false? other._boost_type_erasure_deduce_constructor(std::move(other)) : 0
  972. ), std::move(other))
  973. )
  974. {}
  975. #endif
  976. // construction from a reference
  977. any(const any<Concept, T&>& other)
  978. : table(::boost::type_erasure::detail::access::table(other)),
  979. data(::boost::type_erasure::call(
  980. ::boost::type_erasure::detail::make(
  981. false? this->_boost_type_erasure_deduce_constructor(other) : 0
  982. ), other)
  983. )
  984. {}
  985. any(any<Concept, T&>& other)
  986. : table(::boost::type_erasure::detail::access::table(other)),
  987. data(::boost::type_erasure::call(
  988. ::boost::type_erasure::detail::make(
  989. false? this->_boost_type_erasure_deduce_constructor(other) : 0
  990. ), other)
  991. )
  992. {}
  993. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  994. any(any<Concept, T&>&& other)
  995. : table(::boost::type_erasure::detail::access::table(other)),
  996. data(::boost::type_erasure::call(
  997. ::boost::type_erasure::detail::make(
  998. false? this->_boost_type_erasure_deduce_constructor(other) : 0
  999. ), other)
  1000. )
  1001. {}
  1002. #endif
  1003. any(const any<Concept, const T&>& other)
  1004. : table(::boost::type_erasure::detail::access::table(other)),
  1005. data(::boost::type_erasure::call(
  1006. ::boost::type_erasure::detail::make(
  1007. false? this->_boost_type_erasure_deduce_constructor(other) : 0
  1008. ), other)
  1009. )
  1010. {}
  1011. any(any<Concept, const T&>& other)
  1012. : table(::boost::type_erasure::detail::access::table(other)),
  1013. data(::boost::type_erasure::call(
  1014. ::boost::type_erasure::detail::make(
  1015. false? this->_boost_type_erasure_deduce_constructor(other) : 0
  1016. ), other)
  1017. )
  1018. {}
  1019. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  1020. any(any<Concept, const T&>&& other)
  1021. : table(::boost::type_erasure::detail::access::table(other)),
  1022. data(::boost::type_erasure::call(
  1023. ::boost::type_erasure::detail::make(
  1024. false? this->_boost_type_erasure_deduce_constructor(other) : 0
  1025. ), other)
  1026. )
  1027. {}
  1028. #endif
  1029. // disambiguating overloads
  1030. template<class U, class Map>
  1031. any(U* data_arg, static_binding<Map>& binding_arg)
  1032. : table((
  1033. BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
  1034. binding_arg
  1035. )),
  1036. data(data_arg)
  1037. {
  1038. BOOST_MPL_ASSERT((::boost::is_same<
  1039. typename ::boost::mpl::at<Map, T>::type, U*>));
  1040. }
  1041. #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
  1042. template<class U, class Map>
  1043. any(U& data_arg, static_binding<Map>& binding_arg)
  1044. : table((
  1045. BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
  1046. binding_arg
  1047. )),
  1048. data(data_arg)
  1049. {
  1050. BOOST_MPL_ASSERT((::boost::is_same<
  1051. typename ::boost::mpl::at<Map, T>::type, U>));
  1052. }
  1053. template<class U, class Map>
  1054. any(const U& data_arg, static_binding<Map>& binding_arg)
  1055. : table((
  1056. BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
  1057. binding_arg
  1058. )),
  1059. data(data_arg)
  1060. {
  1061. BOOST_MPL_ASSERT((::boost::is_same<
  1062. typename ::boost::mpl::at<Map, T>::type, U>));
  1063. }
  1064. template<class U, class Map>
  1065. any(U& data_arg, const static_binding<Map>& binding_arg)
  1066. : table((
  1067. BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
  1068. binding_arg
  1069. )),
  1070. data(data_arg)
  1071. {
  1072. BOOST_MPL_ASSERT((::boost::is_same<
  1073. typename ::boost::mpl::at<Map, T>::type, U>));
  1074. }
  1075. #endif
  1076. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  1077. template<class U, class Map>
  1078. any(U* data_arg, static_binding<Map>&& binding_arg)
  1079. : table((
  1080. BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
  1081. binding_arg
  1082. )),
  1083. data(data_arg)
  1084. {
  1085. BOOST_MPL_ASSERT((::boost::is_same<
  1086. typename ::boost::mpl::at<Map, T>::type, U*>));
  1087. }
  1088. template<class U, class Map>
  1089. any(U&& data_arg, static_binding<Map>& binding_arg)
  1090. : table((
  1091. BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
  1092. binding_arg
  1093. )),
  1094. data(data_arg)
  1095. {
  1096. BOOST_MPL_ASSERT((::boost::is_same<
  1097. typename ::boost::mpl::at<Map, T>::type, typename ::boost::remove_cv<typename ::boost::remove_reference<U>::type>::type>));
  1098. }
  1099. template<class U, class Map>
  1100. any(U&& data_arg, static_binding<Map>&& binding_arg)
  1101. : table((
  1102. BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
  1103. binding_arg
  1104. )),
  1105. data(data_arg)
  1106. {
  1107. BOOST_MPL_ASSERT((::boost::is_same<
  1108. typename ::boost::mpl::at<Map, T>::type, typename ::boost::remove_cv<typename ::boost::remove_reference<U>::type>::type>));
  1109. }
  1110. #endif
  1111. template<class Concept2, class Tag2, class Map>
  1112. any(any<Concept2, Tag2>& other, static_binding<Map>& binding_arg)
  1113. : table(::boost::type_erasure::detail::access::table(other), binding_arg),
  1114. data(::boost::type_erasure::call(
  1115. constructible<
  1116. typename ::boost::remove_const<
  1117. typename boost::remove_reference<Tag2>::type
  1118. >::type(const typename boost::remove_reference<Tag2>::type&)
  1119. >(), other)
  1120. )
  1121. {}
  1122. template<class Concept2, class Tag2, class Map>
  1123. any(any<Concept2, Tag2>& other, const static_binding<Map>& binding_arg)
  1124. : table(::boost::type_erasure::detail::access::table(other), binding_arg),
  1125. data(::boost::type_erasure::call(
  1126. constructible<
  1127. typename ::boost::remove_const<
  1128. typename boost::remove_reference<Tag2>::type
  1129. >::type(const typename boost::remove_reference<Tag2>::type&)
  1130. >(), other)
  1131. )
  1132. {}
  1133. template<class Concept2, class Tag2, class Map>
  1134. any(const any<Concept2, Tag2>& other, static_binding<Map>& binding_arg)
  1135. : table(::boost::type_erasure::detail::access::table(other), binding_arg),
  1136. data(::boost::type_erasure::call(
  1137. constructible<
  1138. typename ::boost::remove_const<
  1139. typename boost::remove_reference<Tag2>::type
  1140. >::type(const typename boost::remove_reference<Tag2>::type&)
  1141. >(), other)
  1142. )
  1143. {}
  1144. template<class Concept2, class Tag2>
  1145. any(any<Concept2, Tag2>& other, binding<Concept>& binding_arg)
  1146. : table(binding_arg),
  1147. data(::boost::type_erasure::call(
  1148. constructible<
  1149. typename ::boost::remove_const<
  1150. typename boost::remove_reference<Tag2>::type
  1151. >::type(const typename boost::remove_reference<Tag2>::type&)
  1152. >(), other)
  1153. )
  1154. {}
  1155. template<class Concept2, class Tag2>
  1156. any(any<Concept2, Tag2>& other, const binding<Concept>& binding_arg)
  1157. : table(binding_arg),
  1158. data(::boost::type_erasure::call(
  1159. constructible<
  1160. typename ::boost::remove_const<
  1161. typename boost::remove_reference<Tag2>::type
  1162. >::type(const typename boost::remove_reference<Tag2>::type&)
  1163. >(), other)
  1164. )
  1165. {}
  1166. template<class Concept2, class Tag2>
  1167. any(const any<Concept2, Tag2>& other, binding<Concept>& binding_arg)
  1168. : table(binding_arg),
  1169. data(::boost::type_erasure::call(
  1170. constructible<
  1171. typename ::boost::remove_const<
  1172. typename boost::remove_reference<Tag2>::type
  1173. >::type(const typename boost::remove_reference<Tag2>::type&)
  1174. >(), other)
  1175. )
  1176. {}
  1177. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  1178. template<class Concept2, class Tag2, class Map>
  1179. any(any<Concept2, Tag2>& other, static_binding<Map>&& binding_arg)
  1180. : table(::boost::type_erasure::detail::access::table(other), binding_arg),
  1181. data(::boost::type_erasure::call(
  1182. constructible<
  1183. typename ::boost::remove_const<
  1184. typename boost::remove_reference<Tag2>::type
  1185. >::type(const typename boost::remove_reference<Tag2>::type&)
  1186. >(), other)
  1187. )
  1188. {}
  1189. template<class Concept2, class Tag2, class Map>
  1190. any(const any<Concept2, Tag2>& other, static_binding<Map>&& binding_arg)
  1191. : table(::boost::type_erasure::detail::access::table(other), binding_arg),
  1192. data(::boost::type_erasure::call(
  1193. constructible<
  1194. typename ::boost::remove_const<
  1195. typename boost::remove_reference<Tag2>::type
  1196. >::type(const typename boost::remove_reference<Tag2>::type&)
  1197. >(), other)
  1198. )
  1199. {}
  1200. template<class Concept2, class Tag2, class Map>
  1201. any(any<Concept2, Tag2>&& other, static_binding<Map>&& binding_arg)
  1202. : table(::boost::type_erasure::detail::access::table(other), binding_arg),
  1203. data(::boost::type_erasure::call(
  1204. constructible<
  1205. typename ::boost::remove_const<
  1206. typename boost::remove_reference<Tag2>::type
  1207. >::type(const typename boost::remove_reference<Tag2>::type&)
  1208. >(), std::move(other))
  1209. )
  1210. {}
  1211. template<class Concept2, class Tag2, class Map>
  1212. any(any<Concept2, Tag2>&& other, static_binding<Map>& binding_arg)
  1213. : table(::boost::type_erasure::detail::access::table(other), binding_arg),
  1214. data(::boost::type_erasure::call(
  1215. constructible<
  1216. typename ::boost::remove_const<
  1217. typename boost::remove_reference<Tag2>::type
  1218. >::type(const typename boost::remove_reference<Tag2>::type&)
  1219. >(), std::move(other))
  1220. )
  1221. {}
  1222. template<class Concept2, class Tag2, class Map>
  1223. any(any<Concept2, Tag2>&& other, const static_binding<Map>& binding_arg)
  1224. : table(::boost::type_erasure::detail::access::table(other), binding_arg),
  1225. data(::boost::type_erasure::call(
  1226. constructible<
  1227. typename ::boost::remove_const<
  1228. typename boost::remove_reference<Tag2>::type
  1229. >::type(const typename boost::remove_reference<Tag2>::type&)
  1230. >(), std::move(other))
  1231. )
  1232. {}
  1233. template<class Concept2, class Tag2>
  1234. any(any<Concept2, Tag2>& other, binding<Concept>&& binding_arg)
  1235. : table(binding_arg),
  1236. data(::boost::type_erasure::call(
  1237. constructible<
  1238. typename ::boost::remove_const<
  1239. typename boost::remove_reference<Tag2>::type
  1240. >::type(const typename boost::remove_reference<Tag2>::type&)
  1241. >(), other)
  1242. )
  1243. {}
  1244. template<class Concept2, class Tag2>
  1245. any(const any<Concept2, Tag2>& other, binding<Concept>&& binding_arg)
  1246. : table(binding_arg),
  1247. data(::boost::type_erasure::call(
  1248. constructible<
  1249. typename ::boost::remove_const<
  1250. typename boost::remove_reference<Tag2>::type
  1251. >::type(const typename boost::remove_reference<Tag2>::type&)
  1252. >(), other)
  1253. )
  1254. {}
  1255. template<class Concept2, class Tag2>
  1256. any(any<Concept2, Tag2>&& other, binding<Concept>&& binding_arg)
  1257. : table(binding_arg),
  1258. data(::boost::type_erasure::call(
  1259. constructible<
  1260. typename ::boost::remove_const<
  1261. typename boost::remove_reference<Tag2>::type
  1262. >::type(const typename boost::remove_reference<Tag2>::type&)
  1263. >(), std::move(other))
  1264. )
  1265. {}
  1266. template<class Concept2, class Tag2>
  1267. any(any<Concept2, Tag2>&& other, binding<Concept>& binding_arg)
  1268. : table(binding_arg),
  1269. data(::boost::type_erasure::call(
  1270. constructible<
  1271. typename ::boost::remove_const<
  1272. typename boost::remove_reference<Tag2>::type
  1273. >::type(const typename boost::remove_reference<Tag2>::type&)
  1274. >(), std::move(other))
  1275. )
  1276. {}
  1277. template<class Concept2, class Tag2>
  1278. any(any<Concept2, Tag2>&& other, const binding<Concept>& binding_arg)
  1279. : table(binding_arg),
  1280. data(::boost::type_erasure::call(
  1281. constructible<
  1282. typename ::boost::remove_const<
  1283. typename boost::remove_reference<Tag2>::type
  1284. >::type(const typename boost::remove_reference<Tag2>::type&)
  1285. >(), std::move(other))
  1286. )
  1287. {}
  1288. #endif
  1289. // One argument is a special case. The argument must be an any
  1290. // and the constructor must be explicit.
  1291. template<class Tag2>
  1292. explicit any(const any<Concept, Tag2>& other)
  1293. : table(::boost::type_erasure::detail::access::table(other)),
  1294. data(::boost::type_erasure::call(
  1295. ::boost::type_erasure::detail::make(
  1296. false? this->_boost_type_erasure_deduce_constructor(other) : 0
  1297. ), other)
  1298. )
  1299. {}
  1300. template<class Tag2>
  1301. explicit any(any<Concept, Tag2>& other)
  1302. : table(::boost::type_erasure::detail::access::table(other)),
  1303. data(::boost::type_erasure::call(
  1304. ::boost::type_erasure::detail::make(
  1305. false? this->_boost_type_erasure_deduce_constructor(other) : 0
  1306. ), other)
  1307. )
  1308. {}
  1309. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  1310. template<class Tag2>
  1311. explicit any(any<Concept, Tag2>&& other)
  1312. : table(::boost::type_erasure::detail::access::table(other)),
  1313. data(::boost::type_erasure::call(
  1314. ::boost::type_erasure::detail::make(
  1315. false? this->_boost_type_erasure_deduce_constructor(std::move(other)) : 0
  1316. ), std::move(other))
  1317. )
  1318. {}
  1319. #endif
  1320. explicit any(const binding<Concept>& binding_arg)
  1321. : table(binding_arg),
  1322. data(
  1323. ::boost::type_erasure::call(
  1324. binding_arg,
  1325. ::boost::type_erasure::constructible<T()>()
  1326. )
  1327. )
  1328. {}
  1329. explicit any(binding<Concept>& binding_arg)
  1330. : table(binding_arg),
  1331. data(
  1332. ::boost::type_erasure::call(
  1333. binding_arg,
  1334. ::boost::type_erasure::constructible<T()>()
  1335. )
  1336. )
  1337. {}
  1338. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  1339. explicit any(binding<Concept>&& binding_arg)
  1340. : table(binding_arg),
  1341. data(
  1342. ::boost::type_erasure::call(
  1343. binding_arg,
  1344. ::boost::type_erasure::constructible<T()>()
  1345. )
  1346. )
  1347. {}
  1348. #endif
  1349. #if !defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES) && !defined(BOOST_NO_CXX11_RVALUE_REFERENCES)
  1350. template<class R, class... A, class... U>
  1351. const table_type& _boost_type_erasure_extract_table(
  1352. ::boost::type_erasure::constructible<R(A...)>*,
  1353. U&&... u)
  1354. {
  1355. return *::boost::type_erasure::detail::extract_table(static_cast<void(*)(A...)>(0), u...);
  1356. }
  1357. template<class U0, class U1, class... U>
  1358. any(U0&& u0, U1&& u1, U&&... u)
  1359. : table(
  1360. _boost_type_erasure_extract_table(
  1361. false? this->_boost_type_erasure_deduce_constructor(std::forward<U0>(u0), std::forward<U1>(u1), std::forward<U>(u)...) : 0,
  1362. std::forward<U0>(u0), std::forward<U1>(u1), std::forward<U>(u)...
  1363. )
  1364. ),
  1365. data(
  1366. ::boost::type_erasure::call(
  1367. ::boost::type_erasure::detail::make(
  1368. false? this->_boost_type_erasure_deduce_constructor(std::forward<U0>(u0), std::forward<U1>(u1), std::forward<U>(u)...) : 0
  1369. ),
  1370. std::forward<U0>(u0), std::forward<U1>(u1), std::forward<U>(u)...
  1371. )
  1372. )
  1373. {}
  1374. template<class U0, class... U>
  1375. any(const binding<Concept>& binding_arg, U0&& u0, U&&... u)
  1376. : table(binding_arg),
  1377. data(
  1378. ::boost::type_erasure::call(
  1379. binding_arg,
  1380. ::boost::type_erasure::detail::make(
  1381. false? this->_boost_type_erasure_deduce_constructor(std::forward<U0>(u0), std::forward<U>(u)...) : 0
  1382. ),
  1383. std::forward<U0>(u0), std::forward<U>(u)...
  1384. )
  1385. )
  1386. {}
  1387. // disambiguating overloads
  1388. template<class U0, class... U>
  1389. any(binding<Concept>& binding_arg, U0&& u0, U&&... u)
  1390. : table(binding_arg),
  1391. data(
  1392. ::boost::type_erasure::call(
  1393. binding_arg,
  1394. ::boost::type_erasure::detail::make(
  1395. false? this->_boost_type_erasure_deduce_constructor(std::forward<U0>(u0), std::forward<U>(u)...) : 0
  1396. ),
  1397. std::forward<U0>(u0), std::forward<U>(u)...
  1398. )
  1399. )
  1400. {}
  1401. template<class U0, class... U>
  1402. any(binding<Concept>&& binding_arg, U0&& u0, U&&... u)
  1403. : table(binding_arg),
  1404. data(
  1405. ::boost::type_erasure::call(
  1406. binding_arg,
  1407. ::boost::type_erasure::detail::make(
  1408. false? this->_boost_type_erasure_deduce_constructor(std::forward<U0>(u0), std::forward<U>(u)...) : 0
  1409. ),
  1410. std::forward<U0>(u0), std::forward<U>(u)...
  1411. )
  1412. )
  1413. {}
  1414. #else
  1415. #include <boost/type_erasure/detail/construct.hpp>
  1416. #endif
  1417. #endif
  1418. /** INTERNAL ONLY */
  1419. any& operator=(const any& other)
  1420. {
  1421. _boost_type_erasure_resolve_assign(other);
  1422. return *this;
  1423. }
  1424. /** INTERNAL ONLY */
  1425. any& operator=(any& other)
  1426. {
  1427. _boost_type_erasure_resolve_assign(other);
  1428. return *this;
  1429. }
  1430. #endif // BOOST_TYPE_ERASURE_SFINAE_FRIENDLY_CONSTRUCTORS
  1431. #ifdef BOOST_NO_CXX11_RVALUE_REFERENCES
  1432. template<class U>
  1433. any& operator=(U& other)
  1434. {
  1435. _boost_type_erasure_resolve_assign(other);
  1436. return *this;
  1437. }
  1438. template<class U>
  1439. any& operator=(const U& other)
  1440. {
  1441. _boost_type_erasure_resolve_assign(other);
  1442. return *this;
  1443. }
  1444. #else
  1445. #ifndef BOOST_TYPE_ERASURE_SFINAE_FRIENDLY_CONSTRUCTORS
  1446. /** INTERNAL ONLY */
  1447. any& operator=(any&& other)
  1448. {
  1449. _boost_type_erasure_resolve_assign(std::move(other));
  1450. return *this;
  1451. }
  1452. #endif
  1453. /**
  1454. * Assigns to an @ref any.
  1455. *
  1456. * If an appropriate overload of @ref assignable is not available
  1457. * and @ref relaxed is in @c Concept, falls back on
  1458. * constructing from @c other.
  1459. *
  1460. * \note If @c U is an @ref any, then this can decide dynamically
  1461. * whether to use construction based on the type stored in other.
  1462. *
  1463. * \throws Whatever the assignment operator of the contained
  1464. * type throws. When falling back on construction,
  1465. * throws @c std::bad_alloc or whatever the move (or copy)
  1466. * constructor of the contained type throws. In
  1467. * this case move assignment provides the strong exception
  1468. * guarantee. When calling a (move) assignment operator
  1469. * of the contained type, the exception guarantee is
  1470. * whatever the contained type provides.
  1471. */
  1472. template<class U>
  1473. any& operator=(U&& other)
  1474. {
  1475. _boost_type_erasure_resolve_assign(std::forward<U>(other));
  1476. return *this;
  1477. }
  1478. #endif
  1479. #ifndef BOOST_TYPE_ERASURE_SFINAE_FRIENDLY_CONSTRUCTORS
  1480. /**
  1481. * \pre @c Concept includes @ref destructible "destructible<T>".
  1482. */
  1483. ~any()
  1484. {
  1485. ::boost::type_erasure::detail::access::table(*this).template find<
  1486. ::boost::type_erasure::destructible<T>
  1487. >()(::boost::type_erasure::detail::access::data(*this));
  1488. }
  1489. #endif
  1490. #ifndef BOOST_NO_CXX11_REF_QUALIFIERS
  1491. /** INTERNAL ONLY */
  1492. operator param<Concept, T&>() &
  1493. {
  1494. return param<Concept, T&>(
  1495. boost::type_erasure::detail::access::data(*this),
  1496. boost::type_erasure::detail::access::table(*this));
  1497. }
  1498. /** INTERNAL ONLY */
  1499. operator param<Concept, T&&>() && {
  1500. return param<Concept, T&&>(
  1501. boost::type_erasure::detail::access::data(*this),
  1502. boost::type_erasure::detail::access::table(*this));
  1503. }
  1504. #endif
  1505. private:
  1506. #ifndef BOOST_TYPE_ERASURE_SFINAE_FRIENDLY_CONSTRUCTORS
  1507. /** INTERNAL ONLY */
  1508. void _boost_type_erasure_swap(any& other)
  1509. {
  1510. ::std::swap(data, other.data);
  1511. ::std::swap(table, other.table);
  1512. }
  1513. #else
  1514. void _boost_type_erasure_swap(any& other)
  1515. {
  1516. ::std::swap(this->_boost_type_erasure_data, other._boost_type_erasure_data);
  1517. ::std::swap(this->_boost_type_erasure_table, other._boost_type_erasure_table);
  1518. }
  1519. #endif
  1520. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  1521. /** INTERNAL ONLY */
  1522. template<class Other>
  1523. void _boost_type_erasure_resolve_assign(Other&& other)
  1524. {
  1525. _boost_type_erasure_assign_impl(
  1526. std::forward<Other>(other),
  1527. false? this->_boost_type_erasure_deduce_assign(
  1528. ::boost::type_erasure::detail::make_fallback(
  1529. std::forward<Other>(other),
  1530. ::boost::mpl::bool_<
  1531. sizeof(
  1532. ::boost::type_erasure::detail::check_overload(
  1533. ::boost::declval<any&>().
  1534. _boost_type_erasure_deduce_assign(std::forward<Other>(other))
  1535. )
  1536. ) == sizeof(::boost::type_erasure::detail::yes)
  1537. >()
  1538. )
  1539. ) : 0,
  1540. ::boost::type_erasure::is_relaxed<Concept>()
  1541. );
  1542. }
  1543. /** INTERNAL ONLY */
  1544. template<class Other, class U>
  1545. void _boost_type_erasure_assign_impl(
  1546. Other&& other,
  1547. const assignable<T, U>*,
  1548. ::boost::mpl::false_)
  1549. {
  1550. ::boost::type_erasure::call(assignable<T, U>(), *this, std::forward<Other>(other));
  1551. }
  1552. /** INTERNAL ONLY */
  1553. template<class Other, class U>
  1554. void _boost_type_erasure_assign_impl(
  1555. Other&& other,
  1556. const assignable<T, U>*,
  1557. ::boost::mpl::true_)
  1558. {
  1559. ::boost::type_erasure::call(assignable<T, U>(), *this, std::forward<Other>(other));
  1560. }
  1561. /** INTERNAL ONLY */
  1562. template<class Other>
  1563. void _boost_type_erasure_assign_impl(
  1564. Other&& other,
  1565. const void*,
  1566. ::boost::mpl::true_)
  1567. {
  1568. any temp(std::forward<Other>(other));
  1569. _boost_type_erasure_swap(temp);
  1570. }
  1571. #else
  1572. /** INTERNAL ONLY */
  1573. template<class Other>
  1574. void _boost_type_erasure_resolve_assign(Other& other)
  1575. {
  1576. _boost_type_erasure_assign_impl(
  1577. other,
  1578. false? this->_boost_type_erasure_deduce_assign(
  1579. ::boost::type_erasure::detail::make_fallback(
  1580. other,
  1581. ::boost::mpl::bool_<
  1582. sizeof(
  1583. ::boost::type_erasure::detail::check_overload(
  1584. ::boost::declval<any&>().
  1585. _boost_type_erasure_deduce_assign(other)
  1586. )
  1587. ) == sizeof(::boost::type_erasure::detail::yes)
  1588. >()
  1589. )
  1590. ) : 0,
  1591. ::boost::type_erasure::is_relaxed<Concept>()
  1592. );
  1593. }
  1594. /** INTERNAL ONLY */
  1595. template<class Other, class U>
  1596. void _boost_type_erasure_assign_impl(
  1597. Other& other,
  1598. const assignable<T, U>*,
  1599. ::boost::mpl::false_)
  1600. {
  1601. ::boost::type_erasure::call(assignable<T, U>(), *this, other);
  1602. }
  1603. /** INTERNAL ONLY */
  1604. template<class Other, class U>
  1605. void _boost_type_erasure_assign_impl(
  1606. Other& other,
  1607. const assignable<T, U>*,
  1608. ::boost::mpl::true_)
  1609. {
  1610. ::boost::type_erasure::call(assignable<T, U>(), *this, other);
  1611. }
  1612. /** INTERNAL ONLY */
  1613. template<class Other>
  1614. void _boost_type_erasure_assign_impl(
  1615. Other& other,
  1616. const void*,
  1617. ::boost::mpl::true_)
  1618. {
  1619. any temp(other);
  1620. _boost_type_erasure_swap(temp);
  1621. }
  1622. #endif
  1623. /** INTERNAL ONLY */
  1624. template<class Concept2, class Tag2>
  1625. void _boost_type_erasure_resolve_assign(const any<Concept2, Tag2>& other)
  1626. {
  1627. _boost_type_erasure_resolve_assign_any(other);
  1628. }
  1629. /** INTERNAL ONLY */
  1630. template<class Concept2, class Tag2>
  1631. void _boost_type_erasure_resolve_assign(any<Concept2, Tag2>& other)
  1632. {
  1633. _boost_type_erasure_resolve_assign_any(other);
  1634. }
  1635. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  1636. /** INTERNAL ONLY */
  1637. template<class Concept2, class Tag2>
  1638. void _boost_type_erasure_resolve_assign(any<Concept2, Tag2>&& other)
  1639. {
  1640. _boost_type_erasure_resolve_assign_any(std::move(other));
  1641. }
  1642. /** INTERNAL ONLY */
  1643. template<class Other>
  1644. void _boost_type_erasure_resolve_assign_any(Other&& other)
  1645. {
  1646. _boost_type_erasure_assign_impl(
  1647. std::forward<Other>(other),
  1648. false? this->_boost_type_erasure_deduce_assign(
  1649. ::boost::type_erasure::detail::make_fallback(
  1650. std::forward<Other>(other),
  1651. ::boost::mpl::bool_<
  1652. sizeof(
  1653. ::boost::type_erasure::detail::check_overload(
  1654. ::boost::declval<any&>().
  1655. _boost_type_erasure_deduce_assign(std::forward<Other>(other))
  1656. )
  1657. ) == sizeof(::boost::type_erasure::detail::yes)
  1658. >()
  1659. )
  1660. ) : 0,
  1661. false? this->_boost_type_erasure_deduce_constructor(
  1662. ::boost::type_erasure::detail::make_fallback(
  1663. std::forward<Other>(other),
  1664. ::boost::mpl::bool_<
  1665. sizeof(
  1666. ::boost::type_erasure::detail::check_overload(
  1667. ::boost::declval<any&>().
  1668. _boost_type_erasure_deduce_constructor(std::forward<Other>(other))
  1669. )
  1670. ) == sizeof(::boost::type_erasure::detail::yes)
  1671. >()
  1672. )
  1673. ) : 0,
  1674. ::boost::type_erasure::is_relaxed<Concept>()
  1675. );
  1676. }
  1677. /** INTERNAL ONLY */
  1678. template<class Other, class U>
  1679. void _boost_type_erasure_assign_impl(
  1680. Other&& other,
  1681. const assignable<T, U>*,
  1682. const void*,
  1683. ::boost::mpl::false_)
  1684. {
  1685. ::boost::type_erasure::call(assignable<T, U>(), *this, std::forward<Other>(other));
  1686. }
  1687. /** INTERNAL ONLY */
  1688. template<class Other, class U>
  1689. void _boost_type_erasure_assign_impl(
  1690. Other&& other,
  1691. const assignable<T, U>*,
  1692. const void*,
  1693. ::boost::mpl::true_)
  1694. {
  1695. ::boost::type_erasure::call(assignable<T, U>(), *this, std::forward<Other>(other));
  1696. }
  1697. /** INTERNAL ONLY */
  1698. template<class Other, class Sig>
  1699. void _boost_type_erasure_assign_impl(
  1700. Other&& other,
  1701. const void*,
  1702. const constructible<Sig>*,
  1703. ::boost::mpl::true_)
  1704. {
  1705. any temp(std::forward<Other>(other));
  1706. _boost_type_erasure_swap(temp);
  1707. }
  1708. /** INTERNAL ONLY */
  1709. template<class Other, class U, class Sig>
  1710. void _boost_type_erasure_assign_impl(
  1711. Other&& other,
  1712. const assignable<T, U>*,
  1713. const constructible<Sig>*,
  1714. ::boost::mpl::true_)
  1715. {
  1716. if(::boost::type_erasure::check_match(assignable<T, U>(), *this, other)) // const reference to other is enough!
  1717. {
  1718. ::boost::type_erasure::unchecked_call(assignable<T, U>(), *this, std::forward<Other>(other));
  1719. }
  1720. else
  1721. {
  1722. any temp(std::forward<Other>(other));
  1723. _boost_type_erasure_swap(temp);
  1724. }
  1725. }
  1726. #else
  1727. /** INTERNAL ONLY */
  1728. template<class Other>
  1729. void _boost_type_erasure_resolve_assign_any(Other& other)
  1730. {
  1731. _boost_type_erasure_assign_impl(
  1732. other,
  1733. false? this->_boost_type_erasure_deduce_assign(
  1734. ::boost::type_erasure::detail::make_fallback(
  1735. other,
  1736. ::boost::mpl::bool_<
  1737. sizeof(
  1738. ::boost::type_erasure::detail::check_overload(
  1739. ::boost::declval<any&>().
  1740. _boost_type_erasure_deduce_assign(other)
  1741. )
  1742. ) == sizeof(::boost::type_erasure::detail::yes)
  1743. >()
  1744. )
  1745. ) : 0,
  1746. false? this->_boost_type_erasure_deduce_constructor(
  1747. ::boost::type_erasure::detail::make_fallback(
  1748. other,
  1749. ::boost::mpl::bool_<
  1750. sizeof(
  1751. ::boost::type_erasure::detail::check_overload(
  1752. ::boost::declval<any&>().
  1753. _boost_type_erasure_deduce_constructor(other)
  1754. )
  1755. ) == sizeof(::boost::type_erasure::detail::yes)
  1756. >()
  1757. )
  1758. ) : 0,
  1759. ::boost::type_erasure::is_relaxed<Concept>()
  1760. );
  1761. }
  1762. /** INTERNAL ONLY */
  1763. template<class Other, class U>
  1764. void _boost_type_erasure_assign_impl(
  1765. Other& other,
  1766. const assignable<T, U>*,
  1767. const void*,
  1768. ::boost::mpl::false_)
  1769. {
  1770. ::boost::type_erasure::call(assignable<T, U>(), *this, other);
  1771. }
  1772. /** INTERNAL ONLY */
  1773. template<class Other, class U>
  1774. void _boost_type_erasure_assign_impl(
  1775. Other& other,
  1776. const assignable<T, U>*,
  1777. const void*,
  1778. ::boost::mpl::true_)
  1779. {
  1780. ::boost::type_erasure::call(assignable<T, U>(), *this, other);
  1781. }
  1782. /** INTERNAL ONLY */
  1783. template<class Other, class Sig>
  1784. void _boost_type_erasure_assign_impl(
  1785. Other& other,
  1786. const void*,
  1787. const constructible<Sig>*,
  1788. ::boost::mpl::true_)
  1789. {
  1790. any temp(other);
  1791. _boost_type_erasure_swap(temp);
  1792. }
  1793. /** INTERNAL ONLY */
  1794. template<class Other, class U, class Sig>
  1795. void _boost_type_erasure_assign_impl(
  1796. Other& other,
  1797. const assignable<T, U>*,
  1798. const constructible<Sig>*,
  1799. ::boost::mpl::true_)
  1800. {
  1801. if(::boost::type_erasure::check_match(assignable<T, U>(), *this, other))
  1802. {
  1803. ::boost::type_erasure::unchecked_call(assignable<T, U>(), *this, other);
  1804. }
  1805. else
  1806. {
  1807. any temp(other);
  1808. _boost_type_erasure_swap(temp);
  1809. }
  1810. }
  1811. #endif
  1812. friend struct ::boost::type_erasure::detail::access;
  1813. #ifndef BOOST_TYPE_ERASURE_SFINAE_FRIENDLY_CONSTRUCTORS
  1814. // The table has to be initialized first for exception
  1815. // safety in some constructors.
  1816. table_type table;
  1817. ::boost::type_erasure::detail::storage data;
  1818. #else
  1819. template<class Concept2, class T2>
  1820. friend struct ::boost::type_erasure::any_constructor_impl;
  1821. #endif
  1822. };
  1823. template<class Concept, class T>
  1824. class any<Concept, T&> :
  1825. public ::boost::type_erasure::detail::compute_bases<
  1826. ::boost::type_erasure::any<Concept, T&>,
  1827. Concept,
  1828. T
  1829. >::type
  1830. {
  1831. typedef ::boost::type_erasure::binding<Concept> table_type;
  1832. public:
  1833. /** INTERNAL ONLY */
  1834. typedef Concept _boost_type_erasure_concept_type;
  1835. /** INTERNAL ONLY */
  1836. any(const ::boost::type_erasure::detail::storage& data_arg,
  1837. const table_type& table_arg)
  1838. : data(data_arg),
  1839. table(table_arg)
  1840. {}
  1841. /**
  1842. * Constructs an @ref any from a reference.
  1843. *
  1844. * \param arg The object to bind the reference to.
  1845. *
  1846. * \pre @c U is a model of @c Concept.
  1847. * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
  1848. *
  1849. * \throws Nothing.
  1850. */
  1851. template<class U>
  1852. any(U& arg
  1853. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  1854. , typename ::boost::disable_if<
  1855. ::boost::mpl::or_<
  1856. ::boost::is_const<U>,
  1857. ::boost::type_erasure::detail::is_any<U>
  1858. >
  1859. >::type* = 0
  1860. #endif
  1861. )
  1862. : table((
  1863. BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, U),
  1864. ::boost::type_erasure::make_binding<
  1865. ::boost::mpl::map1< ::boost::mpl::pair<T, U> >
  1866. >()
  1867. ))
  1868. {
  1869. data.data = ::boost::addressof(arg);
  1870. }
  1871. /**
  1872. * Constructs an @ref any from a reference.
  1873. *
  1874. * \param arg The object to bind the reference to.
  1875. * \param binding Specifies the actual types that
  1876. * all the placeholders should bind to.
  1877. *
  1878. * \pre @c U is a model of @c Concept.
  1879. * \pre @c Map is an MPL map with an entry for every
  1880. * non-deduced placeholder referred to by @c Concept.
  1881. *
  1882. * \throws Nothing.
  1883. */
  1884. template<class U, class Map>
  1885. any(U& arg, const static_binding<Map>& binding_arg)
  1886. : table((
  1887. BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
  1888. binding_arg
  1889. ))
  1890. {
  1891. BOOST_MPL_ASSERT((::boost::is_same<
  1892. typename ::boost::mpl::at<Map, T>::type, U>));
  1893. data.data = ::boost::addressof(arg);
  1894. }
  1895. /**
  1896. * Constructs an @ref any from another reference.
  1897. *
  1898. * \param other The reference to copy.
  1899. *
  1900. * \throws Nothing.
  1901. */
  1902. any(const any& other)
  1903. : data(other.data),
  1904. table(other.table)
  1905. {}
  1906. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  1907. any(any& other)
  1908. : data(other.data),
  1909. table(other.table)
  1910. {}
  1911. #endif
  1912. /**
  1913. * Constructs an @ref any from another @ref any.
  1914. *
  1915. * \param other The object to bind the reference to.
  1916. *
  1917. * \throws Nothing.
  1918. */
  1919. any(any<Concept, T>& other)
  1920. : data(::boost::type_erasure::detail::access::data(other)),
  1921. table(::boost::type_erasure::detail::access::table(other))
  1922. {}
  1923. /**
  1924. * Constructs an @ref any from another reference.
  1925. *
  1926. * \param other The reference to copy.
  1927. *
  1928. * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
  1929. * \pre After substituting @c T for @c Tag2, the requirements of
  1930. * @c Concept2 must be a superset of the requirements of
  1931. * @c Concept.
  1932. *
  1933. * \throws std::bad_alloc
  1934. */
  1935. template<class Concept2, class Tag2>
  1936. any(const any<Concept2, Tag2&>& other
  1937. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  1938. , typename ::boost::disable_if<
  1939. ::boost::mpl::or_<
  1940. ::boost::is_same<Concept, Concept2>,
  1941. ::boost::is_const<Tag2>
  1942. >
  1943. >::type* = 0
  1944. #endif
  1945. )
  1946. : data(::boost::type_erasure::detail::access::data(other)),
  1947. table(
  1948. ::boost::type_erasure::detail::access::table(other),
  1949. ::boost::mpl::map1<
  1950. ::boost::mpl::pair<
  1951. T,
  1952. Tag2
  1953. >
  1954. >())
  1955. {}
  1956. /**
  1957. * Constructs an @ref any from another @ref any.
  1958. *
  1959. * \param other The object to bind the reference to.
  1960. *
  1961. * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
  1962. * \pre After substituting @c T for @c Tag2, the requirements of
  1963. * @c Concept2 must be a superset of the requirements of
  1964. * @c Concept.
  1965. *
  1966. * \throws std::bad_alloc
  1967. */
  1968. template<class Concept2, class Tag2>
  1969. any(any<Concept2, Tag2>& other
  1970. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  1971. , typename ::boost::disable_if<
  1972. ::boost::mpl::or_<
  1973. ::boost::is_same<Concept, Concept2>,
  1974. ::boost::is_const<typename ::boost::remove_reference<Tag2>::type>
  1975. >
  1976. >::type* = 0
  1977. #endif
  1978. )
  1979. : data(::boost::type_erasure::detail::access::data(other)),
  1980. table(
  1981. ::boost::type_erasure::detail::access::table(other),
  1982. ::boost::mpl::map1<
  1983. ::boost::mpl::pair<
  1984. T,
  1985. typename ::boost::remove_reference<Tag2>::type
  1986. >
  1987. >())
  1988. {}
  1989. /**
  1990. * Constructs an @ref any from another reference.
  1991. *
  1992. * \param other The reference to copy.
  1993. * \param binding Specifies the mapping between the two concepts.
  1994. *
  1995. * \pre @c Map must be an MPL map with keys for all the non-deduced
  1996. * placeholders used by @c Concept and values for the corresponding
  1997. * placeholders in @c Concept2.
  1998. * \pre After substituting placeholders according to @c Map, the
  1999. * requirements of @c Concept2 must be a superset of the
  2000. * requirements of @c Concept.
  2001. *
  2002. * \throws std::bad_alloc
  2003. */
  2004. template<class Concept2, class Tag2, class Map>
  2005. any(const any<Concept2, Tag2&>& other, const static_binding<Map>& binding_arg
  2006. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  2007. , typename ::boost::disable_if< ::boost::is_const<Tag2> >::type* = 0
  2008. #endif
  2009. )
  2010. : data(::boost::type_erasure::detail::access::data(other)),
  2011. table(::boost::type_erasure::detail::access::table(other), binding_arg)
  2012. {}
  2013. /**
  2014. * Constructs an @ref any from another @ref any.
  2015. *
  2016. * \param other The object to bind the reference to.
  2017. * \param binding Specifies the mapping between the two concepts.
  2018. *
  2019. * \pre @c Map must be an MPL map with keys for all the non-deduced
  2020. * placeholders used by @c Concept and values for the corresponding
  2021. * placeholders in @c Concept2.
  2022. * \pre After substituting placeholders according to @c Map, the
  2023. * requirements of @c Concept2 must be a superset of the
  2024. * requirements of @c Concept.
  2025. *
  2026. * \throws std::bad_alloc
  2027. */
  2028. template<class Concept2, class Tag2, class Map>
  2029. any(any<Concept2, Tag2>& other, const static_binding<Map>& binding_arg
  2030. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  2031. , typename ::boost::disable_if<
  2032. ::boost::is_const<typename ::boost::remove_reference<Tag2>::type>
  2033. >::type* = 0
  2034. #endif
  2035. )
  2036. : data(::boost::type_erasure::detail::access::data(other)),
  2037. table(::boost::type_erasure::detail::access::table(other), binding_arg)
  2038. {}
  2039. /**
  2040. * Constructs an @ref any from another reference.
  2041. *
  2042. * \param other The reference to copy.
  2043. * \param binding Specifies the bindings of placeholders to actual types.
  2044. *
  2045. * \pre The type stored in @c other must match the type expected by
  2046. * @c binding.
  2047. *
  2048. * \post binding_of(*this) == @c binding
  2049. *
  2050. * \throws Nothing.
  2051. */
  2052. template<class Concept2, class Tag2>
  2053. any(const any<Concept2, Tag2&>& other, const binding<Concept>& binding_arg
  2054. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  2055. , typename ::boost::disable_if<
  2056. ::boost::is_const<Tag2>
  2057. >::type* = 0
  2058. #endif
  2059. )
  2060. : data(::boost::type_erasure::detail::access::data(other)),
  2061. table(binding_arg)
  2062. {}
  2063. /**
  2064. * Constructs an @ref any from another @ref any.
  2065. *
  2066. * \param other The object to bind the reference to.
  2067. * \param binding Specifies the bindings of placeholders to actual types.
  2068. *
  2069. * \pre The type stored in @c other must match the type expected by
  2070. * @c binding.
  2071. *
  2072. * \post binding_of(*this) == @c binding
  2073. *
  2074. * \throws Nothing.
  2075. */
  2076. template<class Concept2, class Tag2>
  2077. any(any<Concept2, Tag2>& other, const binding<Concept>& binding_arg
  2078. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  2079. , typename ::boost::disable_if<
  2080. ::boost::is_const<typename ::boost::remove_reference<Tag2>::type>
  2081. >::type* = 0
  2082. #endif
  2083. )
  2084. : data(::boost::type_erasure::detail::access::data(other)),
  2085. table(binding_arg)
  2086. {}
  2087. /** INTERNAL ONLY */
  2088. any& operator=(const any& other)
  2089. {
  2090. _boost_type_erasure_resolve_assign(other);
  2091. return *this;
  2092. }
  2093. /** INTERNAL ONLY */
  2094. any& operator=(any& other)
  2095. {
  2096. _boost_type_erasure_resolve_assign(other);
  2097. return *this;
  2098. }
  2099. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  2100. /** INTERNAL ONLY */
  2101. any& operator=(any&& other)
  2102. {
  2103. _boost_type_erasure_resolve_assign(std::move(other));
  2104. return *this;
  2105. }
  2106. /**
  2107. * Assigns to an @ref any.
  2108. *
  2109. * If an appropriate overload of @ref assignable is not available
  2110. * and @ref relaxed is in @c Concept, falls back on
  2111. * constructing from @c other.
  2112. *
  2113. * \throws Whatever the assignment operator of the contained
  2114. * type throws. When falling back on construction,
  2115. * can only throw @c std::bad_alloc if @c U is an @ref any
  2116. * that uses a different @c Concept. In this case assignment
  2117. * provides the strong exception guarantee. When
  2118. * calling the assignment operator of the contained type,
  2119. * the exception guarantee is whatever the contained type provides.
  2120. */
  2121. template<class U>
  2122. any& operator=(U&& other)
  2123. {
  2124. _boost_type_erasure_resolve_assign(std::forward<U>(other));
  2125. return *this;
  2126. }
  2127. #else
  2128. template<class U>
  2129. any& operator=(U& other)
  2130. {
  2131. _boost_type_erasure_resolve_assign(other);
  2132. return *this;
  2133. }
  2134. template<class U>
  2135. any& operator=(const U& other)
  2136. {
  2137. _boost_type_erasure_resolve_assign(other);
  2138. return *this;
  2139. }
  2140. #endif
  2141. #ifndef BOOST_NO_CXX11_REF_QUALIFIERS
  2142. /** INTERNAL ONLY */
  2143. operator param<Concept, T&>() const { return param<Concept, T&>(data, table); }
  2144. #endif
  2145. private:
  2146. /** INTERNAL ONLY */
  2147. void _boost_type_erasure_swap(any& other)
  2148. {
  2149. ::std::swap(data, other.data);
  2150. ::std::swap(table, other.table);
  2151. }
  2152. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  2153. /** INTERNAL ONLY */
  2154. template<class Other>
  2155. void _boost_type_erasure_resolve_assign(Other&& other)
  2156. {
  2157. _boost_type_erasure_assign_impl(
  2158. std::forward<Other>(other),
  2159. false? this->_boost_type_erasure_deduce_assign(
  2160. ::boost::type_erasure::detail::make_fallback(
  2161. std::forward<Other>(other),
  2162. ::boost::mpl::bool_<
  2163. sizeof(
  2164. ::boost::type_erasure::detail::check_overload(
  2165. ::boost::declval<any&>().
  2166. _boost_type_erasure_deduce_assign(std::forward<Other>(other))
  2167. )
  2168. ) == sizeof(::boost::type_erasure::detail::yes)
  2169. >()
  2170. )
  2171. ) : 0,
  2172. ::boost::mpl::and_<
  2173. ::boost::type_erasure::is_relaxed<Concept>,
  2174. ::boost::is_convertible<Other, any>
  2175. #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1900))
  2176. , ::boost::mpl::not_<
  2177. ::boost::type_erasure::detail::is_rvalue_for_any<Other>
  2178. >
  2179. #endif
  2180. >()
  2181. );
  2182. }
  2183. /** INTERNAL ONLY */
  2184. template<class Other, class U>
  2185. void _boost_type_erasure_assign_impl(
  2186. Other&& other,
  2187. const assignable<T, U>*,
  2188. ::boost::mpl::false_)
  2189. {
  2190. ::boost::type_erasure::call(assignable<T, U>(), *this, std::forward<Other>(other));
  2191. }
  2192. /** INTERNAL ONLY */
  2193. template<class Other, class U>
  2194. void _boost_type_erasure_assign_impl(
  2195. Other&& other,
  2196. const assignable<T, U>*,
  2197. ::boost::mpl::true_)
  2198. {
  2199. if(::boost::type_erasure::check_match(assignable<T, U>(), *this, other)) {
  2200. ::boost::type_erasure::unchecked_call(assignable<T, U>(), *this, std::forward<Other>(other));
  2201. } else {
  2202. any temp(std::forward<Other>(other));
  2203. _boost_type_erasure_swap(temp);
  2204. }
  2205. }
  2206. /** INTERNAL ONLY */
  2207. template<class Other>
  2208. void _boost_type_erasure_assign_impl(
  2209. Other&& other,
  2210. const void*,
  2211. ::boost::mpl::true_)
  2212. {
  2213. any temp(std::forward<Other>(other));
  2214. _boost_type_erasure_swap(temp);
  2215. }
  2216. #else
  2217. /** INTERNAL ONLY */
  2218. template<class Other>
  2219. void _boost_type_erasure_resolve_assign(Other& other)
  2220. {
  2221. _boost_type_erasure_assign_impl(
  2222. other,
  2223. false? this->_boost_type_erasure_deduce_assign(
  2224. ::boost::type_erasure::detail::make_fallback(
  2225. other,
  2226. ::boost::mpl::bool_<
  2227. sizeof(
  2228. ::boost::type_erasure::detail::check_overload(
  2229. ::boost::declval<any&>().
  2230. _boost_type_erasure_deduce_assign(other)
  2231. )
  2232. ) == sizeof(::boost::type_erasure::detail::yes)
  2233. >()
  2234. )
  2235. ) : 0,
  2236. ::boost::mpl::and_<
  2237. ::boost::type_erasure::is_relaxed<Concept>,
  2238. ::boost::is_convertible<Other&, any>
  2239. >()
  2240. );
  2241. }
  2242. /** INTERNAL ONLY */
  2243. template<class Other, class U>
  2244. void _boost_type_erasure_assign_impl(
  2245. Other& other,
  2246. const assignable<T, U>*,
  2247. ::boost::mpl::false_)
  2248. {
  2249. ::boost::type_erasure::call(assignable<T, U>(), *this, other);
  2250. }
  2251. /** INTERNAL ONLY */
  2252. template<class Other, class U>
  2253. void _boost_type_erasure_assign_impl(
  2254. Other& other,
  2255. const assignable<T, U>*,
  2256. ::boost::mpl::true_)
  2257. {
  2258. if(::boost::type_erasure::check_match(assignable<T, U>(), *this, other)) {
  2259. ::boost::type_erasure::unchecked_call(assignable<T, U>(), *this, other);
  2260. } else {
  2261. any temp(other);
  2262. _boost_type_erasure_swap(temp);
  2263. }
  2264. }
  2265. /** INTERNAL ONLY */
  2266. template<class Other>
  2267. void _boost_type_erasure_assign_impl(
  2268. Other& other,
  2269. const void*,
  2270. ::boost::mpl::true_)
  2271. {
  2272. any temp(other);
  2273. _boost_type_erasure_swap(temp);
  2274. }
  2275. #endif
  2276. friend struct ::boost::type_erasure::detail::access;
  2277. ::boost::type_erasure::detail::storage data;
  2278. table_type table;
  2279. };
  2280. #ifdef BOOST_MSVC
  2281. #pragma warning(pop)
  2282. #endif
  2283. template<class Concept, class T>
  2284. class any<Concept, const T&> :
  2285. public ::boost::type_erasure::detail::compute_bases<
  2286. ::boost::type_erasure::any<Concept, const T&>,
  2287. Concept,
  2288. T
  2289. >::type
  2290. {
  2291. typedef ::boost::type_erasure::binding<Concept> table_type;
  2292. public:
  2293. /** INTERNAL ONLY */
  2294. typedef Concept _boost_type_erasure_concept_type;
  2295. /** INTERNAL ONLY */
  2296. any(const ::boost::type_erasure::detail::storage& data_arg,
  2297. const table_type& table_arg)
  2298. : data(data_arg),
  2299. table(table_arg)
  2300. {}
  2301. /**
  2302. * Constructs an @ref any from a reference.
  2303. *
  2304. * \param arg The object to bind the reference to.
  2305. *
  2306. * \pre @c U is a model of @c Concept.
  2307. * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
  2308. *
  2309. * \throws Nothing.
  2310. */
  2311. template<class U>
  2312. any(const U& arg)
  2313. : table((
  2314. BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, U),
  2315. ::boost::type_erasure::make_binding<
  2316. ::boost::mpl::map1< ::boost::mpl::pair<T, U> >
  2317. >()
  2318. ))
  2319. {
  2320. data.data = const_cast<void*>(static_cast<const void*>(::boost::addressof(arg)));
  2321. }
  2322. /**
  2323. * Constructs an @ref any from a reference.
  2324. *
  2325. * \param arg The object to bind the reference to.
  2326. * \param binding Specifies the actual types that
  2327. * all the placeholders should bind to.
  2328. *
  2329. * \pre @c U is a model of @c Concept.
  2330. * \pre @c Map is an MPL map with an entry for every
  2331. * non-deduced placeholder referred to by @c Concept.
  2332. *
  2333. * \throws Nothing.
  2334. */
  2335. template<class U, class Map>
  2336. any(const U& arg, const static_binding<Map>& binding_arg)
  2337. : table((
  2338. BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
  2339. binding_arg
  2340. ))
  2341. {
  2342. BOOST_MPL_ASSERT((::boost::is_same<
  2343. typename ::boost::mpl::at<Map, T>::type, U>));
  2344. data.data = const_cast<void*>(static_cast<const void*>(::boost::addressof(arg)));
  2345. }
  2346. /**
  2347. * Constructs an @ref any from another @ref any.
  2348. *
  2349. * \param other The reference to copy.
  2350. *
  2351. * \throws Nothing.
  2352. */
  2353. any(const any& other)
  2354. : data(other.data),
  2355. table(other.table)
  2356. {}
  2357. /**
  2358. * Constructs an @ref any from another @ref any.
  2359. *
  2360. * \param other The reference to copy.
  2361. *
  2362. * \throws Nothing.
  2363. */
  2364. any(const any<Concept, T&>& other)
  2365. : data(::boost::type_erasure::detail::access::data(other)),
  2366. table(::boost::type_erasure::detail::access::table(other))
  2367. {}
  2368. /**
  2369. * Constructs an @ref any from another @ref any.
  2370. *
  2371. * \param other The object to bind the reference to.
  2372. *
  2373. * \throws Nothing.
  2374. */
  2375. any(const any<Concept, T>& other)
  2376. : data(::boost::type_erasure::detail::access::data(other)),
  2377. table(::boost::type_erasure::detail::access::table(other))
  2378. {}
  2379. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  2380. /**
  2381. * Constructs an @ref any from another @ref any.
  2382. *
  2383. * \param other The object to bind the reference to.
  2384. *
  2385. * \throws Nothing.
  2386. */
  2387. any(const any<Concept, T&&>& other)
  2388. : data(::boost::type_erasure::detail::access::data(other)),
  2389. table(::boost::type_erasure::detail::access::table(other))
  2390. {}
  2391. #endif
  2392. /**
  2393. * Constructs an @ref any from another @ref any.
  2394. *
  2395. * \param other The object to bind the reference to.
  2396. *
  2397. * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
  2398. * \pre After substituting @c T for @c Tag2, the requirements of
  2399. * @c Concept2 must be a superset of the requirements of
  2400. * @c Concept.
  2401. *
  2402. * \throws std::bad_alloc
  2403. */
  2404. template<class Concept2, class Tag2>
  2405. any(const any<Concept2, Tag2>& other
  2406. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  2407. , typename ::boost::disable_if< ::boost::is_same<Concept, Concept2> >::type* = 0
  2408. #endif
  2409. )
  2410. : data(::boost::type_erasure::detail::access::data(other)),
  2411. table(
  2412. ::boost::type_erasure::detail::access::table(other),
  2413. ::boost::mpl::map1<
  2414. ::boost::mpl::pair<
  2415. T,
  2416. typename ::boost::remove_const<
  2417. typename ::boost::remove_reference<Tag2>::type
  2418. >::type
  2419. >
  2420. >())
  2421. {}
  2422. /**
  2423. * Constructs an @ref any from another @ref any.
  2424. *
  2425. * \param other The object to bind the reference to.
  2426. * \param binding Specifies the mapping between the two concepts.
  2427. *
  2428. * \pre @c Map must be an MPL map with keys for all the non-deduced
  2429. * placeholders used by @c Concept and values for the corresponding
  2430. * placeholders in @c Concept2.
  2431. * \pre After substituting placeholders according to @c Map, the
  2432. * requirements of @c Concept2 must be a superset of the
  2433. * requirements of @c Concept.
  2434. *
  2435. * \throws std::bad_alloc
  2436. */
  2437. template<class Concept2, class Tag2, class Map>
  2438. any(const any<Concept2, Tag2>& other, const static_binding<Map>& binding_arg)
  2439. : data(::boost::type_erasure::detail::access::data(other)),
  2440. table(::boost::type_erasure::detail::access::table(other), binding_arg)
  2441. {}
  2442. /**
  2443. * Constructs an @ref any from another @ref any.
  2444. *
  2445. * \param other The object to bind the reference to.
  2446. * \param binding Specifies the bindings of placeholders to actual types.
  2447. *
  2448. * \pre The type stored in @c other must match the type expected by
  2449. * @c binding.
  2450. *
  2451. * \post binding_of(*this) == @c binding
  2452. *
  2453. * \throws Nothing.
  2454. */
  2455. template<class Concept2, class Tag2>
  2456. any(const any<Concept2, Tag2>& other, const binding<Concept>& binding_arg)
  2457. : data(::boost::type_erasure::detail::access::data(other)),
  2458. table(binding_arg)
  2459. {}
  2460. /**
  2461. * Assigns to an @ref any.
  2462. *
  2463. * \pre @ref relaxed is in @c Concept.
  2464. *
  2465. * \throws Nothing.
  2466. */
  2467. any& operator=(const any& other)
  2468. {
  2469. BOOST_MPL_ASSERT((::boost::type_erasure::is_relaxed<Concept>));
  2470. any temp(other);
  2471. _boost_type_erasure_swap(temp);
  2472. return *this;
  2473. }
  2474. /**
  2475. * Assigns to an @ref any.
  2476. *
  2477. * \pre @ref relaxed is in @c Concept.
  2478. *
  2479. * \throws std::bad_alloc. Provides the strong exception guarantee.
  2480. */
  2481. template<class U>
  2482. any& operator=(const U& other)
  2483. {
  2484. BOOST_MPL_ASSERT((::boost::type_erasure::is_relaxed<Concept>));
  2485. any temp(other);
  2486. _boost_type_erasure_swap(temp);
  2487. return *this;
  2488. }
  2489. #ifndef BOOST_NO_CXX11_REF_QUALIFIERS
  2490. /** INTERNAL ONLY */
  2491. operator param<Concept, const T&>() const { return param<Concept, const T&>(data, table); }
  2492. #endif
  2493. private:
  2494. /** INTERNAL ONLY */
  2495. void _boost_type_erasure_swap(any& other)
  2496. {
  2497. ::std::swap(data, other.data);
  2498. ::std::swap(table, other.table);
  2499. }
  2500. friend struct ::boost::type_erasure::detail::access;
  2501. ::boost::type_erasure::detail::storage data;
  2502. table_type table;
  2503. };
  2504. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  2505. template<class Concept, class T>
  2506. class any<Concept, T&&> :
  2507. public ::boost::type_erasure::detail::compute_bases<
  2508. ::boost::type_erasure::any<Concept, T&&>,
  2509. Concept,
  2510. T
  2511. >::type
  2512. {
  2513. typedef ::boost::type_erasure::binding<Concept> table_type;
  2514. public:
  2515. /** INTERNAL ONLY */
  2516. typedef Concept _boost_type_erasure_concept_type;
  2517. /** INTERNAL ONLY */
  2518. any(const ::boost::type_erasure::detail::storage& data_arg,
  2519. const table_type& table_arg)
  2520. : data(data_arg),
  2521. table(table_arg)
  2522. {}
  2523. /**
  2524. * Constructs an @ref any from a reference.
  2525. *
  2526. * \param arg The object to bind the reference to.
  2527. *
  2528. * \pre @c U is a model of @c Concept.
  2529. * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
  2530. *
  2531. * \throws Nothing.
  2532. */
  2533. template<class U>
  2534. any(U&& arg
  2535. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  2536. , typename ::boost::disable_if<
  2537. ::boost::mpl::or_<
  2538. ::boost::is_reference<U>,
  2539. ::boost::is_const<U>,
  2540. ::boost::type_erasure::detail::is_any<U>
  2541. >
  2542. >::type* = 0
  2543. #endif
  2544. )
  2545. : table((
  2546. BOOST_TYPE_ERASURE_INSTANTIATE1(Concept, T, U),
  2547. ::boost::type_erasure::make_binding<
  2548. ::boost::mpl::map1< ::boost::mpl::pair<T, U> >
  2549. >()
  2550. ))
  2551. {
  2552. data.data = ::boost::addressof(arg);
  2553. }
  2554. /**
  2555. * Constructs an @ref any from a reference.
  2556. *
  2557. * \param arg The object to bind the reference to.
  2558. * \param binding Specifies the actual types that
  2559. * all the placeholders should bind to.
  2560. *
  2561. * \pre @c U is a model of @c Concept.
  2562. * \pre @c Map is an MPL map with an entry for every
  2563. * non-deduced placeholder referred to by @c Concept.
  2564. *
  2565. * \throws Nothing.
  2566. */
  2567. template<class U, class Map>
  2568. any(U&& arg, const static_binding<Map>& binding_arg)
  2569. : table((
  2570. BOOST_TYPE_ERASURE_INSTANTIATE(Concept, Map),
  2571. binding_arg
  2572. ))
  2573. {
  2574. BOOST_MPL_ASSERT((::boost::is_same<
  2575. typename ::boost::mpl::at<Map, T>::type, U>));
  2576. data.data = ::boost::addressof(arg);
  2577. }
  2578. /**
  2579. * Constructs an @ref any from another rvalue reference.
  2580. *
  2581. * \param other The reference to copy.
  2582. *
  2583. * \throws Nothing.
  2584. */
  2585. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  2586. any(any&& other)
  2587. : data(other.data),
  2588. table(std::move(other.table))
  2589. {}
  2590. any(const any& other)
  2591. : data(other.data),
  2592. table(other.table)
  2593. {}
  2594. #endif
  2595. /**
  2596. * Constructs an @ref any from another @ref any.
  2597. *
  2598. * \param other The object to bind the reference to.
  2599. *
  2600. * \throws Nothing.
  2601. */
  2602. any(any<Concept, T>&& other)
  2603. : data(::boost::type_erasure::detail::access::data(other)),
  2604. table(std::move(::boost::type_erasure::detail::access::table(other)))
  2605. {}
  2606. /**
  2607. * Constructs an @ref any from another rvalue reference.
  2608. *
  2609. * \param other The reference to copy.
  2610. *
  2611. * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
  2612. * \pre After substituting @c T for @c Tag2, the requirements of
  2613. * @c Concept2 must be a superset of the requirements of
  2614. * @c Concept.
  2615. *
  2616. * \throws std::bad_alloc
  2617. */
  2618. template<class Concept2, class Tag2>
  2619. any(any<Concept2, Tag2&&>&& other
  2620. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  2621. , typename ::boost::disable_if<
  2622. ::boost::mpl::or_<
  2623. ::boost::is_reference<Tag2>,
  2624. ::boost::is_same<Concept, Concept2>,
  2625. ::boost::is_const<Tag2>
  2626. >
  2627. >::type* = 0
  2628. #endif
  2629. )
  2630. : data(::boost::type_erasure::detail::access::data(other)),
  2631. table(
  2632. std::move(::boost::type_erasure::detail::access::table(other)),
  2633. ::boost::mpl::map1<
  2634. ::boost::mpl::pair<
  2635. T,
  2636. Tag2
  2637. >
  2638. >())
  2639. {}
  2640. /**
  2641. * Constructs an @ref any from another @ref any.
  2642. *
  2643. * \param other The object to bind the reference to.
  2644. *
  2645. * \pre @c Concept must not refer to any non-deduced placeholder besides @c T.
  2646. * \pre After substituting @c T for @c Tag2, the requirements of
  2647. * @c Concept2 must be a superset of the requirements of
  2648. * @c Concept.
  2649. *
  2650. * \throws std::bad_alloc
  2651. */
  2652. template<class Concept2, class Tag2>
  2653. any(any<Concept2, Tag2>&& other
  2654. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  2655. , typename ::boost::disable_if<
  2656. ::boost::mpl::or_<
  2657. ::boost::is_same<Concept, Concept2>,
  2658. ::boost::is_const<typename ::boost::remove_reference<Tag2>::type>
  2659. >
  2660. >::type* = 0
  2661. #endif
  2662. )
  2663. : data(::boost::type_erasure::detail::access::data(other)),
  2664. table(
  2665. std::move(::boost::type_erasure::detail::access::table(other)),
  2666. ::boost::mpl::map1<
  2667. ::boost::mpl::pair<
  2668. T,
  2669. typename ::boost::remove_reference<Tag2>::type
  2670. >
  2671. >())
  2672. {}
  2673. /**
  2674. * Constructs an @ref any from another reference.
  2675. *
  2676. * \param other The reference to copy.
  2677. * \param binding Specifies the mapping between the two concepts.
  2678. *
  2679. * \pre @c Map must be an MPL map with keys for all the non-deduced
  2680. * placeholders used by @c Concept and values for the corresponding
  2681. * placeholders in @c Concept2.
  2682. * \pre After substituting placeholders according to @c Map, the
  2683. * requirements of @c Concept2 must be a superset of the
  2684. * requirements of @c Concept.
  2685. *
  2686. * \throws std::bad_alloc
  2687. */
  2688. template<class Concept2, class Tag2, class Map>
  2689. any(const any<Concept2, Tag2&&>& other, const static_binding<Map>& binding_arg
  2690. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  2691. , typename ::boost::disable_if< ::boost::is_const<Tag2> >::type* = 0
  2692. #endif
  2693. )
  2694. : data(::boost::type_erasure::detail::access::data(other)),
  2695. table(std::move(::boost::type_erasure::detail::access::table(other)), binding_arg)
  2696. {}
  2697. /**
  2698. * Constructs an @ref any from another @ref any.
  2699. *
  2700. * \param other The object to bind the reference to.
  2701. * \param binding Specifies the mapping between the two concepts.
  2702. *
  2703. * \pre @c Map must be an MPL map with keys for all the non-deduced
  2704. * placeholders used by @c Concept and values for the corresponding
  2705. * placeholders in @c Concept2.
  2706. * \pre After substituting placeholders according to @c Map, the
  2707. * requirements of @c Concept2 must be a superset of the
  2708. * requirements of @c Concept.
  2709. *
  2710. * \throws std::bad_alloc
  2711. */
  2712. template<class Concept2, class Tag2, class Map>
  2713. any(any<Concept2, Tag2>&& other, const static_binding<Map>& binding_arg
  2714. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  2715. , typename ::boost::disable_if<
  2716. ::boost::is_const<typename ::boost::remove_reference<Tag2>::type>
  2717. >::type* = 0
  2718. #endif
  2719. )
  2720. : data(::boost::type_erasure::detail::access::data(other)),
  2721. table(::boost::type_erasure::detail::access::table(other), binding_arg)
  2722. {}
  2723. /**
  2724. * Constructs an @ref any from another rvalue reference.
  2725. *
  2726. * \param other The reference to copy.
  2727. * \param binding Specifies the bindings of placeholders to actual types.
  2728. *
  2729. * \pre The type stored in @c other must match the type expected by
  2730. * @c binding.
  2731. *
  2732. * \post binding_of(*this) == @c binding
  2733. *
  2734. * \throws Nothing.
  2735. */
  2736. template<class Concept2, class Tag2>
  2737. any(const any<Concept2, Tag2&&>& other, const binding<Concept>& binding_arg
  2738. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  2739. , typename ::boost::disable_if<
  2740. ::boost::is_const<Tag2>
  2741. >::type* = 0
  2742. #endif
  2743. )
  2744. : data(::boost::type_erasure::detail::access::data(other)),
  2745. table(binding_arg)
  2746. {}
  2747. /**
  2748. * Constructs an @ref any from another @ref any.
  2749. *
  2750. * \param other The object to bind the reference to.
  2751. * \param binding Specifies the bindings of placeholders to actual types.
  2752. *
  2753. * \pre The type stored in @c other must match the type expected by
  2754. * @c binding.
  2755. *
  2756. * \post binding_of(*this) == @c binding
  2757. *
  2758. * \throws Nothing.
  2759. */
  2760. template<class Concept2, class Tag2>
  2761. any(any<Concept2, Tag2>&& other, const binding<Concept>& binding_arg
  2762. #ifndef BOOST_TYPE_ERASURE_DOXYGEN
  2763. , typename ::boost::disable_if<
  2764. ::boost::is_const<typename ::boost::remove_reference<Tag2>::type>
  2765. >::type* = 0
  2766. #endif
  2767. )
  2768. : data(::boost::type_erasure::detail::access::data(other)),
  2769. table(binding_arg)
  2770. {}
  2771. /** INTERNAL ONLY */
  2772. any& operator=(const any& other)
  2773. {
  2774. _boost_type_erasure_resolve_assign(other);
  2775. return *this;
  2776. }
  2777. /**
  2778. * Assigns to an @ref any.
  2779. *
  2780. * If an appropriate overload of @ref assignable is not available
  2781. * and @ref relaxed is in @c Concept, falls back on
  2782. * constructing from @c other.
  2783. *
  2784. * \throws Whatever the assignment operator of the contained
  2785. * type throws. When falling back on construction,
  2786. * can only throw @c std::bad_alloc if @c U is an @ref any
  2787. * that uses a different @c Concept. In this case assignment
  2788. * provides the strong exception guarantee. When
  2789. * calling the assignment operator of the contained type,
  2790. * the exception guarantee is whatever the contained type provides.
  2791. */
  2792. template<class U>
  2793. any& operator=(U&& other)
  2794. {
  2795. _boost_type_erasure_resolve_assign(std::forward<U>(other));
  2796. return *this;
  2797. }
  2798. #ifndef BOOST_NO_CXX11_REF_QUALIFIERS
  2799. /** INTERNAL ONLY */
  2800. operator param<Concept, T&&>() const { return param<Concept, T&&>(data, table); }
  2801. #endif
  2802. private:
  2803. /** INTERNAL ONLY */
  2804. void _boost_type_erasure_swap(any& other)
  2805. {
  2806. ::std::swap(data, other.data);
  2807. ::std::swap(table, other.table);
  2808. }
  2809. /** INTERNAL ONLY */
  2810. template<class Other>
  2811. void _boost_type_erasure_resolve_assign(Other&& other)
  2812. {
  2813. _boost_type_erasure_assign_impl(
  2814. std::forward<Other>(other),
  2815. false? this->_boost_type_erasure_deduce_assign(
  2816. ::boost::type_erasure::detail::make_fallback(
  2817. std::forward<Other>(other),
  2818. ::boost::mpl::bool_<
  2819. sizeof(
  2820. ::boost::type_erasure::detail::check_overload(
  2821. ::boost::declval<any&>().
  2822. _boost_type_erasure_deduce_assign(std::forward<Other>(other))
  2823. )
  2824. ) == sizeof(::boost::type_erasure::detail::yes)
  2825. >()
  2826. )
  2827. ) : 0,
  2828. ::boost::mpl::and_<
  2829. ::boost::type_erasure::is_relaxed<Concept>,
  2830. ::boost::is_convertible<Other, any>
  2831. >()
  2832. );
  2833. }
  2834. /** INTERNAL ONLY */
  2835. template<class Other, class U>
  2836. void _boost_type_erasure_assign_impl(
  2837. Other&& other,
  2838. const assignable<T, U>*,
  2839. ::boost::mpl::false_)
  2840. {
  2841. ::boost::type_erasure::call(
  2842. assignable<T, U>(),
  2843. // lose rvalueness of this
  2844. ::boost::type_erasure::param<Concept, T&>(data, table),
  2845. std::forward<Other>(other));
  2846. }
  2847. /** INTERNAL ONLY */
  2848. template<class Other, class U>
  2849. void _boost_type_erasure_assign_impl(
  2850. Other&& other,
  2851. const assignable<T, U>*,
  2852. ::boost::mpl::true_)
  2853. {
  2854. if(::boost::type_erasure::check_match(assignable<T, U>(), *this, other)) {
  2855. ::boost::type_erasure::unchecked_call(
  2856. assignable<T, U>(),
  2857. // lose rvalueness of this
  2858. ::boost::type_erasure::param<Concept, T&>(data, table),
  2859. std::forward<Other>(other));
  2860. } else {
  2861. any temp(std::forward<Other>(other));
  2862. _boost_type_erasure_swap(temp);
  2863. }
  2864. }
  2865. /** INTERNAL ONLY */
  2866. template<class Other>
  2867. void _boost_type_erasure_assign_impl(
  2868. Other&& other,
  2869. const void*,
  2870. ::boost::mpl::true_)
  2871. {
  2872. any temp(std::forward<Other>(other));
  2873. _boost_type_erasure_swap(temp);
  2874. }
  2875. friend struct ::boost::type_erasure::detail::access;
  2876. ::boost::type_erasure::detail::storage data;
  2877. table_type table;
  2878. };
  2879. #endif
  2880. #ifndef BOOST_NO_CXX11_TEMPLATE_ALIASES
  2881. template<class Concept, class T>
  2882. using any_ref = any<Concept, T&>;
  2883. template<class Concept, class T>
  2884. using any_cref = any<Concept, const T&>;
  2885. #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
  2886. template<class Concept, class T>
  2887. using any_rvref = any<Concept, T&&>;
  2888. #endif
  2889. #endif
  2890. }
  2891. }
  2892. #endif