mirror of
https://github.com/boostorg/variant.git
synced 2026-07-23 14:03:43 +00:00
Compare commits
19 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4d3055a177 | |||
| 2a6c6f3948 | |||
| c13372a092 | |||
| 64d68fc379 | |||
| 19ba44bb3f | |||
| 4d02fbcd84 | |||
| 4f4555fa93 | |||
| e0151cc209 | |||
| 3bc66e9264 | |||
| aa1eeb3b0f | |||
| a400952c16 | |||
| dcc25e1a1d | |||
| c7d1cccc13 | |||
| 5edc863174 | |||
| d465155ccc | |||
| ddf192fc53 | |||
| de56bdaa0a | |||
| 2d1dea19ba | |||
| 39469616d2 |
+7
-1
@@ -1,5 +1,11 @@
|
||||
project boost/doc ;
|
||||
import boostbook : boostbook ;
|
||||
|
||||
boostbook variant-doc : variant.xml ;
|
||||
boostbook variant-doc
|
||||
:
|
||||
variant.xml
|
||||
:
|
||||
<xsl:param>boost.root=../../../..
|
||||
<format>pdf:<xsl:param>boost.url.prefix=http://www.boost.org/doc/libs/release/doc/html
|
||||
;
|
||||
|
||||
|
||||
@@ -136,7 +136,7 @@
|
||||
<rationale>
|
||||
<simpara>While visitation via
|
||||
<code><functionname>apply_visitor</functionname></code>
|
||||
is generally prefered due to its greater safety, <code>get</code> may
|
||||
is generally preferred due to its greater safety, <code>get</code> may
|
||||
may be more convenient in some cases due to its straightforward
|
||||
usage.</simpara>
|
||||
</rationale>
|
||||
|
||||
@@ -364,6 +364,11 @@
|
||||
</returns>
|
||||
|
||||
<throws>Will not throw.</throws>
|
||||
|
||||
<notes>
|
||||
<simpara>Not available when <code>BOOST_NO_TYPEID</code> is
|
||||
defined.</simpara>
|
||||
</notes>
|
||||
</method>
|
||||
|
||||
</method-group>
|
||||
@@ -536,6 +541,12 @@
|
||||
<simpara>Calls <code>out << x</code>, where <code>x</code> is
|
||||
the content of <code>rhs</code>.</simpara>
|
||||
</effects>
|
||||
|
||||
<notes>
|
||||
<simpara>Not available when <code>BOOST_NO_IOSTREAM</code> is
|
||||
defined.</simpara>
|
||||
</notes>
|
||||
|
||||
</function>
|
||||
|
||||
<class name="make_variant_over">
|
||||
|
||||
@@ -343,7 +343,7 @@ seq2.push_back(3.14);
|
||||
|
||||
are_strict_equals visitor;
|
||||
assert( std::equal(
|
||||
v1.begin(), v1.end(), v2.begin()
|
||||
seq1.begin(), seq1.end(), seq2.begin()
|
||||
, <functionname>boost::apply_visitor</functionname>( visitor )
|
||||
) );</programlisting>
|
||||
|
||||
|
||||
@@ -83,9 +83,9 @@ str += " world! ";</programlisting>
|
||||
|
||||
<programlisting>void times_two( boost::variant< int, std::string > & operand )
|
||||
{
|
||||
if ( int* pi = <functionname>boost::get</functionname><int>( &v ) )
|
||||
if ( int* pi = <functionname>boost::get</functionname><int>( &operand ) )
|
||||
*pi *= 2;
|
||||
else if ( std::string* pstr = <functionname>boost::get</functionname><std::string>( &v ) )
|
||||
else if ( std::string* pstr = <functionname>boost::get</functionname><std::string>( &operand ) )
|
||||
*pstr += *pstr;
|
||||
}</programlisting>
|
||||
|
||||
|
||||
+5
-10
@@ -21,16 +21,11 @@
|
||||
</copyright>
|
||||
|
||||
<legalnotice>
|
||||
<para>Permission to copy, use, sell and distribute this software
|
||||
is granted provided this copyright notice appears in all copies.
|
||||
Permission to modify the code and to distribute modified code is
|
||||
granted provided this copyright notice appears in all copies, and
|
||||
a notice that the code was modified is included with the copyright
|
||||
notice.</para>
|
||||
|
||||
<para> This software is provided "as is" without express or
|
||||
implied warranty, and with no claim as to its suitability for any
|
||||
purpose.</para>
|
||||
<para>Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file <filename>LICENSE_1_0.txt</filename> or copy at
|
||||
<ulink
|
||||
url="http://www.boost.org/LICENSE_1_0.txt">http://www.boost.org/LICENSE_1_0.txt</ulink>)
|
||||
</para>
|
||||
</legalnotice>
|
||||
|
||||
<librarypurpose>Safe, generic, stack-based discriminated union container</librarypurpose>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost variant.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
// See http://www.boost.org/libs/variant for documentation.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2003
|
||||
|
||||
@@ -19,7 +19,11 @@
|
||||
|
||||
#include "boost/variant/detail/apply_visitor_unary.hpp"
|
||||
|
||||
#if BOOST_WORKAROUND(__EDG__, BOOST_TESTED_AT(302))
|
||||
#include "boost/utility/enable_if.hpp"
|
||||
#include "boost/mpl/not.hpp"
|
||||
#include "boost/type_traits/is_const.hpp"
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
@@ -63,6 +67,9 @@ public: // visitor interfaces
|
||||
return visitor_(value1_, value2);
|
||||
}
|
||||
|
||||
private:
|
||||
apply_visitor_binary_invoke& operator=(const apply_visitor_binary_invoke&);
|
||||
|
||||
};
|
||||
|
||||
template <typename Visitor, typename Visitable2>
|
||||
@@ -100,6 +107,9 @@ public: // visitor interfaces
|
||||
return boost::apply_visitor(invoker, visitable2_);
|
||||
}
|
||||
|
||||
private:
|
||||
apply_visitor_binary_unwrap& operator=(const apply_visitor_binary_unwrap&);
|
||||
|
||||
};
|
||||
|
||||
}} // namespace detail::variant
|
||||
|
||||
@@ -58,7 +58,7 @@ public: // unary visitor interface
|
||||
|
||||
template <typename Visitable>
|
||||
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
|
||||
operator()(Visitable& visitable)
|
||||
operator()(Visitable& visitable) const
|
||||
{
|
||||
return apply_visitor(visitor_, visitable);
|
||||
}
|
||||
@@ -67,11 +67,14 @@ public: // binary visitor interface
|
||||
|
||||
template <typename Visitable1, typename Visitable2>
|
||||
BOOST_VARIANT_AUX_GENERIC_RESULT_TYPE(result_type)
|
||||
operator()(Visitable1& visitable1, Visitable2& visitable2)
|
||||
operator()(Visitable1& visitable1, Visitable2& visitable2) const
|
||||
{
|
||||
return apply_visitor(visitor_, visitable1, visitable2);
|
||||
}
|
||||
|
||||
private:
|
||||
apply_visitor_delayed_t& operator=(const apply_visitor_delayed_t&);
|
||||
|
||||
};
|
||||
|
||||
template <typename Visitor>
|
||||
|
||||
@@ -17,7 +17,11 @@
|
||||
#include "boost/detail/workaround.hpp"
|
||||
#include "boost/variant/detail/generic_result_type.hpp"
|
||||
|
||||
#if BOOST_WORKAROUND(__EDG__, BOOST_TESTED_AT(302))
|
||||
#include "boost/utility/enable_if.hpp"
|
||||
#include "boost/mpl/not.hpp"
|
||||
#include "boost/type_traits/is_const.hpp"
|
||||
#endif
|
||||
|
||||
namespace boost {
|
||||
|
||||
|
||||
@@ -64,6 +64,9 @@ public: // visitor interface
|
||||
out_ << operand;
|
||||
}
|
||||
|
||||
private:
|
||||
printer& operator=(const printer&);
|
||||
|
||||
};
|
||||
|
||||
}} // namespace detail::variant
|
||||
|
||||
@@ -35,6 +35,10 @@
|
||||
#include "boost/type_traits/has_nothrow_copy.hpp"
|
||||
#include "boost/variant/detail/has_nothrow_move.hpp"
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
# pragma warning (push)
|
||||
# pragma warning (disable : 4702) //unreachable code
|
||||
#endif
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// BOOST_VARIANT_VISITATION_UNROLLING_LIMIT
|
||||
@@ -163,7 +167,7 @@ visitation_impl_invoke(
|
||||
, has_nothrow_copy<T>
|
||||
>::type never_uses_backup;
|
||||
|
||||
return visitation_impl_invoke_impl(
|
||||
return (visitation_impl_invoke_impl)(
|
||||
internal_which, visitor, storage, t
|
||||
, never_uses_backup()
|
||||
);
|
||||
@@ -242,7 +246,7 @@ visitation_impl(
|
||||
// ...applying the appropriate case:
|
||||
# define BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_CASE(z, N, _) \
|
||||
case (Which::value + (N)): \
|
||||
return visitation_impl_invoke( \
|
||||
return (visitation_impl_invoke)( \
|
||||
internal_which, visitor, storage \
|
||||
, static_cast<BOOST_PP_CAT(T,N)*>(0) \
|
||||
, no_backup_flag, 1L \
|
||||
@@ -257,6 +261,7 @@ visitation_impl(
|
||||
|
||||
# undef BOOST_VARIANT_AUX_APPLY_VISITOR_STEP_CASE
|
||||
|
||||
default: BOOST_ASSERT(!"Boost.Variant internal error: 'which' out of range.");
|
||||
}
|
||||
|
||||
// If not handled in this iteration, continue unrolling:
|
||||
@@ -283,4 +288,8 @@ visitation_impl(
|
||||
}} // namespace detail::variant
|
||||
} // namespace boost
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400)
|
||||
# pragma warning(pop)
|
||||
#endif
|
||||
|
||||
#endif // BOOST_VARIANT_DETAIL_VISITATION_IMPL_HPP
|
||||
|
||||
@@ -21,15 +21,15 @@
|
||||
|
||||
#include "boost/mpl/aux_/lambda_arity_param.hpp"
|
||||
|
||||
#if !defined(BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT)
|
||||
# include "boost/mpl/eval_if.hpp"
|
||||
# include "boost/mpl/identity.hpp"
|
||||
# include "boost/mpl/protect.hpp"
|
||||
# include "boost/mpl/transform.hpp"
|
||||
#else
|
||||
# include "boost/preprocessor/cat.hpp"
|
||||
# include "boost/preprocessor/repeat.hpp"
|
||||
#endif
|
||||
#include "boost/mpl/equal.hpp"
|
||||
#include "boost/mpl/eval_if.hpp"
|
||||
#include "boost/mpl/identity.hpp"
|
||||
#include "boost/mpl/if.hpp"
|
||||
#include "boost/mpl/protect.hpp"
|
||||
#include "boost/mpl/transform.hpp"
|
||||
#include "boost/type_traits/is_same.hpp"
|
||||
#include "boost/preprocessor/cat.hpp"
|
||||
#include "boost/preprocessor/repeat.hpp"
|
||||
|
||||
#include "boost/mpl/bool.hpp"
|
||||
#include "boost/mpl/is_sequence.hpp"
|
||||
@@ -74,34 +74,48 @@ template <
|
||||
BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(typename Arity)
|
||||
>
|
||||
struct substitute<
|
||||
::boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >
|
||||
::boost::variant<
|
||||
::boost::detail::variant::over_sequence< T0 >
|
||||
, BOOST_VARIANT_ENUM_SHIFTED_PARAMS(T)
|
||||
>
|
||||
, RecursiveVariant
|
||||
, ::boost::recursive_variant_
|
||||
BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(Arity)
|
||||
>
|
||||
{
|
||||
private:
|
||||
|
||||
#if !defined(BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT)
|
||||
|
||||
private: // helpers, for metafunction result (below)
|
||||
|
||||
typedef typename mpl::eval_if<
|
||||
::boost::detail::variant::is_over_sequence<T0>
|
||||
, mpl::identity< T0 >
|
||||
, make_variant_list< BOOST_VARIANT_ENUM_PARAMS(T) >
|
||||
>::type initial_types;
|
||||
typedef T0 initial_types;
|
||||
|
||||
typedef typename mpl::transform<
|
||||
initial_types
|
||||
, mpl::protect< quoted_enable_recursive<RecursiveVariant,mpl::true_> >
|
||||
>::type types;
|
||||
|
||||
public: // metafunction result
|
||||
public:
|
||||
|
||||
typedef ::boost::variant< types > type;
|
||||
|
||||
#else // defined(BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT)
|
||||
typedef typename mpl::if_<
|
||||
mpl::equal<initial_types, types, ::boost::is_same<mpl::_1, mpl::_2> >
|
||||
, ::boost::variant<
|
||||
::boost::detail::variant::over_sequence< T0 >
|
||||
, BOOST_VARIANT_ENUM_SHIFTED_PARAMS(T)
|
||||
>
|
||||
, ::boost::variant< over_sequence<types> >
|
||||
>::type type;
|
||||
};
|
||||
|
||||
template <
|
||||
BOOST_VARIANT_ENUM_PARAMS(typename T)
|
||||
, typename RecursiveVariant
|
||||
BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(typename Arity)
|
||||
>
|
||||
struct substitute<
|
||||
::boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >
|
||||
, RecursiveVariant
|
||||
, ::boost::recursive_variant_
|
||||
BOOST_MPL_AUX_LAMBDA_ARITY_PARAM(Arity)
|
||||
>
|
||||
{
|
||||
private: // helpers, for metafunction result (below)
|
||||
|
||||
#define BOOST_VARIANT_AUX_ENABLE_RECURSIVE_TYPEDEFS(z,N,_) \
|
||||
@@ -123,9 +137,6 @@ private: // helpers, for metafunction result (below)
|
||||
public: // metafunction result
|
||||
|
||||
typedef ::boost::variant< BOOST_VARIANT_ENUM_PARAMS(wknd_T) > type;
|
||||
|
||||
#endif // BOOST_VARIANT_NO_TYPE_SEQUENCE_SUPPORT workaround
|
||||
|
||||
};
|
||||
|
||||
#else // defined(BOOST_VARIANT_DETAIL_NO_SUBSTITUTE)
|
||||
|
||||
@@ -15,7 +15,10 @@
|
||||
|
||||
#include <cstddef> // for std::size_t
|
||||
#include <new> // for placement new
|
||||
|
||||
#if !defined(BOOST_NO_TYPEID)
|
||||
#include <typeinfo> // for typeid, std::type_info
|
||||
#endif // BOOST_NO_TYPEID
|
||||
|
||||
#include "boost/variant/detail/config.hpp"
|
||||
#include "boost/mpl/aux_/config/eti.hpp"
|
||||
@@ -37,6 +40,7 @@
|
||||
#include "boost/detail/reference_content.hpp"
|
||||
#include "boost/aligned_storage.hpp"
|
||||
#include "boost/blank.hpp"
|
||||
#include "boost/math/common_factor_ct.hpp"
|
||||
#include "boost/static_assert.hpp"
|
||||
#include "boost/preprocessor/cat.hpp"
|
||||
#include "boost/preprocessor/repeat.hpp"
|
||||
@@ -50,11 +54,14 @@
|
||||
#include "boost/variant/recursive_wrapper_fwd.hpp"
|
||||
#include "boost/variant/static_visitor.hpp"
|
||||
|
||||
#include "boost/mpl/eval_if.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"
|
||||
@@ -65,7 +72,7 @@
|
||||
#include "boost/mpl/logical.hpp"
|
||||
#include "boost/mpl/max_element.hpp"
|
||||
#include "boost/mpl/next.hpp"
|
||||
#include "boost/mpl/deref.hpp"
|
||||
#include "boost/mpl/not.hpp"
|
||||
#include "boost/mpl/pair.hpp"
|
||||
#include "boost/mpl/protect.hpp"
|
||||
#include "boost/mpl/push_front.hpp"
|
||||
@@ -73,7 +80,6 @@
|
||||
#include "boost/mpl/size_t.hpp"
|
||||
#include "boost/mpl/sizeof.hpp"
|
||||
#include "boost/mpl/transform.hpp"
|
||||
#include "boost/mpl/assert.hpp"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Implementation Macros:
|
||||
@@ -126,6 +132,19 @@ public: // metafunction result
|
||||
|
||||
};
|
||||
|
||||
struct add_alignment
|
||||
{
|
||||
template <typename State, typename Item>
|
||||
struct apply
|
||||
: mpl::size_t<
|
||||
::boost::math::static_lcm<
|
||||
BOOST_MPL_AUX_VALUE_WKND(State)::value
|
||||
, ::boost::alignment_of<Item>::value
|
||||
>::value
|
||||
>
|
||||
{};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// (detail) metafunction find_fallback_type
|
||||
//
|
||||
@@ -230,8 +249,10 @@ private: // helpers, for metafunction result (below)
|
||||
|
||||
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0551))
|
||||
|
||||
typedef typename max_value<
|
||||
types, alignment_of<mpl::_1>
|
||||
typedef typename mpl::fold<
|
||||
types
|
||||
, mpl::size_t<1>
|
||||
, add_alignment
|
||||
>::type max_alignment;
|
||||
|
||||
#else // borland
|
||||
@@ -290,7 +311,8 @@ public: // visitor interfaces
|
||||
{
|
||||
operand.~T();
|
||||
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0551))
|
||||
#if BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x0551)) || \
|
||||
BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
|
||||
operand; // suppresses warnings
|
||||
#endif
|
||||
|
||||
@@ -477,11 +499,11 @@ class direct_assigner
|
||||
{
|
||||
private: // representation
|
||||
|
||||
T& rhs_;
|
||||
const T& rhs_;
|
||||
|
||||
public: // structors
|
||||
|
||||
explicit direct_assigner(T& rhs)
|
||||
explicit direct_assigner(const T& rhs)
|
||||
: rhs_(rhs)
|
||||
{
|
||||
}
|
||||
@@ -529,6 +551,11 @@ public: // visitor interface
|
||||
|
||||
#endif // MSVC6 workaround
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
|
||||
private:
|
||||
// silence MSVC warning C4512: assignment operator could not be generated
|
||||
direct_assigner& operator= (direct_assigner const&);
|
||||
#endif
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -540,7 +567,7 @@ public: // visitor interface
|
||||
// NOTE: This needs to be a friend of variant, as it needs access to
|
||||
// indicate_which, indicate_backup_which, etc.
|
||||
//
|
||||
template <typename Variant, typename RhsT>
|
||||
template <typename Variant>
|
||||
class backup_assigner
|
||||
: public static_visitor<>
|
||||
{
|
||||
@@ -548,19 +575,28 @@ private: // representation
|
||||
|
||||
Variant& lhs_;
|
||||
int rhs_which_;
|
||||
const RhsT& rhs_content_;
|
||||
const void* rhs_content_;
|
||||
void (*copy_rhs_content_)(void*, const void*);
|
||||
|
||||
public: // structors
|
||||
|
||||
template<class RhsT>
|
||||
backup_assigner(Variant& lhs, int rhs_which, const RhsT& rhs_content)
|
||||
: lhs_(lhs)
|
||||
, rhs_which_(rhs_which)
|
||||
, rhs_content_(rhs_content)
|
||||
, rhs_content_(&rhs_content)
|
||||
, copy_rhs_content_(&construct_impl<RhsT>)
|
||||
{
|
||||
}
|
||||
|
||||
private: // helpers, for visitor interface (below)
|
||||
|
||||
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(
|
||||
LhsT& lhs_content
|
||||
@@ -578,7 +614,7 @@ private: // helpers, for visitor interface (below)
|
||||
try
|
||||
{
|
||||
// ...and attempt to copy rhs content into lhs storage:
|
||||
new(lhs_.storage_.address()) RhsT(rhs_content_);
|
||||
copy_rhs_content_(lhs_.storage_.address(), rhs_content_);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -611,7 +647,7 @@ private: // helpers, for visitor interface (below)
|
||||
try
|
||||
{
|
||||
// ...and attempt to copy rhs content into lhs storage:
|
||||
new(lhs_.storage_.address()) RhsT(rhs_content_);
|
||||
copy_rhs_content_(lhs_.storage_.address(), rhs_content_);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
@@ -647,6 +683,11 @@ public: // visitor interface
|
||||
BOOST_VARIANT_AUX_RETURN_VOID;
|
||||
}
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
|
||||
private:
|
||||
// silence MSVC warning C4512: assignment operator could not be generated
|
||||
backup_assigner& operator= (backup_assigner const&);
|
||||
#endif
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -684,6 +725,9 @@ public: // internal visitor interfaces
|
||||
::boost::detail::variant::move_swap( operand, other );
|
||||
}
|
||||
|
||||
private:
|
||||
swap_with& operator=(const swap_with&);
|
||||
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -691,6 +735,9 @@ public: // internal visitor interfaces
|
||||
//
|
||||
// Generic static visitor that performs a typeid on the value it visits.
|
||||
//
|
||||
|
||||
#if !defined(BOOST_NO_TYPEID)
|
||||
|
||||
class reflect
|
||||
: public static_visitor<const std::type_info&>
|
||||
{
|
||||
@@ -704,6 +751,8 @@ public: // visitor interfaces
|
||||
|
||||
};
|
||||
|
||||
#endif // BOOST_NO_TYPEID
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// (detail) class comparer
|
||||
//
|
||||
@@ -740,6 +789,9 @@ public: // visitor interfaces
|
||||
return Comp()(lhs_content, rhs_content);
|
||||
}
|
||||
|
||||
private:
|
||||
comparer& operator=(const comparer&);
|
||||
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -891,6 +943,11 @@ public: // internal visitor interfaces, cont.
|
||||
return internal_visit( operand.get(), 1L );
|
||||
}
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
|
||||
private:
|
||||
// silence MSVC warning C4512: assignment operator could not be generated
|
||||
invoke_visitor& operator= (invoke_visitor const&);
|
||||
#endif
|
||||
};
|
||||
|
||||
}} // namespace detail::variant
|
||||
@@ -1112,14 +1169,14 @@ private: // helpers, for representation (below)
|
||||
which_t which_;
|
||||
storage_t storage_;
|
||||
|
||||
void indicate_which(int which)
|
||||
void indicate_which(int which_arg)
|
||||
{
|
||||
which_ = static_cast<which_t>( which );
|
||||
which_ = static_cast<which_t>( which_arg );
|
||||
}
|
||||
|
||||
void indicate_backup_which(int which)
|
||||
void indicate_backup_which(int which_arg)
|
||||
{
|
||||
which_ = static_cast<which_t>( -(which + 1) );
|
||||
which_ = static_cast<which_t>( -(which_arg + 1) );
|
||||
}
|
||||
|
||||
private: // helpers, for queries (below)
|
||||
@@ -1400,7 +1457,7 @@ public: // structors, cont.
|
||||
private: // helpers, for modifiers (below)
|
||||
|
||||
# if !defined(BOOST_NO_MEMBER_TEMPLATE_FRIENDS)
|
||||
template <typename Variant, typename RhsT>
|
||||
template <typename Variant>
|
||||
friend class detail::variant::backup_assigner;
|
||||
# endif
|
||||
|
||||
@@ -1513,7 +1570,7 @@ private: // helpers, for modifiers (below)
|
||||
, mpl::false_// has_fallback_type
|
||||
)
|
||||
{
|
||||
detail::variant::backup_assigner<wknd_self_t, RhsT>
|
||||
detail::variant::backup_assigner<wknd_self_t>
|
||||
visitor(lhs_, rhs_which_, rhs_content);
|
||||
lhs_.internal_apply_visitor(visitor);
|
||||
}
|
||||
@@ -1541,6 +1598,11 @@ private: // helpers, for modifiers (below)
|
||||
BOOST_VARIANT_AUX_RETURN_VOID;
|
||||
}
|
||||
|
||||
#if BOOST_WORKAROUND(BOOST_MSVC, BOOST_TESTED_AT(1600))
|
||||
private:
|
||||
// silence MSVC warning C4512: assignment operator could not be generated
|
||||
assigner& operator= (assigner const&);
|
||||
#endif
|
||||
};
|
||||
|
||||
friend class assigner;
|
||||
@@ -1568,7 +1630,7 @@ private: // helpers, for modifiers (below)
|
||||
void assign(const T& rhs)
|
||||
{
|
||||
// If direct T-to-T assignment is not possible...
|
||||
detail::variant::direct_assigner<const T> direct_assign(rhs);
|
||||
detail::variant::direct_assigner<T> direct_assign(rhs);
|
||||
if (this->apply_visitor(direct_assign) == false)
|
||||
{
|
||||
// ...then convert rhs to variant and assign:
|
||||
@@ -1627,11 +1689,13 @@ public: // queries
|
||||
return false;
|
||||
}
|
||||
|
||||
#if !defined(BOOST_NO_TYPEID)
|
||||
const std::type_info& type() const
|
||||
{
|
||||
detail::variant::reflect visitor;
|
||||
return this->apply_visitor(visitor);
|
||||
}
|
||||
#endif
|
||||
|
||||
public: // prevent comparison with foreign types
|
||||
|
||||
@@ -1823,6 +1887,9 @@ inline void swap(
|
||||
} // namespace boost
|
||||
|
||||
// implementation additions
|
||||
|
||||
#if !defined(BOOST_NO_IOSTREAM)
|
||||
#include "boost/variant/detail/variant_io.hpp"
|
||||
#endif // BOOST_NO_IOSTREAM
|
||||
|
||||
#endif // BOOST_VARIANT_VARIANT_HPP
|
||||
|
||||
@@ -229,7 +229,7 @@ template < BOOST_VARIANT_AUX_DECLARE_PARAMS > struct make_recursive_variant;
|
||||
// Tag type indicates where recursive variant substitution should occur.
|
||||
//
|
||||
#if !defined(BOOST_VARIANT_NO_FULL_RECURSIVE_VARIANT_SUPPORT)
|
||||
struct recursive_variant_;
|
||||
struct recursive_variant_ {};
|
||||
#else
|
||||
typedef mpl::arg<1> recursive_variant_;
|
||||
#endif
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
# Boost.Variant Library test Jamfile
|
||||
#
|
||||
# Copyright (C) 2003, Eric Friedman, Itay Maman.
|
||||
#
|
||||
# This material is provided "as is", with absolutely no warranty expressed
|
||||
# or implied. Any use is at your own risk.
|
||||
#
|
||||
# Permission to use or copy this software for any purpose is hereby granted
|
||||
# without fee, provided the above notices are retained on all copies.
|
||||
# Permission to modify the code and to distribute modified code is granted,
|
||||
# provided the above notices are retained, and a notice that the code was
|
||||
# modified is included with the above copyright notice.
|
||||
#
|
||||
|
||||
subproject libs/variant/test ;
|
||||
|
||||
# bring in rules for testing
|
||||
import testing ;
|
||||
|
||||
# Make tests run by default.
|
||||
DEPENDS all : test ;
|
||||
|
||||
{
|
||||
# look in BOOST_ROOT for sources first, just in this Jamfile
|
||||
local SEARCH_SOURCE = $(BOOST_ROOT) $(SEARCH_SOURCE) ;
|
||||
|
||||
test-suite variant
|
||||
:
|
||||
[ run libs/variant/test/test1.cpp libs/variant/test/class_a.cpp
|
||||
: : : : variant_test1 ]
|
||||
[ run libs/variant/test/test2.cpp
|
||||
: : : : variant_test2 ]
|
||||
[ run libs/variant/test/test3.cpp
|
||||
: : : : variant_test3 ]
|
||||
[ run libs/variant/test/test4.cpp libs/variant/test/class_a.cpp
|
||||
: : : : variant_test4 ]
|
||||
[ run libs/variant/test/test5.cpp
|
||||
: : : : variant_test5 ]
|
||||
[ run libs/variant/test/test6.cpp
|
||||
: : : : variant_test6 ]
|
||||
[ run libs/variant/test/test7.cpp
|
||||
: : : : variant_test7 ]
|
||||
[ run libs/variant/test/test8.cpp
|
||||
: : : : variant_test8 ]
|
||||
[ run libs/variant/test/recursive_variant_test.cpp ]
|
||||
[ run libs/variant/test/variant_reference_test.cpp ]
|
||||
[ run libs/variant/test/variant_comparison_test.cpp ]
|
||||
[ run libs/variant/test/variant_visit_test.cpp ]
|
||||
;
|
||||
}
|
||||
@@ -11,6 +11,11 @@
|
||||
# provided the above notices are retained, and a notice that the code was
|
||||
# modified is included with the above copyright notice.
|
||||
#
|
||||
project
|
||||
: requirements
|
||||
#<dependency>/boost/test//minimal
|
||||
<toolset>msvc:<asynch-exceptions>on
|
||||
;
|
||||
|
||||
test-suite variant
|
||||
:
|
||||
@@ -28,3 +33,5 @@ test-suite variant
|
||||
[ run variant_comparison_test.cpp ]
|
||||
[ run variant_visit_test.cpp ]
|
||||
;
|
||||
|
||||
|
||||
|
||||
+4
-23
@@ -232,29 +232,6 @@ struct int_adder : boost::static_visitor<>
|
||||
|
||||
|
||||
|
||||
|
||||
struct held_type_name : boost::static_visitor<std::string>
|
||||
{
|
||||
|
||||
template<typename T>
|
||||
std::string operator()(const T& ) const
|
||||
{
|
||||
ost_ << '[' << typeid(T).name() << ']';
|
||||
return result();
|
||||
}
|
||||
|
||||
std::string result() const
|
||||
{
|
||||
return ost_.str();
|
||||
}
|
||||
|
||||
mutable std::ostringstream ost_;
|
||||
|
||||
}; //held_type_name
|
||||
|
||||
|
||||
|
||||
|
||||
template<typename T>
|
||||
struct spec
|
||||
{
|
||||
@@ -267,7 +244,9 @@ inline void verify(VariantType& var, spec<S>, std::string str = "")
|
||||
const VariantType& cvar = var;
|
||||
|
||||
BOOST_CHECK(boost::apply_visitor(total_sizeof(), cvar) == sizeof(S));
|
||||
#if !defined(BOOST_NO_TYPEID)
|
||||
BOOST_CHECK(cvar.type() == typeid(S));
|
||||
#endif
|
||||
|
||||
//
|
||||
// Check get<>()
|
||||
@@ -316,7 +295,9 @@ inline void verify_not(VariantType& var, spec<S>)
|
||||
{
|
||||
const VariantType& cvar = var;
|
||||
|
||||
#if !defined(BOOST_NO_TYPEID)
|
||||
BOOST_CHECK(cvar.type() != typeid(S));
|
||||
#endif
|
||||
|
||||
//
|
||||
// Check get<>()
|
||||
|
||||
+181
-11
@@ -12,10 +12,13 @@
|
||||
|
||||
#include "boost/test/minimal.hpp"
|
||||
#include "boost/variant.hpp"
|
||||
#include "boost/mpl/vector.hpp"
|
||||
#include "boost/mpl/copy.hpp"
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
|
||||
struct vector_printer
|
||||
: boost::static_visitor<std::string>
|
||||
@@ -45,24 +48,191 @@ struct vector_printer
|
||||
}
|
||||
};
|
||||
|
||||
int test_main(int , char* [])
|
||||
void test_recursive_variant()
|
||||
{
|
||||
typedef boost::make_recursive_variant<
|
||||
int
|
||||
, std::vector<boost::recursive_variant_>
|
||||
>::type var_t;
|
||||
>::type var1_t;
|
||||
|
||||
std::vector<var_t> vec;
|
||||
vec.push_back(3);
|
||||
vec.push_back(5);
|
||||
vec.push_back(vec);
|
||||
vec.push_back(7);
|
||||
std::vector<var1_t> vec1;
|
||||
vec1.push_back(3);
|
||||
vec1.push_back(5);
|
||||
vec1.push_back(vec1);
|
||||
vec1.push_back(7);
|
||||
|
||||
var_t var(vec);
|
||||
std::string result( boost::apply_visitor( vector_printer(), var ) );
|
||||
var1_t var1(vec1);
|
||||
std::string result1( boost::apply_visitor( vector_printer(), var1 ) );
|
||||
|
||||
std::cout << "result: " << result << '\n';
|
||||
BOOST_CHECK(result == "( 3 5 ( 3 5 ) 7 ) ");
|
||||
std::cout << "result1: " << result1 << '\n';
|
||||
BOOST_CHECK(result1 == "( 3 5 ( 3 5 ) 7 ) ");
|
||||
|
||||
typedef boost::make_recursive_variant<
|
||||
boost::variant<int, double>
|
||||
, std::vector<boost::recursive_variant_>
|
||||
>::type var2_t;
|
||||
|
||||
std::vector<var2_t> vec2;
|
||||
vec2.push_back(boost::variant<int, double>(3));
|
||||
vec2.push_back(boost::variant<int, double>(3.5));
|
||||
vec2.push_back(vec2);
|
||||
vec2.push_back(boost::variant<int, double>(7));
|
||||
|
||||
var2_t var2(vec2);
|
||||
std::string result2( boost::apply_visitor( vector_printer(), var2 ) );
|
||||
|
||||
std::cout << "result2: " << result2 << '\n';
|
||||
BOOST_CHECK(result2 == "( 3 3.5 ( 3 3.5 ) 7 ) ");
|
||||
|
||||
typedef boost::make_recursive_variant<
|
||||
int
|
||||
, std::vector<
|
||||
boost::variant<
|
||||
double
|
||||
, std::vector<boost::recursive_variant_>
|
||||
>
|
||||
>
|
||||
>::type var3_t;
|
||||
|
||||
typedef boost::variant<double, std::vector<var3_t> > var4_t;
|
||||
|
||||
std::vector<var3_t> vec3;
|
||||
vec3.push_back(3);
|
||||
vec3.push_back(5);
|
||||
std::vector<var4_t> vec4;
|
||||
vec4.push_back(3.5);
|
||||
vec4.push_back(vec3);
|
||||
vec3.push_back(vec4);
|
||||
vec3.push_back(7);
|
||||
|
||||
var4_t var4(vec3);
|
||||
std::string result3( boost::apply_visitor( vector_printer(), var4 ) );
|
||||
|
||||
std::cout << "result2: " << result3 << '\n';
|
||||
BOOST_CHECK(result3 == "( 3 5 ( 3.5 ( 3 5 ) ) 7 ) ");
|
||||
|
||||
typedef boost::make_recursive_variant<
|
||||
double,
|
||||
std::vector<var1_t>
|
||||
>::type var5_t;
|
||||
|
||||
std::vector<var5_t> vec5;
|
||||
vec5.push_back(3.5);
|
||||
vec5.push_back(vec1);
|
||||
vec5.push_back(17.25);
|
||||
|
||||
std::string result5( vector_printer()(vec5) );
|
||||
|
||||
std::cout << "result5: " << result5 << '\n';
|
||||
BOOST_CHECK(result5 == "( 3.5 ( 3 5 ( 3 5 ) 7 ) 17.25 ) ");
|
||||
|
||||
typedef boost::make_recursive_variant<
|
||||
int,
|
||||
std::map<int, boost::recursive_variant_>
|
||||
>::type var6_t;
|
||||
var6_t var6;
|
||||
}
|
||||
|
||||
void test_recursive_variant_over()
|
||||
{
|
||||
typedef boost::make_recursive_variant_over<
|
||||
boost::mpl::vector<
|
||||
int
|
||||
, std::vector<boost::recursive_variant_>
|
||||
>
|
||||
>::type var1_t;
|
||||
|
||||
std::vector<var1_t> vec1;
|
||||
vec1.push_back(3);
|
||||
vec1.push_back(5);
|
||||
vec1.push_back(vec1);
|
||||
vec1.push_back(7);
|
||||
|
||||
var1_t var1(vec1);
|
||||
std::string result1( boost::apply_visitor( vector_printer(), var1 ) );
|
||||
|
||||
std::cout << "result1: " << result1 << '\n';
|
||||
BOOST_CHECK(result1 == "( 3 5 ( 3 5 ) 7 ) ");
|
||||
|
||||
typedef boost::make_recursive_variant_over<
|
||||
boost::mpl::vector<
|
||||
boost::make_variant_over<boost::mpl::vector<int, double> >::type
|
||||
, std::vector<boost::recursive_variant_>
|
||||
>
|
||||
>::type var2_t;
|
||||
|
||||
std::vector<var2_t> vec2;
|
||||
vec2.push_back(boost::variant<int, double>(3));
|
||||
vec2.push_back(boost::variant<int, double>(3.5));
|
||||
vec2.push_back(vec2);
|
||||
vec2.push_back(boost::variant<int, double>(7));
|
||||
|
||||
var2_t var2(vec2);
|
||||
std::string result2( boost::apply_visitor( vector_printer(), var2 ) );
|
||||
|
||||
std::cout << "result2: " << result2 << '\n';
|
||||
BOOST_CHECK(result2 == "( 3 3.5 ( 3 3.5 ) 7 ) ");
|
||||
|
||||
typedef boost::make_recursive_variant_over<
|
||||
boost::mpl::vector<
|
||||
int
|
||||
, std::vector<
|
||||
boost::make_variant_over<
|
||||
boost::mpl::vector<
|
||||
double
|
||||
, std::vector<boost::recursive_variant_>
|
||||
>
|
||||
>::type
|
||||
>
|
||||
>
|
||||
>::type var3_t;
|
||||
|
||||
typedef boost::make_variant_over<
|
||||
boost::mpl::copy<
|
||||
boost::mpl::vector<
|
||||
double
|
||||
, std::vector<var3_t>
|
||||
>
|
||||
>::type
|
||||
>::type var4_t;
|
||||
|
||||
std::vector<var3_t> vec3;
|
||||
vec3.push_back(3);
|
||||
vec3.push_back(5);
|
||||
std::vector<var4_t> vec4;
|
||||
vec4.push_back(3.5);
|
||||
vec4.push_back(vec3);
|
||||
vec3.push_back(vec4);
|
||||
vec3.push_back(7);
|
||||
|
||||
var4_t var3(vec3);
|
||||
std::string result3( boost::apply_visitor( vector_printer(), var3 ) );
|
||||
|
||||
std::cout << "result2: " << result3 << '\n';
|
||||
BOOST_CHECK(result3 == "( 3 5 ( 3.5 ( 3 5 ) ) 7 ) ");
|
||||
|
||||
typedef boost::make_recursive_variant_over<
|
||||
boost::mpl::vector<
|
||||
double
|
||||
, std::vector<var1_t>
|
||||
>
|
||||
>::type var5_t;
|
||||
|
||||
std::vector<var5_t> vec5;
|
||||
vec5.push_back(3.5);
|
||||
vec5.push_back(vec1);
|
||||
vec5.push_back(17.25);
|
||||
|
||||
std::string result5( vector_printer()(vec5) );
|
||||
|
||||
std::cout << "result5: " << result5 << '\n';
|
||||
BOOST_CHECK(result5 == "( 3.5 ( 3 5 ( 3 5 ) 7 ) 17.25 ) ");
|
||||
}
|
||||
|
||||
int test_main(int , char* [])
|
||||
{
|
||||
test_recursive_variant();
|
||||
test_recursive_variant_over();
|
||||
|
||||
return boost::exit_success;
|
||||
}
|
||||
|
||||
@@ -10,6 +10,12 @@
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "boost/config.hpp"
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(disable:4244) // conversion from const int to const short
|
||||
#endif
|
||||
|
||||
#include "boost/test/minimal.hpp"
|
||||
#include "boost/variant.hpp"
|
||||
|
||||
|
||||
+7
-2
@@ -11,6 +11,11 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "boost/config.hpp"
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(disable:4244) // conversion from 'const int' to 'const short'
|
||||
#endif
|
||||
|
||||
#include "boost/test/minimal.hpp"
|
||||
#include "boost/variant.hpp"
|
||||
|
||||
@@ -38,10 +43,10 @@ struct short_string
|
||||
using std::strlen;
|
||||
#endif // BOOST_NO_STDC_NAMESPACE
|
||||
|
||||
size_t e_limit = this->e_limit; // avoid warnings on some compilers
|
||||
size_t limit = this->e_limit; // avoid warnings on some compilers
|
||||
size_t src_len = strlen(src);
|
||||
|
||||
len_ = (std::min)(src_len, e_limit-1);
|
||||
len_ = (std::min)(src_len, limit-1);
|
||||
std::copy(src, src + len_, buffer_);
|
||||
buffer_[len_] = '\0';
|
||||
}
|
||||
|
||||
@@ -122,7 +122,9 @@ int test_main(int, char* [])
|
||||
std::ostringstream e1_str;
|
||||
e1_str << e1;
|
||||
|
||||
#if !defined(BOOST_NO_TYPEID)
|
||||
BOOST_CHECK(e1.type() == typeid(Add));
|
||||
#endif
|
||||
BOOST_CHECK(e1_str.str() == "(13+((40+2)-(10+4)))");
|
||||
|
||||
//Evaluate expression
|
||||
|
||||
@@ -10,6 +10,12 @@
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "boost/config.hpp"
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(disable:4244) // conversion from 'const int' to 'const short'
|
||||
#endif
|
||||
|
||||
#include "boost/test/minimal.hpp"
|
||||
#include "boost/variant.hpp"
|
||||
|
||||
|
||||
@@ -10,6 +10,12 @@
|
||||
// accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
|
||||
#include "boost/config.hpp"
|
||||
|
||||
#ifdef BOOST_MSVC
|
||||
#pragma warning(disable:4244) // conversion from 'const int' to 'const short'
|
||||
#endif
|
||||
|
||||
#include "boost/test/minimal.hpp"
|
||||
#include "boost/variant.hpp"
|
||||
|
||||
@@ -197,6 +203,9 @@ public:
|
||||
|
||||
ValueType& expected_;
|
||||
|
||||
private:
|
||||
compare_helper& operator=(const compare_helper&);
|
||||
|
||||
};
|
||||
|
||||
template<typename VariantType, typename ExpectedType>
|
||||
|
||||
@@ -63,6 +63,7 @@ void check_fail(Variant& v)
|
||||
try
|
||||
{
|
||||
T& r = get<T>(v);
|
||||
(void)r; // suppress warning about r not being used
|
||||
BOOST_CHECK(false && &r); // should never reach
|
||||
}
|
||||
catch(boost::bad_get&)
|
||||
@@ -110,3 +111,4 @@ int test_main(int , char* [])
|
||||
|
||||
return boost::exit_success;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user