1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311 |
- #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/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;
- };
- 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;
- };
- 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 >
- {};
- 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 >
- {};
- 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);
- }
- };
- 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));
- }
- };
- 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:
-
- template <typename T>
- typename enable_if_c<MoveSemantics && is_same<T, T>::value, result_type>::type internal_visit(T&& operand, int)
- {
- return visitor_(std::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);
- }
- 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_>
- {
- };
- 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;
- 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;
- 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;
- 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;
- 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;
- private:
- template <typename T>
- void convert_construct(
- T& operand
- , int
- , mpl::false_ = mpl::false_()
- )
- {
-
-
-
-
-
- indicate_which(
- initializer::initialize(
- storage_.address()
- , operand
- )
- );
- }
- 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)
- )
- );
- }
- template <typename Variant>
- void convert_construct(
- Variant& operand
- , long
- , mpl::true_
- )
- {
- convert_copy_into visitor(storage_.address());
- indicate_which(
- operand.internal_apply_visitor(visitor)
- );
- }
- 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)
- );
- }
- 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()
- );
- }
- 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()
- );
- }
- 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);
- }
- 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) );
- }
- 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);
- }
- 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);
- }
- public:
-
- variant(const variant& operand)
- {
-
- detail::variant::copy_into visitor( storage_.address() );
- operand.internal_apply_visitor(visitor);
-
- indicate_which(operand.which());
- }
- 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());
- }
- private:
- template <typename Variant>
- friend class detail::variant::backup_assigner;
-
-
-
-
-
- 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;
-
-
-
-
-
- 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;
- 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);
- }
- }
- 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);
- }
- }
- 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) );
- }
- }
- 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) );
- }
- }
- public:
- #if !BOOST_WORKAROUND(BOOST_CLANG_VERSION, BOOST_TESTED_AT(150000)) || BOOST_CXX_VERSION <= 202002L
- 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;
- }
- 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;
- }
- 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:
- 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);
- }
- template <typename Visitor>
- typename Visitor::result_type
- apply_visitor(Visitor& visitor) &
- {
- 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 &
- {
- 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
|