12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456 |
- #ifndef BOOST_VARIANT_VARIANT_HPP
- #define BOOST_VARIANT_VARIANT_HPP
- #include <cstddef> // for std::size_t
- #include <new> // for placement new
- #include <boost/type_index.hpp>
- #include <boost/variant/detail/config.hpp>
- #include <boost/mpl/aux_/value_wknd.hpp>
- #include <boost/variant/variant_fwd.hpp>
- #include <boost/variant/detail/backup_holder.hpp>
- #include <boost/variant/detail/enable_recursive_fwd.hpp>
- #include <boost/variant/detail/forced_return.hpp>
- #include <boost/variant/detail/initializer.hpp>
- #include <boost/variant/detail/make_variant_list.hpp>
- #include <boost/variant/detail/over_sequence.hpp>
- #include <boost/variant/detail/visitation_impl.hpp>
- #include <boost/variant/detail/hash_variant.hpp>
- #include <boost/variant/detail/std_hash.hpp>
- #include <boost/variant/detail/move.hpp>
- #include <boost/detail/reference_content.hpp>
- #include <boost/blank.hpp>
- #include <boost/integer/common_factor_ct.hpp>
- #include <boost/static_assert.hpp>
- #include <boost/preprocessor/cat.hpp>
- #include <boost/preprocessor/repeat.hpp>
- #include <boost/type_traits/aligned_storage.hpp>
- #include <boost/type_traits/alignment_of.hpp>
- #include <boost/type_traits/add_const.hpp>
- #include <boost/type_traits/has_nothrow_constructor.hpp>
- #include <boost/type_traits/has_nothrow_copy.hpp>
- #include <boost/type_traits/is_nothrow_move_assignable.hpp>
- #include <boost/type_traits/is_nothrow_move_constructible.hpp>
- #include <boost/type_traits/is_const.hpp>
- #include <boost/type_traits/is_same.hpp>
- #include <boost/type_traits/is_rvalue_reference.hpp>
- #include <boost/type_traits/is_constructible.hpp>
- #include <boost/type_traits/add_lvalue_reference.hpp>
- #include <boost/type_traits/declval.hpp>
- #include <boost/core/no_exceptions_support.hpp>
- #include <boost/core/enable_if.hpp>
- #include <boost/variant/recursive_wrapper_fwd.hpp>
- #include <boost/variant/static_visitor.hpp>
- #include <boost/mpl/assert.hpp>
- #include <boost/mpl/begin_end.hpp>
- #include <boost/mpl/bool.hpp>
- #include <boost/mpl/deref.hpp>
- #include <boost/mpl/empty.hpp>
- #include <boost/mpl/eval_if.hpp>
- #include <boost/mpl/find_if.hpp>
- #include <boost/mpl/fold.hpp>
- #include <boost/mpl/front.hpp>
- #include <boost/mpl/identity.hpp>
- #include <boost/mpl/if.hpp>
- #include <boost/mpl/insert_range.hpp>
- #include <boost/mpl/int.hpp>
- #include <boost/mpl/is_sequence.hpp>
- #include <boost/mpl/iterator_range.hpp>
- #include <boost/mpl/iter_fold_if.hpp>
- #include <boost/mpl/list.hpp>
- #include <boost/mpl/logical.hpp>
- #include <boost/mpl/max_element.hpp>
- #include <boost/mpl/next.hpp>
- #include <boost/mpl/not.hpp>
- #include <boost/mpl/pair.hpp>
- #include <boost/mpl/protect.hpp>
- #include <boost/mpl/push_front.hpp>
- #include <boost/mpl/same_as.hpp>
- #include <boost/mpl/size_t.hpp>
- #include <boost/mpl/sizeof.hpp>
- #include <boost/mpl/transform.hpp>
- #if defined(BOOST_VARIANT_MINIMIZE_SIZE)
- # include <climits> // for SCHAR_MAX
- # include <boost/mpl/eval_if.hpp>
- # include <boost/mpl/equal_to.hpp>
- # include <boost/mpl/identity.hpp>
- # include <boost/mpl/int.hpp>
- # include <boost/mpl/if.hpp>
- # include <boost/mpl/less.hpp>
- # include <boost/mpl/long.hpp>
- # include <boost/mpl/O1_size.hpp>
- #endif
- namespace boost {
- namespace detail { namespace variant {
- template <typename Sequence, typename F>
- struct max_value
- {
- private:
- typedef typename mpl::transform1<Sequence, F>::type transformed_;
- typedef typename mpl::max_element<transformed_
- >::type max_it;
- public:
- typedef typename mpl::deref<max_it>::type
- type;
- };
- struct add_alignment
- {
- template <typename State, typename Item>
- struct apply
- : mpl::size_t<
- ::boost::integer::static_lcm<
- BOOST_MPL_AUX_VALUE_WKND(State)::value
- , ::boost::alignment_of<Item>::value
- >::value
- >
- {};
- };
- class no_fallback_type;
- struct find_fallback_type_pred
- {
- template <typename Iterator>
- struct apply
- {
- private:
- typedef typename mpl::deref<Iterator>::type t_;
- public:
- typedef mpl::not_< has_nothrow_constructor<t_> > type;
- };
- };
- template <typename Types>
- struct find_fallback_type
- {
- private:
- typedef typename mpl::end<Types>::type end_it;
-
- typedef typename mpl::iter_fold_if<
- Types
- , mpl::int_<0>, mpl::protect< mpl::next<> >
- , mpl::protect< find_fallback_type_pred >
- >::type first_result_;
- typedef typename first_result_::first first_result_index;
- typedef typename first_result_::second first_result_it;
-
- typedef typename mpl::iter_fold_if<
- mpl::iterator_range< first_result_it,end_it >
- , first_result_index, mpl::protect< mpl::next<> >
- , mpl::protect< mpl::not_same_as<boost::blank> >
- >::type second_result_;
- typedef typename second_result_::second second_result_it;
- public:
-
- typedef typename mpl::eval_if<
- is_same< second_result_it,end_it >
- , mpl::if_<
- is_same< first_result_it,end_it >
- , mpl::pair< no_fallback_type,no_fallback_type >
- , first_result_
- >
- , mpl::identity< second_result_ >
- >::type type;
- };
- #ifndef BOOST_NO_CXX11_NOEXCEPT
- template <class Types>
- struct is_variant_move_noexcept_constructible {
- typedef typename boost::mpl::find_if<
- Types, mpl::not_<boost::is_nothrow_move_constructible<boost::mpl::_1> >
- >::type iterator_t;
- typedef typename boost::mpl::end<Types>::type end_t;
- typedef typename boost::is_same<
- iterator_t, end_t
- >::type type;
- };
- template <class Types>
- struct is_variant_move_noexcept_assignable {
- typedef typename boost::mpl::find_if<
- Types, mpl::not_<boost::is_nothrow_move_assignable<boost::mpl::_1> >
- >::type iterator_t;
- typedef typename boost::mpl::end<Types>::type end_t;
- typedef typename boost::is_same<
- iterator_t, end_t
- >::type type;
- };
- #endif
- template <class T1, class T2>
- struct is_constructible_ext:
- boost::mpl::or_<
- boost::is_constructible<
- T1,
- T2
- >,
- boost::is_constructible<
- T1,
- typename boost::add_lvalue_reference<T2>::type
- >
- >
- {};
- template <class T, class Types>
- struct is_variant_constructible_from:
- boost::mpl::not_< boost::is_same<
- typename boost::mpl::find_if<
- Types,
- is_constructible_ext<boost::mpl::_1, T>
- >::type,
- typename boost::mpl::end<Types>::type
- > >
- {};
- template <BOOST_VARIANT_ENUM_PARAMS(typename T), class Types>
- struct is_variant_constructible_from< boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Types >:
- boost::is_same<
- typename boost::mpl::find_if<
- typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::recursive_enabled_types,
- mpl::not_< is_variant_constructible_from< boost::mpl::_1, Types> >
- >::type,
- typename boost::mpl::end< typename boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>::recursive_enabled_types >::type
- >
- {};
- template <BOOST_VARIANT_ENUM_PARAMS(typename T), class Types>
- struct is_variant_constructible_from< const boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>& , Types >:
- is_variant_constructible_from<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Types >
- {};
- template <BOOST_VARIANT_ENUM_PARAMS(typename T), class Types>
- struct is_variant_constructible_from< boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>& , Types >:
- is_variant_constructible_from<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Types >
- {};
- #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- template <BOOST_VARIANT_ENUM_PARAMS(typename T), class Types>
- struct is_variant_constructible_from< boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>&& , Types >:
- is_variant_constructible_from<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Types >
- {};
- template <BOOST_VARIANT_ENUM_PARAMS(typename T), class Types>
- struct is_variant_constructible_from< boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const && , Types >:
- is_variant_constructible_from<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Types >
- {};
- #endif
- template <typename Types, typename NeverUsesBackupFlag>
- struct make_storage
- {
- private:
- typedef typename mpl::eval_if<
- NeverUsesBackupFlag
- , mpl::identity< Types >
- , mpl::push_front<
- Types, backup_holder<void*>
- >
- >::type types;
- typedef typename max_value<
- types, mpl::sizeof_<mpl::_1>
- >::type max_size;
- #if !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x0551))
- typedef typename mpl::fold<
- types
- , mpl::size_t<1>
- , add_alignment
- >::type max_alignment;
- #else
-
- typedef mpl::size_t< -1 > max_alignment;
- #endif
- public:
- typedef ::boost::aligned_storage<
- BOOST_MPL_AUX_VALUE_WKND(max_size)::value
- , BOOST_MPL_AUX_VALUE_WKND(max_alignment)::value
- > type;
- };
- struct destroyer
- : public static_visitor<>
- {
- public:
- template <typename T>
- void internal_visit(T& operand, int) const BOOST_NOEXCEPT
- {
- operand.~T();
- #if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x0551)) || \
- BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
- (void)operand;
- #endif
- }
- };
- template <typename T>
- class known_get
- : public static_visitor<T&>
- {
- public:
- T& operator()(T& operand) const BOOST_NOEXCEPT
- {
- return operand;
- }
- template <typename U>
- T& operator()(U&) const
- {
-
- return ::boost::detail::variant::forced_return< T& >();
- }
- };
- class copy_into
- : public static_visitor<>
- {
- private:
- void* storage_;
- public:
- explicit copy_into(void* storage) BOOST_NOEXCEPT
- : storage_(storage)
- {
- }
- public:
- template <typename T>
- void internal_visit(boost::detail::variant::backup_holder<T>& operand, long) const
- {
- new(storage_) T( operand.get() );
- }
- template <typename T>
- void internal_visit(const boost::detail::variant::backup_holder<T>& operand, long) const
- {
- new(storage_) T( operand.get() );
- }
- template <typename T>
- void internal_visit(const T& operand, int) const
- {
- new(storage_) T(operand);
- }
- };
- #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- class move_into
- : public static_visitor<>
- {
- private:
- void* storage_;
- public:
- explicit move_into(void* storage) BOOST_NOEXCEPT
- : storage_(storage)
- {
- }
- public:
- template <typename T>
- void internal_visit(boost::detail::variant::backup_holder<T>& operand, long) const
- {
- new(storage_) T( ::boost::detail::variant::move(operand.get()) );
- }
- template <typename T>
- void internal_visit(T& operand, int) const BOOST_NOEXCEPT_IF(BOOST_NOEXCEPT_EXPR(T(boost::declval<T>())))
- {
- new(storage_) T(::boost::detail::variant::move(operand));
- }
- };
- #endif
- struct assign_storage
- : public static_visitor<>
- {
- private:
- const void* rhs_storage_;
- public:
- explicit assign_storage(const void* rhs_storage) BOOST_NOEXCEPT
- : rhs_storage_(rhs_storage)
- {
- }
- public:
- template <typename T>
- void internal_visit(backup_holder<T>& lhs_content, long) const
- {
- lhs_content.get()
- = static_cast< const backup_holder<T>* >(rhs_storage_)->get();
- }
- template <typename T>
- void internal_visit(const backup_holder<T>& lhs_content, long) const
- {
- lhs_content.get()
- = static_cast< const backup_holder<T>* >(rhs_storage_)->get();
- }
- template <typename T>
- void internal_visit(T& lhs_content, int) const
- {
-
-
-
-
-
-
-
- lhs_content = *static_cast< const T* >(rhs_storage_);
- }
- };
- struct move_storage
- : public static_visitor<>
- {
- private:
- void* rhs_storage_;
- public:
- explicit move_storage(void* rhs_storage) BOOST_NOEXCEPT
- : rhs_storage_(rhs_storage)
- {
- }
- public:
- template <typename T>
- void internal_visit(backup_holder<T>& lhs_content, long) const
- {
- lhs_content.get()
- = ::boost::detail::variant::move(static_cast<backup_holder<T>* >(rhs_storage_)->get());
- }
- template <typename T>
- void internal_visit(const backup_holder<T>& lhs_content, long) const
- {
- lhs_content.get()
- = ::boost::detail::variant::move(static_cast<backup_holder<T>* >(rhs_storage_)->get());
- }
- template <typename T>
- void internal_visit(T& lhs_content, int) const
- {
-
-
-
-
-
-
-
- lhs_content = ::boost::detail::variant::move(*static_cast<T* >(rhs_storage_));
- }
- };
- template <typename T>
- class direct_assigner
- : public static_visitor<bool>
- {
- private:
- const T& rhs_;
- public:
- explicit direct_assigner(const T& rhs) BOOST_NOEXCEPT
- : rhs_(rhs)
- {
- }
- public:
- bool operator()(T& lhs)
- {
- lhs = rhs_;
- return true;
- }
- template <typename U>
- bool operator()(U&) BOOST_NOEXCEPT
- {
- return false;
- }
- #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
- private:
-
- direct_assigner& operator= (direct_assigner const&);
- #endif
- };
- template <typename T>
- class direct_mover
- : public static_visitor<bool>
- {
- private:
- T& rhs_;
- public:
- explicit direct_mover(T& rhs) BOOST_NOEXCEPT
- : rhs_(rhs)
- {
- }
- public:
- bool operator()(T& lhs)
- {
- lhs = ::boost::detail::variant::move(rhs_);
- return true;
- }
- template <typename U>
- bool operator()(U&) BOOST_NOEXCEPT
- {
- return false;
- }
- #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
- private:
-
- direct_mover& operator= (direct_mover const&);
- #endif
- };
- template <typename Variant>
- class backup_assigner
- : public static_visitor<>
- {
- private:
- Variant& lhs_;
- int rhs_which_;
- const void* rhs_content_;
- void (*copy_rhs_content_)(void*, const void*);
- public:
- template<class RhsT>
- backup_assigner(Variant& lhs, int rhs_which, const RhsT& rhs_content)
- : lhs_(lhs)
- , rhs_which_(rhs_which)
- , rhs_content_(&rhs_content)
- , copy_rhs_content_(&construct_impl<RhsT>)
- {
- }
- private:
- template<class RhsT>
- static void construct_impl(void* addr, const void* obj)
- {
- new(addr) RhsT(*static_cast<const RhsT*>(obj));
- }
- template <typename LhsT>
- void backup_assign_impl(
- backup_holder<LhsT>& lhs_content
- , mpl::false_
- , long
- )
- {
-
- backup_holder<LhsT> backup_lhs_content(0);
- backup_lhs_content.swap(lhs_content);
-
- lhs_content.~backup_holder<LhsT>();
- BOOST_TRY
- {
-
- copy_rhs_content_(lhs_.storage_.address(), rhs_content_);
- }
- BOOST_CATCH (...)
- {
-
- new(lhs_.storage_.address())
- backup_holder<LhsT>( 0 );
- static_cast<backup_holder<LhsT>* >(lhs_.storage_.address())
- ->swap(backup_lhs_content);
-
- BOOST_RETHROW;
- }
- BOOST_CATCH_END
-
- lhs_.indicate_which(rhs_which_);
- }
- template <typename LhsT>
- void backup_assign_impl(
- LhsT& lhs_content
- , mpl::true_
- , int
- )
- {
-
- LhsT backup_lhs_content(
- ::boost::detail::variant::move(lhs_content)
- );
-
- lhs_content.~LhsT();
- BOOST_TRY
- {
-
- copy_rhs_content_(lhs_.storage_.address(), rhs_content_);
- }
- BOOST_CATCH (...)
- {
-
- new(lhs_.storage_.address())
- LhsT(
- ::boost::detail::variant::move(backup_lhs_content)
- );
-
- BOOST_RETHROW;
- }
- BOOST_CATCH_END
-
- lhs_.indicate_which(rhs_which_);
- }
- template <typename LhsT>
- void backup_assign_impl(
- LhsT& lhs_content
- , mpl::false_
- , int
- )
- {
-
- LhsT* backup_lhs_ptr = new LhsT(lhs_content);
-
- lhs_content.~LhsT();
- BOOST_TRY
- {
-
- copy_rhs_content_(lhs_.storage_.address(), rhs_content_);
- }
- BOOST_CATCH (...)
- {
-
- new(lhs_.storage_.address())
- backup_holder<LhsT>( backup_lhs_ptr );
-
- lhs_.indicate_backup_which( lhs_.which() );
-
- BOOST_RETHROW;
- }
- BOOST_CATCH_END
-
- lhs_.indicate_which(rhs_which_);
-
- delete backup_lhs_ptr;
- }
- public:
- template <typename LhsT>
- void internal_visit(LhsT& lhs_content, int)
- {
- typedef typename is_nothrow_move_constructible<LhsT>::type
- nothrow_move;
- backup_assign_impl( lhs_content, nothrow_move(), 1L);
- }
- #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
- private:
-
- backup_assigner& operator= (backup_assigner const&);
- #endif
- };
- template <typename Variant>
- struct swap_with
- : public static_visitor<>
- {
- private:
- Variant& toswap_;
- public:
- explicit swap_with(Variant& toswap) BOOST_NOEXCEPT
- : toswap_(toswap)
- {
- }
- public:
- template <typename T>
- void operator()(T& operand) const
- {
-
- known_get<T> getter;
- T& other = toswap_.apply_visitor(getter);
-
- ::boost::detail::variant::move_swap( operand, other );
- }
- private:
- swap_with& operator=(const swap_with&);
- };
- class reflect
- : public static_visitor<const boost::typeindex::type_info&>
- {
- public:
- template <typename T>
- const boost::typeindex::type_info& operator()(const T&) const BOOST_NOEXCEPT
- {
- return boost::typeindex::type_id<T>().type_info();
- }
- };
- template <typename Variant, typename Comp>
- class comparer
- : public static_visitor<bool>
- {
- private:
- const Variant& lhs_;
- public:
- explicit comparer(const Variant& lhs) BOOST_NOEXCEPT
- : lhs_(lhs)
- {
- }
- public:
- template <typename T>
- bool operator()(T& rhs_content) const
- {
-
- known_get<T> getter;
- const T& lhs_content = lhs_.apply_visitor(getter);
-
- return Comp()(lhs_content, rhs_content);
- }
- private:
- comparer& operator=(const comparer&);
- };
- struct equal_comp
- {
- template <typename T>
- bool operator()(const T& lhs, const T& rhs) const
- {
- return lhs == rhs;
- }
- };
- struct less_comp
- {
- template <typename T>
- bool operator()(const T& lhs, const T& rhs) const
- {
- return lhs < rhs;
- }
- };
- ///////////////////////////////////////////////////////////////////////////////
- // (detail) class template invoke_visitor
- //
- // Internal visitor that invokes the given visitor using:
- // * for wrappers (e.g., recursive_wrapper), the wrapper's held value.
- // * for all other values, the value itself.
- //
- template <typename Visitor, bool MoveSemantics>
- class invoke_visitor
- {
- private:
- Visitor& visitor_;
- public:
- typedef typename Visitor::result_type
- result_type;
- public:
- explicit invoke_visitor(Visitor& visitor) BOOST_NOEXCEPT
- : visitor_(visitor)
- {
- }
- public:
- #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
-
- template <typename T>
- typename enable_if_c<MoveSemantics && is_same<T, T>::value, result_type>::type internal_visit(T&& operand, int)
- {
- return visitor_(::boost::move(operand));
- }
-
- template <typename T>
- typename disable_if_c<MoveSemantics && is_same<T, T>::value, result_type>::type internal_visit(T&& operand, int)
- {
- return visitor_(operand);
- }
- #else
- template <typename T>
- result_type internal_visit(T& operand, int)
- {
- return visitor_(operand);
- }
- # if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x0564))
- template <typename T>
- result_type internal_visit(const T& operand, int)
- {
- return visitor_(operand);
- }
- # endif
- #endif
- public:
- template <typename T>
- result_type internal_visit(boost::recursive_wrapper<T>& operand, long)
- {
- return internal_visit( operand.get(), 1L );
- }
- template <typename T>
- result_type internal_visit(const boost::recursive_wrapper<T>& operand, long)
- {
- return internal_visit( operand.get(), 1L );
- }
- template <typename T>
- result_type internal_visit(boost::detail::reference_content<T>& operand, long)
- {
- return internal_visit( operand.get(), 1L );
- }
- template <typename T>
- result_type internal_visit(const boost::detail::reference_content<T>& operand, long)
- {
- return internal_visit( operand.get(), 1L );
- }
- template <typename T>
- result_type internal_visit(boost::detail::variant::backup_holder<T>& operand, long)
- {
- return internal_visit( operand.get(), 1L );
- }
- template <typename T>
- result_type internal_visit(const boost::detail::variant::backup_holder<T>& operand, long)
- {
- return internal_visit( operand.get(), 1L );
- }
- #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
- private:
-
- invoke_visitor& operator= (invoke_visitor const&);
- #endif
- };
- }}
- template <
- typename T0_
- , BOOST_VARIANT_ENUM_SHIFTED_PARAMS(typename T)
- >
- class variant
- {
- private:
- typedef variant wknd_self_t;
- struct is_recursive_
- : detail::variant::is_recursive_flag<T0_>
- {
- };
- typedef typename mpl::eval_if<
- is_recursive_
- , T0_
- , mpl::identity< T0_ >
- >::type unwrapped_T0_;
- struct is_sequence_based_
- : detail::variant::is_over_sequence<unwrapped_T0_>
- {
- };
- #if !defined(BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT)
- private:
- typedef typename mpl::eval_if<
- is_sequence_based_
- , unwrapped_T0_ // over_sequence<...>::type
- , detail::variant::make_variant_list<
- unwrapped_T0_
- , BOOST_VARIANT_ENUM_SHIFTED_PARAMS(T)
- >
- >::type specified_types;
- BOOST_STATIC_ASSERT((
- ::boost::mpl::not_< mpl::empty<specified_types> >::value
- ));
- public:
- typedef typename mpl::eval_if<
- is_recursive_
- , mpl::transform<
- specified_types
- , mpl::protect<
- detail::variant::quoted_enable_recursive<wknd_self_t>
- >
- >
- , mpl::identity< specified_types >
- >::type recursive_enabled_types;
- typedef typename mpl::transform<
- recursive_enabled_types
- , unwrap_recursive<mpl::_1>
- >::type types;
- private:
- typedef typename mpl::transform<
- recursive_enabled_types
- , mpl::protect< detail::make_reference_content<> >
- >::type internal_types;
- typedef typename mpl::front<
- internal_types
- >::type internal_T0;
- #else
- private:
- typedef unwrapped_T0_ T0;
- #define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS(z,N,_) \
- typedef typename mpl::eval_if< \
- is_recursive_ \
- , detail::variant::enable_recursive< \
- BOOST_PP_CAT(T,N) \
- , wknd_self_t \
- > \
- , mpl::identity< BOOST_PP_CAT(T,N) > \
- >::type BOOST_PP_CAT(recursive_enabled_T,N); \
-
- BOOST_PP_REPEAT(
- BOOST_VARIANT_LIMIT_TYPES
- , BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS
- , _
- )
- #undef BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS
- #define BOOST_VARIANT_AUX_UNWRAP_RECURSIVE_TYPEDEFS(z,N,_) \
- typedef typename unwrap_recursive< \
- BOOST_PP_CAT(recursive_enabled_T,N) \
- >::type BOOST_PP_CAT(public_T,N); \
-
- BOOST_PP_REPEAT(
- BOOST_VARIANT_LIMIT_TYPES
- , BOOST_VARIANT_AUX_UNWRAP_RECURSIVE_TYPEDEFS
- , _
- )
- #undef BOOST_VARIANT_AUX_UNWRAP_RECURSIVE_TYPEDEFS
- public:
- typedef typename detail::variant::make_variant_list<
- BOOST_VARIANT_ENUM_PARAMS(public_T)
- >::type types;
- private:
- #define BOOST_VARIANT_AUX_MAKE_REFERENCE_CONTENT_TYPEDEFS(z,N,_) \
- typedef detail::make_reference_content< \
- BOOST_PP_CAT(recursive_enabled_T,N) \
- >::type BOOST_PP_CAT(internal_T,N); \
-
- BOOST_PP_REPEAT(
- BOOST_VARIANT_LIMIT_TYPES
- , BOOST_VARIANT_AUX_MAKE_REFERENCE_CONTENT_TYPEDEFS
- , _
- )
- #undef BOOST_VARIANT_AUX_MAKE_REFERENCE_CONTENT_TYPEDEFS
- private:
- typedef typename detail::variant::make_variant_list<
- BOOST_VARIANT_ENUM_PARAMS(internal_T)
- >::type internal_types;
- private:
-
-
-
- BOOST_MPL_ASSERT_NOT(( is_sequence_based_ ));
- #endif
- private:
- typedef typename detail::variant::find_fallback_type<
- internal_types
- >::type fallback_type_result_;
- typedef typename fallback_type_result_::first
- fallback_type_index_;
- typedef typename fallback_type_result_::second
- fallback_type_;
- struct has_fallback_type_
- : mpl::not_<
- is_same< fallback_type_, detail::variant::no_fallback_type >
- >
- {
- };
- typedef has_fallback_type_
- never_uses_backup_flag;
- typedef typename detail::variant::make_storage<
- internal_types, never_uses_backup_flag
- >::type storage_t;
- #ifndef BOOST_NO_CXX11_NOEXCEPT
- typedef typename detail::variant::is_variant_move_noexcept_constructible<
- internal_types
- > variant_move_noexcept_constructible;
- typedef typename detail::variant::is_variant_move_noexcept_assignable<
- internal_types
- > variant_move_noexcept_assignable;
- #endif
- private:
-
-
-
-
-
-
- #if !defined(BOOST_VARIANT_MINIMIZE_SIZE)
- typedef int which_t;
- #else
-
-
- typedef typename mpl::eval_if<
- mpl::equal_to< mpl::O1_size<internal_types>, mpl::long_<-1> >
- , mpl::identity< int >
- , mpl::if_<
- mpl::less< mpl::O1_size<internal_types>, mpl::int_<SCHAR_MAX> >
- , signed char
- , int
- >
- >::type which_t;
- #endif
- #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
- private:
- #else
- public:
- #endif
- which_t which_;
- storage_t storage_;
- void indicate_which(int which_arg) BOOST_NOEXCEPT
- {
- which_ = static_cast<which_t>( which_arg );
- }
- void indicate_backup_which(int which_arg) BOOST_NOEXCEPT
- {
- which_ = static_cast<which_t>( -(which_arg + 1) );
- }
- private:
- bool using_backup() const BOOST_NOEXCEPT
- {
- return which_ < 0;
- }
- public: // queries
- int which() const BOOST_NOEXCEPT
- {
- // If using heap backup...
- if (using_backup())
- // ...then return adjusted which_:
- return -(which_ + 1);
- // Otherwise, return which_ directly:
- return which_;
- }
- private: // helpers, for structors (below)
- struct initializer
- : BOOST_VARIANT_AUX_INITIALIZER_T(
- recursive_enabled_types, recursive_enabled_T
- )
- {
- };
- void destroy_content() BOOST_NOEXCEPT
- {
- detail::variant::destroyer visitor;
- this->internal_apply_visitor(visitor);
- }
- public:
- ~variant() BOOST_NOEXCEPT
- {
- destroy_content();
- }
- variant()
- #if !(defined(__SUNPRO_CC) && BOOST_WORKAROUND(__SUNPRO_CC, <= 0x5130))
- BOOST_NOEXCEPT_IF(boost::has_nothrow_constructor<internal_T0>::value)
- #endif
- {
- #ifdef _MSC_VER
- #pragma warning( push )
- #pragma warning( disable : 4345 )
- #endif
-
-
-
-
-
- new( storage_.address() ) internal_T0();
- indicate_which(0);
- #ifdef _MSC_VER
- #pragma warning( pop )
- #endif
- }
- private:
- class convert_copy_into
- : public static_visitor<int>
- {
- private:
- void* storage_;
- public:
- explicit convert_copy_into(void* storage) BOOST_NOEXCEPT
- : storage_(storage)
- {
- }
- public:
- template <typename T>
- int internal_visit(T& operand, int) const
- {
-
-
-
-
-
- return initializer::initialize(storage_, operand);
- }
- # if BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x0564))
- template <typename T>
- result_type internal_visit(const T& operand, int) const
- {
- return initializer::initialize(storage_, operand);
- }
- # endif
- template <typename T>
- int internal_visit(boost::detail::reference_content<T>& operand, long) const
- {
- return internal_visit( operand.get(), 1L );
- }
- template <typename T>
- int internal_visit(const boost::detail::reference_content<T>& operand, long) const
- {
- return internal_visit( operand.get(), 1L );
- }
- template <typename T>
- int internal_visit(boost::detail::variant::backup_holder<T>& operand, long) const
- {
- return internal_visit( operand.get(), 1L );
- }
- template <typename T>
- int internal_visit(const boost::detail::variant::backup_holder<T>& operand, long) const
- {
- return internal_visit( operand.get(), 1L );
- }
- template <typename T>
- int internal_visit(boost::recursive_wrapper<T>& operand, long) const
- {
- return internal_visit( operand.get(), 1L );
- }
- template <typename T>
- int internal_visit(const boost::recursive_wrapper<T>& operand, long) const
- {
- return internal_visit( operand.get(), 1L );
- }
- };
- friend class convert_copy_into;
- #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- class convert_move_into
- : public static_visitor<int>
- {
- private:
- void* storage_;
- public:
- explicit convert_move_into(void* storage) BOOST_NOEXCEPT
- : storage_(storage)
- {
- }
- public:
- template <typename T>
- int internal_visit(T& operand, int) const
- {
-
-
-
-
-
- return initializer::initialize(storage_, detail::variant::move(operand) );
- }
- template <typename T>
- int internal_visit(boost::detail::reference_content<T>& operand, long) const
- {
- return internal_visit( operand.get(), 1L );
- }
- template <typename T>
- int internal_visit(const boost::detail::reference_content<T>& operand, long) const
- {
- return internal_visit( operand.get(), 1L );
- }
- template <typename T>
- int internal_visit(boost::detail::variant::backup_holder<T>& operand, long) const
- {
- return internal_visit( operand.get(), 1L );
- }
- template <typename T>
- int internal_visit(const boost::detail::variant::backup_holder<T>& operand, long) const
- {
- return internal_visit( operand.get(), 1L );
- }
- template <typename T>
- int internal_visit(boost::recursive_wrapper<T>& operand, long) const
- {
- return internal_visit( operand.get(), 1L );
- }
- template <typename T>
- int internal_visit(const boost::recursive_wrapper<T>& operand, long) const
- {
- return internal_visit( operand.get(), 1L );
- }
- };
- friend class convert_move_into;
- #endif
- private:
- template <typename T>
- void convert_construct(
- T& operand
- , int
- , mpl::false_ = mpl::false_()
- )
- {
-
-
-
-
-
- indicate_which(
- initializer::initialize(
- storage_.address()
- , operand
- )
- );
- }
- #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- template <typename T>
- typename boost::enable_if<boost::is_rvalue_reference<T&&> >::type convert_construct(
- T&& operand
- , int
- , mpl::false_ = mpl::false_()
- )
- {
-
-
-
-
-
- indicate_which(
- initializer::initialize(
- storage_.address()
- , detail::variant::move(operand)
- )
- );
- }
- #endif
- template <typename Variant>
- void convert_construct(
- Variant& operand
- , long
- , mpl::true_
- )
- {
- convert_copy_into visitor(storage_.address());
- indicate_which(
- operand.internal_apply_visitor(visitor)
- );
- }
- #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- template <typename Variant>
- typename boost::enable_if<boost::is_rvalue_reference<Variant&&> >::type convert_construct(
- Variant&& operand
- , long
- , mpl::true_
- )
- {
- convert_move_into visitor(storage_.address());
- indicate_which(
- operand.internal_apply_visitor(visitor)
- );
- }
- #endif
- template <typename Variant>
- void convert_construct_variant(Variant& operand)
- {
-
-
-
- typedef typename mpl::find_if<
- types
- , is_same<
- add_const<mpl::_1>
- , const Variant
- >
- >::type found_it;
- typedef typename mpl::end<types>::type not_found;
- typedef typename is_same<
- found_it, not_found
- >::type is_foreign_variant;
-
- convert_construct(
- operand, 1L
- , is_foreign_variant()
- );
- }
- #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- template <typename Variant>
- typename boost::enable_if<boost::is_rvalue_reference<Variant&&> >::type convert_construct_variant(Variant&& operand)
- {
-
-
-
- typedef typename mpl::find_if<
- types
- , is_same<
- add_const<mpl::_1>
- , const Variant
- >
- >::type found_it;
- typedef typename mpl::end<types>::type not_found;
- typedef typename is_same<
- found_it, not_found
- >::type is_foreign_variant;
-
- convert_construct(
- detail::variant::move(operand), 1L
- , is_foreign_variant()
- );
- }
- #endif
- template <BOOST_VARIANT_ENUM_PARAMS(typename U)>
- typename boost::enable_if<mpl::or_<
- boost::is_same<boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>, variant>,
- boost::detail::variant::is_variant_constructible_from<boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>&, internal_types>
- > >::type convert_construct(
- boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>& operand
- , long
- )
- {
- convert_construct_variant(operand);
- }
- template <BOOST_VARIANT_ENUM_PARAMS(typename U)>
- typename boost::enable_if<mpl::or_<
- boost::is_same<boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>, variant>,
- boost::detail::variant::is_variant_constructible_from<const boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>&, internal_types>
- > >::type convert_construct(
- const boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>& operand
- , long
- )
- {
- convert_construct_variant(operand);
- }
- #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- template <BOOST_VARIANT_ENUM_PARAMS(typename U)>
- typename boost::enable_if<mpl::or_<
- boost::is_same<boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>, variant>,
- boost::detail::variant::is_variant_constructible_from<boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>&&, internal_types>
- > >::type convert_construct(
- boost::variant<BOOST_VARIANT_ENUM_PARAMS(U)>&& operand
- , long
- )
- {
- convert_construct_variant( detail::variant::move(operand) );
- }
- #endif
- public:
- template <typename T>
- variant(const T& operand,
- typename boost::enable_if<mpl::or_<
- mpl::and_<
- mpl::not_< boost::is_same<T, variant> >,
- boost::detail::variant::is_variant_constructible_from<const T&, internal_types>
- >,
- boost::is_same<T, boost::recursive_variant_> >,
- bool >::type = true)
- {
- convert_construct(operand, 1L);
- }
- template <typename T>
- variant(
- T& operand
- , typename boost::enable_if<mpl::or_<
- mpl::and_<
- mpl::not_< is_const<T> >,
- mpl::not_< boost::is_same<T, variant> >,
- boost::detail::variant::is_variant_constructible_from<T&, internal_types>
- >,
- boost::is_same<T, boost::recursive_variant_> >,
- bool >::type = true
- )
- {
- convert_construct(operand, 1L);
- }
- #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- template <class T>
- variant(T&& operand,
- typename boost::enable_if<mpl::or_<
- mpl::and_<
- boost::is_rvalue_reference<T&&>,
- mpl::not_< boost::is_const<T> >,
- mpl::not_< boost::is_same<T, variant> >,
- boost::detail::variant::is_variant_constructible_from<T&&, internal_types>
- >,
- boost::is_same<T, boost::recursive_variant_> >,
- bool >::type = true)
- {
- convert_construct( detail::variant::move(operand), 1L);
- }
- #endif
- public:
-
- variant(const variant& operand)
- {
-
- detail::variant::copy_into visitor( storage_.address() );
- operand.internal_apply_visitor(visitor);
-
- indicate_which(operand.which());
- }
- #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- variant(variant&& operand) BOOST_NOEXCEPT_IF(variant_move_noexcept_constructible::type::value)
- {
-
- detail::variant::move_into visitor( storage_.address() );
- operand.internal_apply_visitor(visitor);
-
- indicate_which(operand.which());
- }
- #endif
- private:
- # if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
- template <typename Variant>
- friend class detail::variant::backup_assigner;
- # endif
-
-
-
-
-
- class assigner
- : public static_visitor<>
- {
- protected:
- variant& lhs_;
- const int rhs_which_;
- public:
- assigner(variant& lhs, int rhs_which) BOOST_NOEXCEPT
- : lhs_(lhs)
- , rhs_which_(rhs_which)
- {
- }
- protected:
- template <typename RhsT, typename B1, typename B2>
- void assign_impl(
- const RhsT& rhs_content
- , mpl::true_
- , B1
- , B2
- ) const BOOST_NOEXCEPT
- {
-
- lhs_.destroy_content();
-
- new(lhs_.storage_.address())
- RhsT( rhs_content );
-
- lhs_.indicate_which(rhs_which_);
- }
- template <typename RhsT, typename B>
- void assign_impl(
- const RhsT& rhs_content
- , mpl::false_
- , mpl::true_
- , B
- ) const
- {
-
- RhsT temp(rhs_content);
-
- lhs_.destroy_content();
-
- new(lhs_.storage_.address())
- RhsT( detail::variant::move(temp) );
-
- lhs_.indicate_which(rhs_which_);
- }
- void construct_fallback() const BOOST_NOEXCEPT {
-
- new (lhs_.storage_.address())
- fallback_type_;
-
- lhs_.indicate_which(
- BOOST_MPL_AUX_VALUE_WKND(fallback_type_index_)::value
- );
- }
- template <typename RhsT>
- void assign_impl(
- const RhsT& rhs_content
- , mpl::false_
- , mpl::false_
- , mpl::true_
- ) const
- {
-
- lhs_.destroy_content();
- BOOST_TRY
- {
-
- new(lhs_.storage_.address())
- RhsT( rhs_content );
- }
- BOOST_CATCH (...)
- {
- construct_fallback();
-
- BOOST_RETHROW;
- }
- BOOST_CATCH_END
-
- lhs_.indicate_which(rhs_which_);
- }
- template <typename RhsT>
- void assign_impl(
- const RhsT& rhs_content
- , mpl::false_
- , mpl::false_
- , mpl::false_
- ) const
- {
- detail::variant::backup_assigner<wknd_self_t>
- visitor(lhs_, rhs_which_, rhs_content);
- lhs_.internal_apply_visitor(visitor);
- }
- public:
- template <typename RhsT>
- void internal_visit(const RhsT& rhs_content, int) const
- {
- typedef typename has_nothrow_copy<RhsT>::type
- nothrow_copy;
- typedef typename mpl::or_< // reduces compile-time
- nothrow_copy
- , is_nothrow_move_constructible<RhsT>
- >::type nothrow_move_constructor;
- assign_impl(
- rhs_content
- , nothrow_copy()
- , nothrow_move_constructor()
- , has_fallback_type_()
- );
- }
- #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
- private:
-
- assigner& operator= (assigner const&);
- #endif
- };
- friend class assigner;
- #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
-
-
-
-
-
- class move_assigner
- : public assigner
- {
- public:
- move_assigner(variant& lhs, int rhs_which) BOOST_NOEXCEPT
- : assigner(lhs, rhs_which)
- {
- }
- private:
- template <typename RhsT, typename B2>
- void assign_impl(
- RhsT& rhs_content
- , mpl::true_
- , mpl::false_
- , B2
- ) const BOOST_NOEXCEPT
- {
- assigner::assign_impl(rhs_content, mpl::true_(), mpl::false_(), B2());
- }
- template <typename RhsT, typename B, typename B2>
- void assign_impl(
- RhsT& rhs_content
- , B
- , mpl::true_
- , B2
- ) const BOOST_NOEXCEPT
- {
-
- assigner::lhs_.destroy_content();
-
- new(assigner::lhs_.storage_.address())
- RhsT( detail::variant::move(rhs_content) );
-
- assigner::lhs_.indicate_which(assigner::rhs_which_);
- }
- template <typename RhsT>
- void assign_impl(
- RhsT& rhs_content
- , mpl::false_
- , mpl::false_
- , mpl::true_
- ) const
- {
-
- assigner::lhs_.destroy_content();
- BOOST_TRY
- {
-
- new(assigner::lhs_.storage_.address())
- RhsT( detail::variant::move(rhs_content) );
- }
- BOOST_CATCH (...)
- {
- assigner::construct_fallback();
-
- BOOST_RETHROW;
- }
- BOOST_CATCH_END
-
- assigner::lhs_.indicate_which(assigner::rhs_which_);
- }
- template <typename RhsT>
- void assign_impl(
- RhsT& rhs_content
- , mpl::false_
- , mpl::false_
- , mpl::false_
- ) const
- {
- assigner::assign_impl(rhs_content, mpl::false_(), mpl::false_(), mpl::false_());
- }
- public:
- template <typename RhsT>
- void internal_visit(RhsT& rhs_content, int) const
- {
- typedef typename is_nothrow_move_constructible<RhsT>::type
- nothrow_move_constructor;
- typedef typename mpl::or_< // reduces compile-time
- nothrow_move_constructor
- , has_nothrow_copy<RhsT>
- >::type nothrow_copy;
- assign_impl(
- rhs_content
- , nothrow_copy()
- , nothrow_move_constructor()
- , has_fallback_type_()
- );
- }
- #if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
- private:
-
- move_assigner& operator= (move_assigner const&);
- #endif
- };
- friend class move_assigner;
- #endif
- void variant_assign(const variant& rhs)
- {
-
- if (which_ == rhs.which_)
- {
-
- detail::variant::assign_storage visitor(rhs.storage_.address());
- this->internal_apply_visitor(visitor);
- }
- else
- {
-
- assigner visitor(*this, rhs.which());
- rhs.internal_apply_visitor(visitor);
- }
- }
- #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- void variant_assign(variant&& rhs)
- {
-
- if (which_ == rhs.which_)
- {
-
- detail::variant::move_storage visitor(rhs.storage_.address());
- this->internal_apply_visitor(visitor);
- }
- else
- {
-
- move_assigner visitor(*this, rhs.which());
- rhs.internal_apply_visitor(visitor);
- }
- }
- #endif
- private:
- template <typename T>
- void assign(const T& rhs)
- {
-
- detail::variant::direct_assigner<T> direct_assign(rhs);
- if (this->apply_visitor(direct_assign) == false)
- {
-
-
-
-
-
-
- variant temp(rhs);
- variant_assign( detail::variant::move(temp) );
- }
- }
- #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- template <typename T>
- void move_assign(T&& rhs)
- {
-
- detail::variant::direct_mover<T> direct_move(rhs);
- if (this->apply_visitor(direct_move) == false)
- {
-
-
-
-
-
-
- variant temp( detail::variant::move(rhs) );
- variant_assign( detail::variant::move(temp) );
- }
- }
- #endif
- public:
- #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- template <class T>
- typename boost::enable_if<
- boost::mpl::and_<
- boost::is_rvalue_reference<T&&>,
- mpl::not_< boost::is_const<T> >,
- boost::detail::variant::is_variant_constructible_from<T&&, internal_types>
- >,
- variant&
- >::type operator=(T&& rhs)
- {
- move_assign( detail::variant::move(rhs) );
- return *this;
- }
- #endif
- template <typename T>
- typename boost::enable_if<
- mpl::or_<
- boost::is_same<T, variant>,
- boost::detail::variant::is_variant_constructible_from<const T&, internal_types>
- >,
- variant&
- >::type operator=(const T& rhs)
- {
- assign(rhs);
- return *this;
- }
-
- variant& operator=(const variant& rhs)
- {
- variant_assign(rhs);
- return *this;
- }
- #ifndef BOOST_NO_CXX11_RVALUE_REFERENCES
- variant& operator=(variant&& rhs)
- #if !defined(__GNUC__) || (__GNUC__ != 4) || (__GNUC_MINOR__ > 6) || defined(__clang__)
- BOOST_NOEXCEPT_IF(variant_move_noexcept_constructible::type::value && variant_move_noexcept_assignable::type::value)
- #endif
- {
- variant_assign( detail::variant::move(rhs) );
- return *this;
- }
- #endif
- void swap(variant& rhs)
- {
-
- if (which() == rhs.which())
- {
-
- detail::variant::swap_with<variant> visitor(rhs);
- this->apply_visitor(visitor);
- }
- else
- {
-
- variant tmp( detail::variant::move(rhs) );
- rhs = detail::variant::move(*this);
- *this = detail::variant::move(tmp);
- }
- }
- public:
-
-
-
- bool empty() const BOOST_NOEXCEPT
- {
- return false;
- }
- const boost::typeindex::type_info& type() const
- {
- detail::variant::reflect visitor;
- return this->apply_visitor(visitor);
- }
- public:
- template <typename U>
- void operator==(const U&) const
- {
- BOOST_STATIC_ASSERT( false && sizeof(U) );
- }
- template <typename U>
- void operator<(const U&) const
- {
- BOOST_STATIC_ASSERT( false && sizeof(U) );
- }
- template <typename U>
- void operator!=(const U&) const
- {
- BOOST_STATIC_ASSERT( false && sizeof(U) );
- }
- template <typename U>
- void operator>(const U&) const
- {
- BOOST_STATIC_ASSERT( false && sizeof(U) );
- }
- template <typename U>
- void operator<=(const U&) const
- {
- BOOST_STATIC_ASSERT( false && sizeof(U) );
- }
- template <typename U>
- void operator>=(const U&) const
- {
- BOOST_STATIC_ASSERT( false && sizeof(U) );
- }
- public:
-
- bool operator==(const variant& rhs) const
- {
- if (this->which() != rhs.which())
- return false;
- detail::variant::comparer<
- variant, detail::variant::equal_comp
- > visitor(*this);
- return rhs.apply_visitor(visitor);
- }
- bool operator<(const variant& rhs) const
- {
- //
- // Dirk Schreib suggested this collating order.
- //
- if (this->which() != rhs.which())
- return this->which() < rhs.which();
- detail::variant::comparer<
- variant, detail::variant::less_comp
- > visitor(*this);
- return rhs.apply_visitor(visitor);
- }
-
-
- inline bool operator!=(const variant& rhs) const
- {
- return !(*this == rhs);
- }
- inline bool operator>(const variant& rhs) const
- {
- return rhs < *this;
- }
- inline bool operator<=(const variant& rhs) const
- {
- return !(*this > rhs);
- }
- inline bool operator>=(const variant& rhs) const
- {
- return !(*this < rhs);
- }
- // helpers, for visitation support (below) -- private when possible
- #if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
- template < BOOST_VARIANT_ENUM_PARAMS(typename U) >
- friend class variant;
- private:
- #else
- public:
- #endif
- template <typename Visitor, typename VoidPtrCV>
- BOOST_FORCEINLINE static typename Visitor::result_type
- internal_apply_visitor_impl(
- int internal_which
- , int logical_which
- , Visitor& visitor
- , VoidPtrCV storage
- )
- {
- typedef mpl::int_<0> first_which;
- typedef typename mpl::begin<internal_types>::type first_it;
- typedef typename mpl::end<internal_types>::type last_it;
- typedef detail::variant::visitation_impl_step<
- first_it, last_it
- > first_step;
- return detail::variant::visitation_impl(
- internal_which, logical_which
- , visitor, storage, mpl::false_()
- , never_uses_backup_flag()
- , static_cast<first_which*>(0), static_cast<first_step*>(0)
- );
- }
- template <typename Visitor>
- BOOST_FORCEINLINE typename Visitor::result_type
- internal_apply_visitor(Visitor& visitor)
- {
- return internal_apply_visitor_impl(
- which_, which(), visitor, storage_.address()
- );
- }
- template <typename Visitor>
- BOOST_FORCEINLINE typename Visitor::result_type
- internal_apply_visitor(Visitor& visitor) const
- {
- return internal_apply_visitor_impl(
- which_, which(), visitor, storage_.address()
- );
- }
- public:
- #ifndef BOOST_NO_CXX11_REF_QUALIFIERS
- template <typename Visitor>
- typename Visitor::result_type
- apply_visitor(Visitor& visitor) &&
- {
- detail::variant::invoke_visitor<Visitor, true> invoker(visitor);
- return this->internal_apply_visitor(invoker);
- }
- template <typename Visitor>
- typename Visitor::result_type
- apply_visitor(Visitor& visitor) const&&
- {
- detail::variant::invoke_visitor<Visitor, true> invoker(visitor);
- return this->internal_apply_visitor(invoker);
- }
- #endif
- template <typename Visitor>
- typename Visitor::result_type
- apply_visitor(Visitor& visitor)
- #ifndef BOOST_NO_CXX11_REF_QUALIFIERS
- &
- #endif
- {
- detail::variant::invoke_visitor<Visitor, false> invoker(visitor);
- return this->internal_apply_visitor(invoker);
- }
- template <typename Visitor>
- typename Visitor::result_type
- apply_visitor(Visitor& visitor) const
- #ifndef BOOST_NO_CXX11_REF_QUALIFIERS
- &
- #endif
- {
- detail::variant::invoke_visitor<Visitor, false> invoker(visitor);
- return this->internal_apply_visitor(invoker);
- }
- };
- template <typename Types>
- struct make_variant_over
- {
- private:
- BOOST_STATIC_ASSERT(( ::boost::mpl::is_sequence<Types>::value ));
- typedef typename boost::mpl::insert_range<
- boost::mpl::list<>
- , boost::mpl::end< boost::mpl::list<> >::type
- , Types
- >::type copied_sequence_t;
- public:
- typedef variant<
- detail::variant::over_sequence<copied_sequence_t>
- > type;
- };
- template < BOOST_VARIANT_ENUM_PARAMS(typename T) >
- inline void swap(
- variant< BOOST_VARIANT_ENUM_PARAMS(T) >& lhs
- , variant< BOOST_VARIANT_ENUM_PARAMS(T) >& rhs
- )
- {
- lhs.swap(rhs);
- }
- }
- #if !defined(BOOST_NO_IOSTREAM)
- #include <boost/variant/detail/variant_io.hpp>
- #endif
- #endif
|