mirror of
https://github.com/boostorg/variant.git
synced 2026-07-22 13:53:38 +00:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1ec2a30fe8 | |||
| 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
|
||||
|
||||
@@ -72,6 +72,9 @@ public: // binary visitor interface
|
||||
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
|
||||
@@ -283,4 +287,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
|
||||
|
||||
@@ -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"
|
||||
@@ -53,6 +56,7 @@
|
||||
#include "boost/mpl/eval_if.hpp"
|
||||
#include "boost/mpl/begin_end.hpp"
|
||||
#include "boost/mpl/bool.hpp"
|
||||
#include "boost/mpl/not.hpp"
|
||||
#include "boost/mpl/empty.hpp"
|
||||
#include "boost/mpl/find_if.hpp"
|
||||
#include "boost/mpl/front.hpp"
|
||||
@@ -290,7 +294,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 +482,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 +534,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
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -647,6 +657,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 +699,9 @@ public: // internal visitor interfaces
|
||||
::boost::detail::variant::move_swap( operand, other );
|
||||
}
|
||||
|
||||
private:
|
||||
swap_with& operator=(const swap_with&);
|
||||
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -691,6 +709,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 +725,8 @@ public: // visitor interfaces
|
||||
|
||||
};
|
||||
|
||||
#endif // BOOST_NO_TYPEID
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// (detail) class comparer
|
||||
//
|
||||
@@ -740,6 +763,9 @@ public: // visitor interfaces
|
||||
return Comp()(lhs_content, rhs_content);
|
||||
}
|
||||
|
||||
private:
|
||||
comparer& operator=(const comparer&);
|
||||
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@@ -891,6 +917,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
|
||||
@@ -1541,6 +1572,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 +1604,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 +1663,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 +1861,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
|
||||
|
||||
@@ -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<>()
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -197,6 +197,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