1292928Sdim// -*- C++ -*- 2292928Sdim//===------------------------------ any -----------------------------------===// 3292928Sdim// 4292928Sdim// The LLVM Compiler Infrastructure 5292928Sdim// 6292928Sdim// This file is distributed under the University of Illinois Open Source 7292928Sdim// License. See LICENSE.TXT for details. 8292928Sdim// 9292928Sdim//===----------------------------------------------------------------------===// 10292928Sdim 11292928Sdim#ifndef _LIBCPP_EXPERIMENTAL_ANY 12292928Sdim#define _LIBCPP_EXPERIMENTAL_ANY 13292928Sdim 14292928Sdim/* 15292928Sdim experimental/any synopsis 16292928Sdim 17292928Sdimnamespace std { 18292928Sdimnamespace experimental { 19292928Sdiminline namespace fundamentals_v1 { 20292928Sdim 21292928Sdim class bad_any_cast : public bad_cast 22292928Sdim { 23292928Sdim public: 24292928Sdim virtual const char* what() const noexcept; 25292928Sdim }; 26292928Sdim 27292928Sdim class any 28292928Sdim { 29292928Sdim public: 30292928Sdim 31292928Sdim // 6.3.1 any construct/destruct 32292928Sdim any() noexcept; 33292928Sdim 34292928Sdim any(const any& other); 35292928Sdim any(any&& other) noexcept; 36292928Sdim 37292928Sdim template <class ValueType> 38292928Sdim any(ValueType&& value); 39292928Sdim 40292928Sdim ~any(); 41292928Sdim 42292928Sdim // 6.3.2 any assignments 43292928Sdim any& operator=(const any& rhs); 44292928Sdim any& operator=(any&& rhs) noexcept; 45292928Sdim 46292928Sdim template <class ValueType> 47292928Sdim any& operator=(ValueType&& rhs); 48292928Sdim 49292928Sdim // 6.3.3 any modifiers 50292928Sdim void clear() noexcept; 51292928Sdim void swap(any& rhs) noexcept; 52292928Sdim 53292928Sdim // 6.3.4 any observers 54292928Sdim bool empty() const noexcept; 55292928Sdim const type_info& type() const noexcept; 56292928Sdim }; 57292928Sdim 58292928Sdim // 6.4 Non-member functions 59292928Sdim void swap(any& x, any& y) noexcept; 60292928Sdim 61292928Sdim template<class ValueType> 62292928Sdim ValueType any_cast(const any& operand); 63292928Sdim template<class ValueType> 64292928Sdim ValueType any_cast(any& operand); 65292928Sdim template<class ValueType> 66292928Sdim ValueType any_cast(any&& operand); 67292928Sdim 68292928Sdim template<class ValueType> 69292928Sdim const ValueType* any_cast(const any* operand) noexcept; 70292928Sdim template<class ValueType> 71292928Sdim ValueType* any_cast(any* operand) noexcept; 72292928Sdim 73292928Sdim} // namespace fundamentals_v1 74292928Sdim} // namespace experimental 75292928Sdim} // namespace std 76292928Sdim 77292928Sdim*/ 78292928Sdim 79292928Sdim#include <experimental/__config> 80292928Sdim#include <memory> 81292928Sdim#include <new> 82292928Sdim#include <typeinfo> 83292928Sdim#include <type_traits> 84292928Sdim#include <cstdlib> 85292928Sdim#include <cassert> 86292928Sdim 87292928Sdim#if !defined(_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER) 88292928Sdim#pragma GCC system_header 89292928Sdim#endif 90292928Sdim 91292928Sdim_LIBCPP_BEGIN_NAMESPACE_LFTS 92292928Sdim 93292928Sdimclass _LIBCPP_EXCEPTION_ABI bad_any_cast : public bad_cast 94292928Sdim{ 95292928Sdimpublic: 96292928Sdim virtual const char* what() const _NOEXCEPT; 97292928Sdim}; 98292928Sdim 99292928Sdim#if _LIBCPP_STD_VER > 11 // C++ > 11 100292928Sdim 101292928Sdim_LIBCPP_NORETURN _LIBCPP_INLINE_VISIBILITY 102292928Sdiminline void __throw_bad_any_cast() 103292928Sdim{ 104292928Sdim#ifndef _LIBCPP_NO_EXCEPTIONS 105292928Sdim throw bad_any_cast(); 106292928Sdim#else 107292928Sdim assert(!"bad_any_cast"); 108292928Sdim#endif 109292928Sdim} 110292928Sdim 111292928Sdim// Forward declarations 112292928Sdimclass any; 113292928Sdim 114292928Sdimtemplate <class _ValueType> 115292928Sdimtypename add_pointer<typename add_const<_ValueType>::type>::type 116292928Sdimany_cast(any const *) _NOEXCEPT; 117292928Sdim 118292928Sdimtemplate <class _ValueType> 119292928Sdimtypename add_pointer<_ValueType>::type 120292928Sdimany_cast(any *) _NOEXCEPT; 121292928Sdim 122292928Sdimnamespace __any_imp 123292928Sdim{ 124292928Sdim typedef typename aligned_storage<3*sizeof(void*), alignment_of<void*>::value>::type 125292928Sdim _Buffer; 126292928Sdim 127292928Sdim template <class _Tp> 128292928Sdim struct _IsSmallObject 129292928Sdim : public integral_constant<bool 130292928Sdim , sizeof(_Tp) <= sizeof(_Buffer) 131292928Sdim && alignment_of<_Buffer>::value 132292928Sdim % alignment_of<_Tp>::value == 0 133292928Sdim && is_nothrow_move_constructible<_Tp>::value 134292928Sdim > 135292928Sdim {}; 136292928Sdim 137292928Sdim enum class _Action 138292928Sdim { 139292928Sdim _Destroy, 140292928Sdim _Copy, 141292928Sdim _Move, 142292928Sdim _Get, 143292928Sdim _TypeInfo 144292928Sdim }; 145292928Sdim 146292928Sdim template <class _Tp> 147292928Sdim struct _SmallHandler; 148292928Sdim 149292928Sdim template <class _Tp> 150292928Sdim struct _LargeHandler; 151292928Sdim 152292928Sdim template <class _Tp> 153292928Sdim using _Handler = typename conditional<_IsSmallObject<_Tp>::value 154292928Sdim , _SmallHandler<_Tp> 155292928Sdim , _LargeHandler<_Tp> 156292928Sdim >::type; 157292928Sdim template <class _ValueType> 158292928Sdim using _EnableIfNotAny = typename 159292928Sdim enable_if< 160292928Sdim !is_same<typename decay<_ValueType>::type, any>::value 161292928Sdim >::type; 162292928Sdim 163292928Sdim} // namespace __any_imp 164292928Sdim 165292928Sdimclass any 166292928Sdim{ 167292928Sdimpublic: 168292928Sdim // 6.3.1 any construct/destruct 169292928Sdim _LIBCPP_INLINE_VISIBILITY 170292928Sdim any() _NOEXCEPT : __h(nullptr) {} 171292928Sdim 172292928Sdim _LIBCPP_INLINE_VISIBILITY 173292928Sdim any(any const & __other) : __h(nullptr) 174292928Sdim { 175292928Sdim if (__other.__h) __other.__call(_Action::_Copy, this); 176292928Sdim } 177292928Sdim 178292928Sdim _LIBCPP_INLINE_VISIBILITY 179292928Sdim any(any && __other) _NOEXCEPT : __h(nullptr) 180292928Sdim { 181292928Sdim if (__other.__h) __other.__call(_Action::_Move, this); 182292928Sdim } 183292928Sdim 184292928Sdim template < 185292928Sdim class _ValueType 186292928Sdim , class = __any_imp::_EnableIfNotAny<_ValueType> 187292928Sdim > 188292928Sdim any(_ValueType && __value); 189292928Sdim 190292928Sdim _LIBCPP_INLINE_VISIBILITY 191292928Sdim ~any() 192292928Sdim { 193292928Sdim this->clear(); 194292928Sdim } 195292928Sdim 196292928Sdim // 6.3.2 any assignments 197292928Sdim _LIBCPP_INLINE_VISIBILITY 198292928Sdim any & operator=(any const & __rhs) 199292928Sdim { 200292928Sdim any(__rhs).swap(*this); 201292928Sdim return *this; 202292928Sdim } 203292928Sdim 204292928Sdim _LIBCPP_INLINE_VISIBILITY 205292928Sdim any & operator=(any && __rhs) _NOEXCEPT 206292928Sdim { 207292928Sdim any(_VSTD::move(__rhs)).swap(*this); 208292928Sdim return *this; 209292928Sdim } 210292928Sdim 211292928Sdim template < 212292928Sdim class _ValueType 213292928Sdim , class = __any_imp::_EnableIfNotAny<_ValueType> 214292928Sdim > 215292928Sdim any & operator=(_ValueType && __rhs); 216292928Sdim 217292928Sdim // 6.3.3 any modifiers 218292928Sdim _LIBCPP_INLINE_VISIBILITY 219292928Sdim void clear() _NOEXCEPT 220292928Sdim { 221292928Sdim if (__h) this->__call(_Action::_Destroy); 222292928Sdim } 223292928Sdim 224292928Sdim void swap(any & __rhs) _NOEXCEPT; 225292928Sdim 226292928Sdim // 6.3.4 any observers 227292928Sdim _LIBCPP_INLINE_VISIBILITY 228292928Sdim bool empty() const _NOEXCEPT 229292928Sdim { 230292928Sdim return __h == nullptr; 231292928Sdim } 232292928Sdim 233292928Sdim#if !defined(_LIBCPP_NO_RTTI) 234292928Sdim _LIBCPP_INLINE_VISIBILITY 235292928Sdim const type_info & type() const _NOEXCEPT 236292928Sdim { 237292928Sdim if (__h) { 238292928Sdim return *static_cast<type_info const *>(this->__call(_Action::_TypeInfo)); 239292928Sdim } else { 240292928Sdim return typeid(void); 241292928Sdim } 242292928Sdim } 243292928Sdim#endif 244292928Sdim 245292928Sdimprivate: 246292928Sdim typedef __any_imp::_Action _Action; 247292928Sdim 248292928Sdim typedef void* (*_HandleFuncPtr)(_Action, any const *, any *, const type_info *); 249292928Sdim 250292928Sdim union _Storage 251292928Sdim { 252292928Sdim void * __ptr; 253292928Sdim __any_imp::_Buffer __buf; 254292928Sdim }; 255292928Sdim 256292928Sdim _LIBCPP_ALWAYS_INLINE 257292928Sdim void * __call(_Action __a, any * __other = nullptr, 258292928Sdim type_info const * __info = nullptr) const 259292928Sdim { 260292928Sdim return __h(__a, this, __other, __info); 261292928Sdim } 262292928Sdim 263292928Sdim _LIBCPP_ALWAYS_INLINE 264292928Sdim void * __call(_Action __a, any * __other = nullptr, 265292928Sdim type_info const * __info = nullptr) 266292928Sdim { 267292928Sdim return __h(__a, this, __other, __info); 268292928Sdim } 269292928Sdim 270292928Sdim template <class> 271292928Sdim friend struct __any_imp::_SmallHandler; 272292928Sdim template <class> 273292928Sdim friend struct __any_imp::_LargeHandler; 274292928Sdim 275292928Sdim template <class _ValueType> 276292928Sdim friend typename add_pointer<typename add_const<_ValueType>::type>::type 277292928Sdim any_cast(any const *) _NOEXCEPT; 278292928Sdim 279292928Sdim template <class _ValueType> 280292928Sdim friend typename add_pointer<_ValueType>::type 281292928Sdim any_cast(any *) _NOEXCEPT; 282292928Sdim 283292928Sdim _HandleFuncPtr __h; 284292928Sdim _Storage __s; 285292928Sdim}; 286292928Sdim 287292928Sdimnamespace __any_imp 288292928Sdim{ 289292928Sdim 290292928Sdim template <class _Tp> 291292928Sdim struct _LIBCPP_TYPE_VIS_ONLY _SmallHandler 292292928Sdim { 293292928Sdim _LIBCPP_INLINE_VISIBILITY 294292928Sdim static void* __handle(_Action __act, any const * __this, any * __other, 295292928Sdim type_info const * __info) 296292928Sdim { 297292928Sdim switch (__act) 298292928Sdim { 299292928Sdim case _Action::_Destroy: 300292928Sdim __destroy(const_cast<any &>(*__this)); 301292928Sdim return nullptr; 302292928Sdim case _Action::_Copy: 303292928Sdim __copy(*__this, *__other); 304292928Sdim return nullptr; 305292928Sdim case _Action::_Move: 306292928Sdim __move(const_cast<any &>(*__this), *__other); 307292928Sdim return nullptr; 308292928Sdim case _Action::_Get: 309292928Sdim return __get(const_cast<any &>(*__this), __info); 310292928Sdim case _Action::_TypeInfo: 311292928Sdim return __type_info(); 312292928Sdim } 313292928Sdim } 314292928Sdim 315292928Sdim template <class _Up> 316292928Sdim _LIBCPP_INLINE_VISIBILITY 317292928Sdim static void __create(any & __dest, _Up && __v) 318292928Sdim { 319292928Sdim ::new (static_cast<void*>(&__dest.__s.__buf)) _Tp(_VSTD::forward<_Up>(__v)); 320292928Sdim __dest.__h = &_SmallHandler::__handle; 321292928Sdim } 322292928Sdim 323292928Sdim private: 324292928Sdim _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY 325292928Sdim static void __destroy(any & __this) 326292928Sdim { 327292928Sdim _Tp & __value = *static_cast<_Tp *>(static_cast<void*>(&__this.__s.__buf)); 328292928Sdim __value.~_Tp(); 329292928Sdim __this.__h = nullptr; 330292928Sdim } 331292928Sdim 332292928Sdim _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY 333292928Sdim static void __copy(any const & __this, any & __dest) 334292928Sdim { 335292928Sdim _SmallHandler::__create(__dest, *static_cast<_Tp const *>( 336292928Sdim static_cast<void const *>(&__this.__s.__buf))); 337292928Sdim } 338292928Sdim 339292928Sdim _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY 340292928Sdim static void __move(any & __this, any & __dest) 341292928Sdim { 342292928Sdim _SmallHandler::__create(__dest, _VSTD::move( 343292928Sdim *static_cast<_Tp*>(static_cast<void*>(&__this.__s.__buf)))); 344292928Sdim __destroy(__this); 345292928Sdim } 346292928Sdim 347292928Sdim _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY 348292928Sdim static void* __get(any & __this, type_info const * __info) 349292928Sdim { 350292928Sdim#if !defined(_LIBCPP_NO_RTTI) 351292928Sdim if (typeid(_Tp) == *__info) { 352292928Sdim return static_cast<void*>(&__this.__s.__buf); 353292928Sdim } 354292928Sdim return nullptr; 355292928Sdim#else 356292928Sdim return static_cast<void*>(&__this.__s.__buf); 357292928Sdim#endif 358292928Sdim } 359292928Sdim 360292928Sdim _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY 361292928Sdim static void* __type_info() 362292928Sdim { 363292928Sdim#if !defined(_LIBCPP_NO_RTTI) 364292928Sdim return const_cast<void*>(static_cast<void const *>(&typeid(_Tp))); 365292928Sdim#else 366292928Sdim return nullptr; 367292928Sdim#endif 368292928Sdim } 369292928Sdim }; 370292928Sdim 371292928Sdim template <class _Tp> 372292928Sdim struct _LIBCPP_TYPE_VIS_ONLY _LargeHandler 373292928Sdim { 374292928Sdim _LIBCPP_INLINE_VISIBILITY 375292928Sdim static void* __handle(_Action __act, any const * __this, any * __other, 376292928Sdim type_info const * __info) 377292928Sdim { 378292928Sdim switch (__act) 379292928Sdim { 380292928Sdim case _Action::_Destroy: 381292928Sdim __destroy(const_cast<any &>(*__this)); 382292928Sdim return nullptr; 383292928Sdim case _Action::_Copy: 384292928Sdim __copy(*__this, *__other); 385292928Sdim return nullptr; 386292928Sdim case _Action::_Move: 387292928Sdim __move(const_cast<any &>(*__this), *__other); 388292928Sdim return nullptr; 389292928Sdim case _Action::_Get: 390292928Sdim return __get(const_cast<any &>(*__this), __info); 391292928Sdim case _Action::_TypeInfo: 392292928Sdim return __type_info(); 393292928Sdim } 394292928Sdim } 395292928Sdim 396292928Sdim template <class _Up> 397292928Sdim _LIBCPP_INLINE_VISIBILITY 398292928Sdim static void __create(any & __dest, _Up && __v) 399292928Sdim { 400292928Sdim typedef allocator<_Tp> _Alloc; 401292928Sdim typedef __allocator_destructor<_Alloc> _Dp; 402292928Sdim _Alloc __a; 403292928Sdim unique_ptr<_Tp, _Dp> __hold(__a.allocate(1), _Dp(__a, 1)); 404292928Sdim ::new ((void*)__hold.get()) _Tp(_VSTD::forward<_Up>(__v)); 405292928Sdim __dest.__s.__ptr = __hold.release(); 406292928Sdim __dest.__h = &_LargeHandler::__handle; 407292928Sdim } 408292928Sdim 409292928Sdim private: 410292928Sdim 411292928Sdim _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY 412292928Sdim static void __destroy(any & __this) 413292928Sdim { 414292928Sdim delete static_cast<_Tp*>(__this.__s.__ptr); 415292928Sdim __this.__h = nullptr; 416292928Sdim } 417292928Sdim 418292928Sdim _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY 419292928Sdim static void __copy(any const & __this, any & __dest) 420292928Sdim { 421292928Sdim _LargeHandler::__create(__dest, *static_cast<_Tp const *>(__this.__s.__ptr)); 422292928Sdim } 423292928Sdim 424292928Sdim _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY 425292928Sdim static void __move(any & __this, any & __dest) 426292928Sdim { 427292928Sdim __dest.__s.__ptr = __this.__s.__ptr; 428292928Sdim __dest.__h = &_LargeHandler::__handle; 429292928Sdim __this.__h = nullptr; 430292928Sdim } 431292928Sdim 432292928Sdim _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY 433292928Sdim static void* __get(any & __this, type_info const * __info) 434292928Sdim { 435292928Sdim#if !defined(_LIBCPP_NO_RTTI) 436292928Sdim if (typeid(_Tp) == *__info) { 437292928Sdim return static_cast<void*>(__this.__s.__ptr); 438292928Sdim } 439292928Sdim return nullptr; 440292928Sdim#else 441292928Sdim return static_cast<void*>(__this.__s.__ptr); 442292928Sdim#endif 443292928Sdim } 444292928Sdim 445292928Sdim _LIBCPP_ALWAYS_INLINE _LIBCPP_INLINE_VISIBILITY 446292928Sdim static void* __type_info() 447292928Sdim { 448292928Sdim#if !defined(_LIBCPP_NO_RTTI) 449292928Sdim return const_cast<void*>(static_cast<void const *>(&typeid(_Tp))); 450292928Sdim#else 451292928Sdim return nullptr; 452292928Sdim#endif 453292928Sdim } 454292928Sdim }; 455292928Sdim 456292928Sdim} // namespace __any_imp 457292928Sdim 458292928Sdim 459292928Sdimtemplate <class _ValueType, class> 460292928Sdim_LIBCPP_INLINE_VISIBILITY 461292928Sdimany::any(_ValueType && __v) : __h(nullptr) 462292928Sdim{ 463292928Sdim typedef typename decay<_ValueType>::type _Tp; 464292928Sdim static_assert(is_copy_constructible<_Tp>::value, 465292928Sdim "_ValueType must be CopyConstructible."); 466292928Sdim typedef __any_imp::_Handler<_Tp> _HandlerType; 467292928Sdim _HandlerType::__create(*this, _VSTD::forward<_ValueType>(__v)); 468292928Sdim} 469292928Sdim 470292928Sdimtemplate <class _ValueType, class> 471292928Sdim_LIBCPP_INLINE_VISIBILITY 472292928Sdimany & any::operator=(_ValueType && __v) 473292928Sdim{ 474292928Sdim typedef typename decay<_ValueType>::type _Tp; 475292928Sdim static_assert(is_copy_constructible<_Tp>::value, 476292928Sdim "_ValueType must be CopyConstructible."); 477292928Sdim any(_VSTD::forward<_ValueType>(__v)).swap(*this); 478292928Sdim return *this; 479292928Sdim} 480292928Sdim 481292928Sdiminline _LIBCPP_INLINE_VISIBILITY 482292928Sdimvoid any::swap(any & __rhs) _NOEXCEPT 483292928Sdim{ 484292928Sdim if (__h && __rhs.__h) { 485292928Sdim any __tmp; 486292928Sdim __rhs.__call(_Action::_Move, &__tmp); 487292928Sdim this->__call(_Action::_Move, &__rhs); 488292928Sdim __tmp.__call(_Action::_Move, this); 489292928Sdim } 490292928Sdim else if (__h) { 491292928Sdim this->__call(_Action::_Move, &__rhs); 492292928Sdim } 493292928Sdim else if (__rhs.__h) { 494292928Sdim __rhs.__call(_Action::_Move, this); 495292928Sdim } 496292928Sdim} 497292928Sdim 498292928Sdim// 6.4 Non-member functions 499292928Sdim 500292928Sdiminline _LIBCPP_INLINE_VISIBILITY 501292928Sdimvoid swap(any & __lhs, any & __rhs) _NOEXCEPT 502292928Sdim{ 503292928Sdim __lhs.swap(__rhs); 504292928Sdim} 505292928Sdim 506292928Sdimtemplate <class _ValueType> 507292928Sdim_LIBCPP_INLINE_VISIBILITY 508292928Sdim_ValueType any_cast(any const & __v) 509292928Sdim{ 510292928Sdim static_assert( 511292928Sdim is_reference<_ValueType>::value 512292928Sdim || is_copy_constructible<_ValueType>::value, 513292928Sdim "_ValueType is required to be a reference or a CopyConstructible type."); 514292928Sdim typedef typename add_const<typename remove_reference<_ValueType>::type>::type 515292928Sdim _Tp; 516292928Sdim _Tp * __tmp = any_cast<_Tp>(&__v); 517292928Sdim if (__tmp == nullptr) 518292928Sdim __throw_bad_any_cast(); 519292928Sdim return *__tmp; 520292928Sdim} 521292928Sdim 522292928Sdimtemplate <class _ValueType> 523292928Sdim_LIBCPP_INLINE_VISIBILITY 524292928Sdim_ValueType any_cast(any & __v) 525292928Sdim{ 526292928Sdim static_assert( 527292928Sdim is_reference<_ValueType>::value 528292928Sdim || is_copy_constructible<_ValueType>::value, 529292928Sdim "_ValueType is required to be a reference or a CopyConstructible type."); 530292928Sdim typedef typename remove_reference<_ValueType>::type _Tp; 531292928Sdim _Tp * __tmp = any_cast<_Tp>(&__v); 532292928Sdim if (__tmp == nullptr) 533292928Sdim __throw_bad_any_cast(); 534292928Sdim return *__tmp; 535292928Sdim} 536292928Sdim 537292928Sdimtemplate <class _ValueType> 538292928Sdim_LIBCPP_INLINE_VISIBILITY 539292928Sdim_ValueType any_cast(any && __v) 540292928Sdim{ 541292928Sdim static_assert( 542292928Sdim is_reference<_ValueType>::value 543292928Sdim || is_copy_constructible<_ValueType>::value, 544292928Sdim "_ValueType is required to be a reference or a CopyConstructible type."); 545292928Sdim typedef typename remove_reference<_ValueType>::type _Tp; 546292928Sdim _Tp * __tmp = any_cast<_Tp>(&__v); 547292928Sdim if (__tmp == nullptr) 548292928Sdim __throw_bad_any_cast(); 549292928Sdim return *__tmp; 550292928Sdim} 551292928Sdim 552292928Sdimtemplate <class _ValueType> 553292928Sdiminline _LIBCPP_INLINE_VISIBILITY 554292928Sdimtypename add_pointer<typename add_const<_ValueType>::type>::type 555292928Sdimany_cast(any const * __any) _NOEXCEPT 556292928Sdim{ 557292928Sdim static_assert(!is_reference<_ValueType>::value, 558292928Sdim "_ValueType may not be a reference."); 559292928Sdim return any_cast<_ValueType>(const_cast<any *>(__any)); 560292928Sdim} 561292928Sdim 562292928Sdimtemplate <class _ValueType> 563292928Sdim_LIBCPP_INLINE_VISIBILITY 564292928Sdimtypename add_pointer<_ValueType>::type 565292928Sdimany_cast(any * __any) _NOEXCEPT 566292928Sdim{ 567292928Sdim using __any_imp::_Action; 568292928Sdim static_assert(!is_reference<_ValueType>::value, 569292928Sdim "_ValueType may not be a reference."); 570292928Sdim typedef typename add_pointer<_ValueType>::type _ReturnType; 571292928Sdim if (__any && __any->__h) { 572292928Sdim 573292928Sdim return static_cast<_ReturnType>( 574292928Sdim __any->__call(_Action::_Get, nullptr, 575292928Sdim#if !defined(_LIBCPP_NO_RTTI) 576292928Sdim &typeid(_ValueType) 577292928Sdim#else 578292928Sdim nullptr 579292928Sdim#endif 580292928Sdim )); 581292928Sdim 582292928Sdim } 583292928Sdim return nullptr; 584292928Sdim} 585292928Sdim 586292928Sdim#endif // _LIBCPP_STD_VER > 11 587292928Sdim 588292928Sdim_LIBCPP_END_NAMESPACE_LFTS 589292928Sdim 590292928Sdim#endif // _LIBCPP_EXPERIMENTAL_ANY 591