mirror of
https://github.com/boostorg/variant.git
synced 2026-02-12 12:42:08 +00:00
Migrated from Sandbox CVS.
[SVN r18578]
This commit is contained in:
39
include/boost/empty.hpp
Normal file
39
include/boost/empty.hpp
Normal file
@@ -0,0 +1,39 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost empty.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2003
|
||||
// Eric Friedman
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both the copyright notice and this permission notice appear in
|
||||
// supporting documentation. No representations are made about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
|
||||
#ifndef BOOST_EMPTY_HPP
|
||||
#define BOOST_EMPTY_HPP
|
||||
|
||||
#include "boost/config.hpp"
|
||||
#include "boost/mpl/bool.hpp"
|
||||
#include "boost/type_traits/is_pod.hpp"
|
||||
|
||||
namespace boost {
|
||||
|
||||
struct empty
|
||||
{
|
||||
};
|
||||
|
||||
template <>
|
||||
struct is_pod<empty>
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(bool, value = true);
|
||||
typedef mpl::bool_<value> type;
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_EMPTY_HPP
|
||||
114
include/boost/incomplete.hpp
Normal file
114
include/boost/incomplete.hpp
Normal file
@@ -0,0 +1,114 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost incomplete.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2002-2003
|
||||
// Eric Friedman, Itay Maman
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both the copyright notice and this permission notice appear in
|
||||
// supporting documentation. No representations are made about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
|
||||
#ifndef BOOST_INCOMPLETE_HPP
|
||||
#define BOOST_INCOMPLETE_HPP
|
||||
|
||||
#include "boost/incomplete_fwd.hpp"
|
||||
#include "boost/checked_delete.hpp"
|
||||
|
||||
namespace boost {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// class template incomplete
|
||||
//
|
||||
// Treats an incomplete type as a value type.
|
||||
//
|
||||
template <typename T>
|
||||
class incomplete
|
||||
{
|
||||
public: // representation
|
||||
|
||||
T* p_;
|
||||
|
||||
public: // structors
|
||||
|
||||
~incomplete();
|
||||
incomplete();
|
||||
|
||||
incomplete(const incomplete& operand);
|
||||
incomplete(const T& operand);
|
||||
|
||||
public: // modifiers
|
||||
|
||||
incomplete& operator=(incomplete rhs)
|
||||
{
|
||||
swap(rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
incomplete& operator=(const T& rhs)
|
||||
{
|
||||
incomplete temp(rhs);
|
||||
swap(temp);
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
void swap(incomplete& operand)
|
||||
{
|
||||
T* temp = operand.p_;
|
||||
operand.p_ = p_;
|
||||
p_ = temp;
|
||||
}
|
||||
|
||||
public: // queries
|
||||
|
||||
T& get() { return *get_pointer(); }
|
||||
const T& get() const { return *get_pointer(); }
|
||||
|
||||
T* get_pointer() { return p_; }
|
||||
const T* get_pointer() const { return p_; }
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
incomplete<T>::~incomplete()
|
||||
{
|
||||
boost::checked_delete(p_);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
incomplete<T>::incomplete()
|
||||
: p_(new T)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
incomplete<T>::incomplete(const incomplete& operand)
|
||||
: p_(new T( operand.get() ))
|
||||
{
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
incomplete<T>::incomplete(const T& operand)
|
||||
: p_(new T(operand))
|
||||
{
|
||||
}
|
||||
|
||||
// function template swap
|
||||
//
|
||||
// Swaps two incomplete<T> objects of the same type T.
|
||||
//
|
||||
template <typename T>
|
||||
inline void swap(incomplete<T>& lhs, incomplete<T>& rhs)
|
||||
{
|
||||
lhs.swap(rhs);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_INCOMPLETE_HPP
|
||||
31
include/boost/incomplete_fwd.hpp
Normal file
31
include/boost/incomplete_fwd.hpp
Normal file
@@ -0,0 +1,31 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost incomplete_fwd.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2002
|
||||
// Eric Friedman, Itay Maman
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both the copyright notice and this permission notice appear in
|
||||
// supporting documentation. No representations are made about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
|
||||
#ifndef BOOST_INCOMPLETE_FWD_HPP
|
||||
#define BOOST_INCOMPLETE_FWD_HPP
|
||||
|
||||
namespace boost {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// class template incomplete
|
||||
//
|
||||
// Treats an incomplete type as a value type.
|
||||
//
|
||||
template <typename T> class incomplete;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_INCOMPLETE_FWD_HPP
|
||||
30
include/boost/variant.hpp
Normal file
30
include/boost/variant.hpp
Normal file
@@ -0,0 +1,30 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost variant.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2003
|
||||
// Eric Friedman, Itay Maman
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both the copyright notice and this permission notice appear in
|
||||
// supporting documentation. No representations are made about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
|
||||
#ifndef BOOST_VARIANT_HPP
|
||||
#define BOOST_VARIANT_HPP
|
||||
|
||||
// variant "main"
|
||||
#include "boost/variant/variant_fwd.hpp"
|
||||
#include "boost/variant/variant.hpp"
|
||||
|
||||
// common applications
|
||||
#include "boost/variant/get.hpp"
|
||||
#include "boost/variant/apply_visitor.hpp"
|
||||
#include "boost/variant/static_visitor.hpp"
|
||||
#include "boost/variant/visitor_ptr.hpp"
|
||||
|
||||
#endif // BOOST_VARIANT_HPP
|
||||
24
include/boost/variant/apply_visitor.hpp
Normal file
24
include/boost/variant/apply_visitor.hpp
Normal file
@@ -0,0 +1,24 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost apply_visitor.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2003
|
||||
// Eric Friedman
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both the copyright notice and this permission notice appear in
|
||||
// supporting documentation. No representations are made about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
|
||||
#ifndef BOOST_APPLY_VISITOR_HPP
|
||||
#define BOOST_APPLY_VISITOR_HPP
|
||||
|
||||
#include "boost/variant/detail/apply_visitor_unary.hpp"
|
||||
#include "boost/variant/detail/apply_visitor_binary.hpp"
|
||||
#include "boost/variant/detail/apply_visitor_delayed.hpp"
|
||||
|
||||
#endif // BOOST_APPLY_VISITOR_HPP
|
||||
43
include/boost/variant/bad_visit.hpp
Normal file
43
include/boost/variant/bad_visit.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost visitor/bad_visit.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2002
|
||||
// Eric Friedman
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both the copyright notice and this permission notice appear in
|
||||
// supporting documentation. No representations are made about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
|
||||
#ifndef BOOST_VISITOR_BAD_VISIT_HPP
|
||||
#define BOOST_VISITOR_BAD_VISIT_HPP
|
||||
|
||||
#include <exception>
|
||||
|
||||
namespace boost {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// class bad_visit
|
||||
//
|
||||
// Exception thrown when a visitation attempt fails due to invalid
|
||||
// visited subtype or contents.
|
||||
//
|
||||
struct bad_visit
|
||||
: std::exception
|
||||
{
|
||||
public:
|
||||
virtual const char * what() const throw()
|
||||
{
|
||||
return "boost::bad_visit: "
|
||||
"failed visitation using boost::apply_visitor";
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_VISITOR_BAD_VISIT_HPP
|
||||
133
include/boost/variant/detail/apply_visitor_binary.hpp
Normal file
133
include/boost/variant/detail/apply_visitor_binary.hpp
Normal file
@@ -0,0 +1,133 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost variant/detail/apply_visitor_binary.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2002-2003
|
||||
// Eric Friedman
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both the copyright notice and this permission notice appear in
|
||||
// supporting documentation. No representations are made about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
|
||||
#ifndef BOOST_VARIANT_DETAIL_APPLY_VISITOR_BINARY_HPP
|
||||
#define BOOST_VARIANT_DETAIL_APPLY_VISITOR_BINARY_HPP
|
||||
|
||||
#include "boost/variant/detail/apply_visitor_unary.hpp"
|
||||
#include "boost/variant/detail/define_forwarding_func.hpp"
|
||||
|
||||
namespace boost {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// function template apply_visitor(visitor, visitable1, visitable2)
|
||||
//
|
||||
// Visits visitable1 and visitable2 such that their values (which we
|
||||
// shall call x and y, respectively) are used as arguments in the
|
||||
// expression visitor(x, y).
|
||||
//
|
||||
|
||||
namespace detail { namespace visitor {
|
||||
|
||||
template <typename Visitor, typename Value1>
|
||||
class binary_delay0
|
||||
{
|
||||
public:
|
||||
typedef typename Visitor::result_type
|
||||
result_type;
|
||||
|
||||
private:
|
||||
Visitor& visitor_;
|
||||
Value1& value1_;
|
||||
|
||||
public:
|
||||
binary_delay0(Visitor& visitor, Value1& value1)
|
||||
: visitor_(visitor)
|
||||
, value1_(value1)
|
||||
{
|
||||
}
|
||||
|
||||
template <typename Value0>
|
||||
result_type operator()(Value0& value0)
|
||||
{
|
||||
return visitor_(value0, value1_);
|
||||
}
|
||||
|
||||
template <typename Value0>
|
||||
result_type operator()(const Value0& value0)
|
||||
{
|
||||
return visitor_(value0, value1_);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Visitor, typename Visitable1>
|
||||
class binary_delay1
|
||||
{
|
||||
public:
|
||||
typedef typename Visitor::result_type
|
||||
result_type;
|
||||
|
||||
private:
|
||||
Visitor& visitor_;
|
||||
Visitable1& visitable1_;
|
||||
|
||||
public:
|
||||
binary_delay1(Visitor& visitor, Visitable1& visitable1)
|
||||
: visitor_(visitor)
|
||||
, visitable1_(visitable1)
|
||||
{
|
||||
}
|
||||
|
||||
# define BOOST_AUX_BINARY_VISITOR_DELAY1_FUNC_OPERATOR(CV__) \
|
||||
template <typename Visitable2> \
|
||||
result_type operator()(CV__ Visitable2& visitable2) \
|
||||
{ \
|
||||
binary_delay0< \
|
||||
Visitor \
|
||||
, CV__ Visitable2 \
|
||||
> delayer(visitor_, visitable2); \
|
||||
return boost::apply_visitor(delayer, visitable1_); \
|
||||
} \
|
||||
/**/
|
||||
|
||||
BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC(
|
||||
BOOST_AUX_BINARY_VISITOR_DELAY1_FUNC_OPERATOR
|
||||
, 1
|
||||
)
|
||||
|
||||
# undef BOOST_AUX_BINARY_VISITOR_DELAY1_FUNC_OPERATOR
|
||||
};
|
||||
|
||||
}} // namespace detail::visitor
|
||||
|
||||
#define BOOST_VARIANT_AUX_APPLY_VISITOR_BINARY(CV1__, CV2__, CV3__) \
|
||||
template <typename Visitor, typename Visitable1, typename Visitable2> \
|
||||
inline \
|
||||
typename Visitor::result_type \
|
||||
apply_visitor( \
|
||||
CV1__ Visitor& visitor \
|
||||
, CV2__ Visitable1& visitable1 \
|
||||
, CV3__ Visitable2& visitable2 \
|
||||
) \
|
||||
{ \
|
||||
detail::visitor::binary_delay1< \
|
||||
CV1__ Visitor \
|
||||
, CV2__ Visitable1 \
|
||||
> delayer(visitor, visitable1); \
|
||||
return boost::apply_visitor(delayer, visitable2); \
|
||||
} \
|
||||
/**/
|
||||
|
||||
BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC(
|
||||
BOOST_VARIANT_AUX_APPLY_VISITOR_BINARY
|
||||
, 3
|
||||
)
|
||||
|
||||
#undef BOOST_VARIANT_AUX_APPLY_VISITOR_BINARY
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_VARIANT_DETAIL_APPLY_VISITOR_BINARY_HPP
|
||||
110
include/boost/variant/detail/apply_visitor_delayed.hpp
Normal file
110
include/boost/variant/detail/apply_visitor_delayed.hpp
Normal file
@@ -0,0 +1,110 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost variant/detail/apply_visitor_delayed.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2002-2003
|
||||
// Eric Friedman
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both the copyright notice and this permission notice appear in
|
||||
// supporting documentation. No representations are made about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
|
||||
#ifndef BOOST_VISITOR_APPLY_VISITOR_DELAYED_HPP
|
||||
#define BOOST_VISITOR_APPLY_VISITOR_DELAYED_HPP
|
||||
|
||||
#include "boost/variant/detail/apply_visitor_unary.hpp"
|
||||
#include "boost/variant/detail/apply_visitor_binary.hpp"
|
||||
|
||||
#include "boost/variant/detail/define_forwarding_func.hpp"
|
||||
|
||||
namespace boost {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// function template apply_visitor(visitor)
|
||||
//
|
||||
// Returns a function object, overloaded for unary and binary usage, that
|
||||
// visits its arguments using visitor (or a copy of visitor) via
|
||||
// * apply_visitor( visitor, [argument] )
|
||||
// under unary invocation, or
|
||||
// * apply_visitor( visitor, [argument1], [argument2] )
|
||||
// under binary invocation.
|
||||
//
|
||||
// NOTE: Unlike other apply_visitor forms, the visitor object must be
|
||||
// non-const; this prevents user from giving temporary, to disastrous
|
||||
// effect (i.e., returned function object would have dead reference).
|
||||
//
|
||||
|
||||
template <typename Visitor>
|
||||
class apply_visitor_delayed_t
|
||||
{
|
||||
public: // typedefs
|
||||
|
||||
typedef typename Visitor::result_type
|
||||
result_type;
|
||||
|
||||
private: // representation
|
||||
|
||||
Visitor& visitor_;
|
||||
|
||||
public: // structors
|
||||
|
||||
explicit apply_visitor_delayed_t(Visitor& visitor)
|
||||
: visitor_(visitor)
|
||||
{
|
||||
}
|
||||
|
||||
public: // unary function operators
|
||||
|
||||
# define BOOST_AUX_APPLY_VISITOR_DELAYED_T_UNARY_FUNC_OPERATOR(CV__) \
|
||||
template <typename Visitable> \
|
||||
result_type operator()( \
|
||||
CV__ Visitable& visitable \
|
||||
) \
|
||||
{ \
|
||||
apply_visitor(visitor_, visitable); \
|
||||
} \
|
||||
/**/
|
||||
|
||||
BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC(
|
||||
BOOST_AUX_APPLY_VISITOR_DELAYED_T_UNARY_FUNC_OPERATOR
|
||||
, 1
|
||||
)
|
||||
|
||||
# undef BOOST_AUX_APPLY_VISITOR_DELAYED_T_UNARY_FUNC_OPERATOR
|
||||
|
||||
public: // binary function operators
|
||||
|
||||
# define BOOST_AUX_APPLY_VISITOR_DELAYED_T_BINARY_FUNC_OPERATOR(CV1__, CV2__) \
|
||||
template <typename Visitable1, typename Visitable2> \
|
||||
result_type operator()( \
|
||||
CV1__ Visitable1& visitable1 \
|
||||
, CV2__ Visitable2& visitable2 \
|
||||
) \
|
||||
{ \
|
||||
apply_visitor(visitor_, visitable1, visitable2); \
|
||||
} \
|
||||
/**/
|
||||
|
||||
BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC(
|
||||
BOOST_AUX_APPLY_VISITOR_DELAYED_T_BINARY_FUNC_OPERATOR
|
||||
, 2
|
||||
)
|
||||
|
||||
# undef BOOST_AUX_APPLY_VISITOR_DELAYED_T_BINARY_FUNC_OPERATOR
|
||||
|
||||
};
|
||||
|
||||
template <typename Visitor>
|
||||
inline apply_visitor_delayed_t<Visitor> apply_visitor(Visitor& visitor)
|
||||
{
|
||||
return apply_visitor_delayed_t<Visitor>(visitor);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_VISITOR_APPLY_VISITOR_DELAYED_HPP
|
||||
57
include/boost/variant/detail/apply_visitor_unary.hpp
Normal file
57
include/boost/variant/detail/apply_visitor_unary.hpp
Normal file
@@ -0,0 +1,57 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost variant/detail/apply_visitor_unary.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2002-2003
|
||||
// Eric Friedman
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both the copyright notice and this permission notice appear in
|
||||
// supporting documentation. No representations are made about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
|
||||
#ifndef BOOST_VARIANT_DETAIL_APPLY_VISITOR_UNARY_HPP
|
||||
#define BOOST_VARIANT_DETAIL_APPLY_VISITOR_UNARY_HPP
|
||||
|
||||
#include "boost/variant/detail/define_forwarding_func.hpp"
|
||||
|
||||
namespace boost {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// function template apply_visitor(visitor, variant)
|
||||
//
|
||||
// Visits visitable with visitor.
|
||||
//
|
||||
|
||||
#define BOOST_VARIANT_AUX_APPLY_VISITOR_FUNC(CV1_, CV2_) \
|
||||
template < \
|
||||
typename Visitor \
|
||||
, BOOST_PP_ENUM_PARAMS(BOOST_VARIANT_LIMIT_TYPES, typename T) \
|
||||
> \
|
||||
inline \
|
||||
typename Visitor::result_type \
|
||||
apply_visitor( \
|
||||
CV1_ Visitor& visitor \
|
||||
, CV2_ boost::variant< \
|
||||
BOOST_PP_ENUM_PARAMS(BOOST_VARIANT_LIMIT_TYPES, T) \
|
||||
>& var \
|
||||
) \
|
||||
{ \
|
||||
return var.apply_visitor(visitor); \
|
||||
} \
|
||||
/**/
|
||||
#
|
||||
BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC(
|
||||
BOOST_VARIANT_AUX_APPLY_VISITOR_FUNC
|
||||
, 2
|
||||
)
|
||||
#
|
||||
#undef BOOST_VARIANT_AUX_APPLY_VISITOR_FUNC
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_VARIANT_DETAIL_APPLY_VISITOR_UNARY_HPP
|
||||
98
include/boost/variant/detail/define_forwarding_func.hpp
Normal file
98
include/boost/variant/detail/define_forwarding_func.hpp
Normal file
@@ -0,0 +1,98 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost variant/detail/define_forwarding_func.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2002-2003
|
||||
// Eric Friedman
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both the copyright notice and this permission notice appear in
|
||||
// supporting documentation. No representations are made about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
|
||||
#ifndef BOOST_VARIANT_DETAIL_DEFINE_FORWARDING_FUNC_HPP
|
||||
#define BOOST_VARIANT_DETAIL_DEFINE_FORWARDING_FUNC_HPP
|
||||
|
||||
#include "boost/preprocessor/debug/assert.hpp"
|
||||
#include "boost/preprocessor/comparison/less_equal.hpp"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC
|
||||
|
||||
// 000
|
||||
// 001
|
||||
// 010
|
||||
// 011 'const pattern' follows binary addition...
|
||||
// 100 (TODO: generalize with preprocessor to N params)
|
||||
// 101
|
||||
// 110
|
||||
// 111
|
||||
|
||||
// support macros
|
||||
#define BOOST_VARIANT_AUX_NOTHING /**/
|
||||
|
||||
#if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
||||
|
||||
#define BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC_1(macro) \
|
||||
macro(BOOST_VARIANT_AUX_NOTHING) \
|
||||
macro(const) \
|
||||
/**/
|
||||
|
||||
#define BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC_2(macro) \
|
||||
macro(BOOST_VARIANT_AUX_NOTHING,BOOST_VARIANT_AUX_NOTHING) \
|
||||
macro(BOOST_VARIANT_AUX_NOTHING,const) \
|
||||
macro(const,BOOST_VARIANT_AUX_NOTHING) \
|
||||
macro(const,const) \
|
||||
/**/
|
||||
|
||||
#define BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC_3(macro) \
|
||||
macro(BOOST_VARIANT_AUX_NOTHING,BOOST_VARIANT_AUX_NOTHING,BOOST_VARIANT_AUX_NOTHING) \
|
||||
macro(BOOST_VARIANT_AUX_NOTHING,BOOST_VARIANT_AUX_NOTHING,const) \
|
||||
macro(BOOST_VARIANT_AUX_NOTHING,const,BOOST_VARIANT_AUX_NOTHING) \
|
||||
macro(BOOST_VARIANT_AUX_NOTHING,const,const) \
|
||||
macro(const,BOOST_VARIANT_AUX_NOTHING,BOOST_VARIANT_AUX_NOTHING) \
|
||||
macro(const,BOOST_VARIANT_AUX_NOTHING,const) \
|
||||
macro(const,const,BOOST_VARIANT_AUX_NOTHING) \
|
||||
macro(const,const,const) \
|
||||
/**/
|
||||
|
||||
#else // defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
|
||||
|
||||
#define BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC_1(macro) \
|
||||
macro(BOOST_VARIANT_AUX_NOTHING) \
|
||||
/**/
|
||||
|
||||
#define BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC_2(macro) \
|
||||
macro(BOOST_VARIANT_AUX_NOTHING,BOOST_VARIANT_AUX_NOTHING) \
|
||||
/**/
|
||||
|
||||
#define BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC_3(macro) \
|
||||
macro(BOOST_VARIANT_AUX_NOTHING,BOOST_VARIANT_AUX_NOTHING,BOOST_VARIANT_AUX_NOTHING) \
|
||||
/**/
|
||||
|
||||
#endif
|
||||
|
||||
#define BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC_IMPL_MAX 3
|
||||
#define BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC_IMPL_MAX_MSG \
|
||||
"current implementation of BOOST_DEFINE_FORWARDING_FUNC only supports 3 params"
|
||||
|
||||
// actual macro definition:
|
||||
#define BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC( macro , arg_count ) \
|
||||
BOOST_PP_ASSERT_MSG( \
|
||||
BOOST_PP_LESS_EQUAL( \
|
||||
arg_count \
|
||||
, BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC_IMPL_MAX \
|
||||
) \
|
||||
, BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC_IMPL_MAX_MSG \
|
||||
) \
|
||||
BOOST_PP_CAT( \
|
||||
BOOST_VARIANT_AUX_DEFINE_FORWARDING_FUNC_ \
|
||||
, arg_count \
|
||||
) (macro) \
|
||||
/**/
|
||||
|
||||
#endif // BOOST_VARIANT_DETAIL_DEFINE_FORWARDING_FUNC_HPP
|
||||
106
include/boost/variant/detail/has_nothrow_move.hpp
Normal file
106
include/boost/variant/detail/has_nothrow_move.hpp
Normal file
@@ -0,0 +1,106 @@
|
||||
|
||||
// (C) Copyright Eric Friedman 2002-2003.
|
||||
// Permission to copy, use, modify, sell and distribute this software is
|
||||
// granted provided this copyright notice appears in all copies. This software
|
||||
// is provided "as is" without express or implied warranty, and with no claim
|
||||
// as to its suitability for any purpose.
|
||||
//
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
#ifndef BOOST_VARIANT_DETAIL_HAS_NOTHROW_MOVE_HPP_INCLUDED
|
||||
#define BOOST_VARIANT_DETAIL_HAS_NOTHROW_MOVE_HPP_INCLUDED
|
||||
|
||||
#include "boost/variant/detail/has_trivial_move.hpp"
|
||||
#include "boost/type_traits/has_nothrow_copy.hpp"
|
||||
#include "boost/type_traits/has_nothrow_assign.hpp"
|
||||
|
||||
#include "boost/mpl/and.hpp"
|
||||
#include "boost/mpl/or.hpp"
|
||||
|
||||
// should be the last #include
|
||||
#include "boost/type_traits/detail/bool_trait_def.hpp"
|
||||
|
||||
namespace boost {
|
||||
namespace detail { namespace variant {
|
||||
|
||||
// TRAIT: has_nothrow_move
|
||||
|
||||
template <typename T>
|
||||
struct has_nothrow_move_impl
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
mpl::or_<
|
||||
has_trivial_move<T>
|
||||
, mpl::and_<
|
||||
has_nothrow_copy<T>
|
||||
, has_nothrow_assign<T>
|
||||
>
|
||||
>::type::value
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
BOOST_TT_AUX_BOOL_TRAIT_DEF1(
|
||||
has_nothrow_move
|
||||
, T
|
||||
, (::boost::detail::variant::has_nothrow_move_impl<T>::value)
|
||||
)
|
||||
|
||||
|
||||
// TRAIT: has_nothrow_move_constructor
|
||||
|
||||
template <typename T>
|
||||
struct has_nothrow_move_constructor_impl
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
mpl::or_<
|
||||
has_nothrow_move<T>
|
||||
, has_trivial_move_constructor<T>
|
||||
, has_nothrow_copy<T>
|
||||
>::type::value
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
BOOST_TT_AUX_BOOL_TRAIT_DEF1(
|
||||
has_nothrow_move_constructor
|
||||
, T
|
||||
, (::boost::detail::variant::has_nothrow_move_constructor_impl<T>::value)
|
||||
)
|
||||
|
||||
|
||||
// TRAIT: has_nothrow_move_assign
|
||||
|
||||
template <typename T>
|
||||
struct has_nothrow_move_assign_impl
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
mpl::or_<
|
||||
has_nothrow_move<T>
|
||||
, has_trivial_move_assign<T>
|
||||
, has_nothrow_assign<T>
|
||||
>::type::value
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
BOOST_TT_AUX_BOOL_TRAIT_DEF1(
|
||||
has_nothrow_move_assign
|
||||
, T
|
||||
, (::boost::detail::variant::has_nothrow_move_assign_impl<T>::value)
|
||||
)
|
||||
|
||||
}} // namespace detail::variant
|
||||
|
||||
BOOST_TT_AUX_TEMPLATE_ARITY_SPEC(1,::boost::detail::variant::has_nothrow_move)
|
||||
BOOST_TT_AUX_TEMPLATE_ARITY_SPEC(1,::boost::detail::variant::has_nothrow_move_constructor)
|
||||
BOOST_TT_AUX_TEMPLATE_ARITY_SPEC(1,::boost::detail::variant::has_nothrow_move_assign)
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#include "boost/type_traits/detail/bool_trait_undef.hpp"
|
||||
|
||||
#endif // BOOST_VARIANT_DETAIL_HAS_NOTHROW_MOVE_HPP_INCLUDED
|
||||
100
include/boost/variant/detail/has_trivial_move.hpp
Normal file
100
include/boost/variant/detail/has_trivial_move.hpp
Normal file
@@ -0,0 +1,100 @@
|
||||
|
||||
// (C) Copyright Eric Friedman 2002-2003.
|
||||
// Permission to copy, use, modify, sell and distribute this software is
|
||||
// granted provided this copyright notice appears in all copies. This software
|
||||
// is provided "as is" without express or implied warranty, and with no claim
|
||||
// as to its suitability for any purpose.
|
||||
//
|
||||
// See http://www.boost.org for most recent version including documentation.
|
||||
|
||||
#ifndef BOOST_VARIANT_DETAIL_HAS_TRIVIAL_MOVE_HPP_INCLUDED
|
||||
#define BOOST_VARIANT_DETAIL_HAS_TRIVIAL_MOVE_HPP_INCLUDED
|
||||
|
||||
#include "boost/type_traits/has_trivial_copy.hpp"
|
||||
#include "boost/type_traits/has_trivial_assign.hpp"
|
||||
|
||||
#include "boost/mpl/and.hpp"
|
||||
#include "boost/mpl/or.hpp"
|
||||
|
||||
// should be the last #include
|
||||
#include "boost/type_traits/detail/bool_trait_def.hpp"
|
||||
|
||||
namespace boost {
|
||||
namespace detail { namespace variant {
|
||||
|
||||
// TRAIT: has_trivial_move
|
||||
|
||||
template <typename T>
|
||||
struct has_trivial_move_impl
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
mpl::and_<
|
||||
has_trivial_copy<T>
|
||||
, has_trivial_assign<T>
|
||||
>::type::value
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
BOOST_TT_AUX_BOOL_TRAIT_DEF1(
|
||||
has_trivial_move
|
||||
, T
|
||||
, (::boost::detail::variant::has_trivial_move_impl<T>::value)
|
||||
)
|
||||
|
||||
|
||||
// TRAIT: has_trivial_move_constructor
|
||||
|
||||
template <typename T>
|
||||
struct has_trivial_move_constructor_impl
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
mpl::or_<
|
||||
has_trivial_move<T>
|
||||
, has_trivial_copy<T>
|
||||
>::type::value
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
BOOST_TT_AUX_BOOL_TRAIT_DEF1(
|
||||
has_trivial_move_constructor
|
||||
, T
|
||||
, (::boost::detail::variant::has_trivial_move_constructor_impl<T>::value)
|
||||
)
|
||||
|
||||
|
||||
// TRAIT: has_trivial_move_assign
|
||||
|
||||
template <typename T>
|
||||
struct has_trivial_move_assign_impl
|
||||
{
|
||||
BOOST_STATIC_CONSTANT(
|
||||
bool, value = (
|
||||
mpl::or_<
|
||||
has_trivial_move<T>
|
||||
, has_trivial_assign<T>
|
||||
>::type::value
|
||||
)
|
||||
);
|
||||
};
|
||||
|
||||
BOOST_TT_AUX_BOOL_TRAIT_DEF1(
|
||||
has_trivial_move_assign
|
||||
, T
|
||||
, (::boost::detail::variant::has_trivial_move_assign_impl<T>::value)
|
||||
)
|
||||
|
||||
}} // namespace detail::variant
|
||||
|
||||
BOOST_TT_AUX_TEMPLATE_ARITY_SPEC(1,::boost::detail::variant::has_trivial_move)
|
||||
BOOST_TT_AUX_TEMPLATE_ARITY_SPEC(1,::boost::detail::variant::has_trivial_move_constructor)
|
||||
BOOST_TT_AUX_TEMPLATE_ARITY_SPEC(1,::boost::detail::variant::has_trivial_move_assign)
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#include "boost/type_traits/detail/bool_trait_undef.hpp"
|
||||
|
||||
#endif // BOOST_VARIANT_DETAIL_HAS_TRIVIAL_MOVE_HPP_INCLUDED
|
||||
169
include/boost/variant/detail/move.hpp
Normal file
169
include/boost/variant/detail/move.hpp
Normal file
@@ -0,0 +1,169 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost variant/detail/move.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2002-2003
|
||||
// Eric Friedman
|
||||
//
|
||||
// See below original copyright by Andrei Alexandrescu.
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both the copyright notice and this permission notice appear in
|
||||
// supporting documentation. No representations are made about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
|
||||
#ifndef BOOST_VARIANT_DETAIL_MOVE_HPP
|
||||
#define BOOST_VARIANT_DETAIL_MOVE_HPP
|
||||
|
||||
#include <iterator> // for iterator_traits
|
||||
#include <new> // for placement new
|
||||
|
||||
#include "boost/config.hpp"
|
||||
#include "boost/detail/workaround.hpp"
|
||||
#include "boost/mpl/if.hpp"
|
||||
#include "boost/type_traits/is_base_and_derived.hpp"
|
||||
|
||||
namespace boost {
|
||||
namespace detail { namespace variant {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// forward declares
|
||||
//
|
||||
template <typename Deriving> class moveable;
|
||||
template <typename T> class move_source;
|
||||
template <typename T> class move_return;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// function template move
|
||||
//
|
||||
// Takes a T& and returns, if T derives moveable<T>, a move_source<T> for
|
||||
// the object; else, returns the T&.
|
||||
//
|
||||
|
||||
namespace detail {
|
||||
|
||||
// (detail) class template move
|
||||
//
|
||||
// Metafunction that, given moveable T, provides move_source<T>, else T&.
|
||||
//
|
||||
template <typename T>
|
||||
struct move_type
|
||||
{
|
||||
public: // metafunction result
|
||||
|
||||
typedef typename mpl::if_<
|
||||
is_base_and_derived<moveable<T>, T>
|
||||
, move_source<T>
|
||||
, T&
|
||||
>::type type;
|
||||
|
||||
};
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename T>
|
||||
inline
|
||||
typename detail::move_type<T>::type
|
||||
move(T& source)
|
||||
{
|
||||
typedef typename detail::move_type<T>::type
|
||||
move_t;
|
||||
|
||||
return move_t(source);
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// class template return_t
|
||||
//
|
||||
// Metafunction that, given moveable T, provides move_return<T>, else T.
|
||||
//
|
||||
template <typename T>
|
||||
struct return_t
|
||||
{
|
||||
public: // metafunction result
|
||||
|
||||
typedef typename mpl::if_<
|
||||
is_base_and_derived<moveable<T>, T>
|
||||
, move_return<T>
|
||||
, T
|
||||
>::type type;
|
||||
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// function template move_swap
|
||||
//
|
||||
// Swaps using Koenig lookup but falls back to move-swap for primitive
|
||||
// types and on non-conforming compilers.
|
||||
//
|
||||
|
||||
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP) \
|
||||
|| BOOST_WORKAROUND(__GNUC__, BOOST_TESTED_AT(2))
|
||||
|
||||
// [Indicate that move_swap by overload is disabled...]
|
||||
#define BOOST_NO_MOVE_SWAP_BY_OVERLOAD
|
||||
|
||||
// [...and provide straight swap-by-move implementation:]
|
||||
template <typename T>
|
||||
inline void move_swap(T& lhs, T& rhs)
|
||||
{
|
||||
T tmp( boost::detail::variant::move(lhs) );
|
||||
lhs = boost::detail::variant::move(rhs);
|
||||
rhs = boost::detail::variant::move(tmp);
|
||||
}
|
||||
|
||||
#else// !workaround
|
||||
|
||||
namespace detail { namespace move_swap {
|
||||
|
||||
template <typename T>
|
||||
inline void swap(T& lhs, T& rhs)
|
||||
{
|
||||
T tmp( boost::detail::variant::move(lhs) );
|
||||
lhs = boost::detail::variant::move(rhs);
|
||||
rhs = boost::detail::variant::move(tmp);
|
||||
}
|
||||
|
||||
}} // namespace detail::move_swap
|
||||
|
||||
template <typename T>
|
||||
inline void move_swap(T& lhs, T& rhs)
|
||||
{
|
||||
using detail::move_swap::swap;
|
||||
|
||||
swap(lhs, rhs);
|
||||
}
|
||||
|
||||
#endif // workaround
|
||||
|
||||
}} // namespace detail::variant
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_VARIANT_DETAIL_MOVE_HPP
|
||||
|
||||
|
||||
/* This file derivative of MoJO. Much thanks to Andrei for his initial work.
|
||||
* See <http://www.cuj.com/experts/2102/alexandr.htm> for information on MOJO.
|
||||
|
||||
* Original copyright -- on mojo.h -- follows:
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// MOJO: MOving Joint Objects
|
||||
// Copyright (c) 2002 by Andrei Alexandrescu
|
||||
//
|
||||
// Created by Andrei Alexandrescu
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software for any
|
||||
// purpose is hereby granted without fee, provided that the above copyright
|
||||
// notice appear in all copies and that both that copyright notice and this
|
||||
// permission notice appear in supporting documentation.
|
||||
// The author makes no representations about the suitability of this software
|
||||
// for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
*/
|
||||
130
include/boost/variant/get.hpp
Normal file
130
include/boost/variant/get.hpp
Normal file
@@ -0,0 +1,130 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost variant/get.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2003
|
||||
// Eric Friedman, Itay Maman
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both the copyright notice and this permission notice appear in
|
||||
// supporting documentation. No representations are made about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
|
||||
#ifndef BOOST_VARIANT_GET_HPP
|
||||
#define BOOST_VARIANT_GET_HPP
|
||||
|
||||
#include <exception>
|
||||
|
||||
#include "boost/preprocessor/enum_params.hpp"
|
||||
#include "boost/utility/addressof.hpp"
|
||||
#include "boost/variant/variant_fwd.hpp"
|
||||
|
||||
namespace boost {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// class bad_get
|
||||
//
|
||||
// The exception thrown in the event of a failed get of a value.
|
||||
//
|
||||
class bad_get
|
||||
: public std::exception
|
||||
{
|
||||
public: // std::exception implementation
|
||||
|
||||
virtual const char * what() const throw()
|
||||
{
|
||||
return "boost::bad_get: "
|
||||
"failed value get using boost::get";
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// function template get<T>
|
||||
//
|
||||
// Retrieves content of given variant object if content is of type T.
|
||||
// Otherwise: pointer ver. returns 0; reference ver. throws bad_get.
|
||||
//
|
||||
|
||||
namespace detail { namespace variant {
|
||||
|
||||
// (detail) class template get_visitor
|
||||
//
|
||||
// Generic static visitor that: if the value is of the specified type,
|
||||
// returns a pointer to the value it visits; else a null pointer.
|
||||
//
|
||||
template <typename T>
|
||||
struct get_visitor
|
||||
{
|
||||
public: // typedefs
|
||||
|
||||
typedef T* result_type;
|
||||
|
||||
public: // visitor interfaces
|
||||
|
||||
template <typename U>
|
||||
T* operator()(U&) const
|
||||
{
|
||||
return static_cast<T*>(0);
|
||||
}
|
||||
|
||||
T* operator()(T& operand) const
|
||||
{
|
||||
return boost::addressof(operand);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
}} // namespace detail::variant
|
||||
|
||||
template <typename U, BOOST_PP_ENUM_PARAMS(BOOST_VARIANT_LIMIT_TYPES, typename T) >
|
||||
inline U* get(
|
||||
boost::variant< BOOST_PP_ENUM_PARAMS(BOOST_VARIANT_LIMIT_TYPES, T) >* operand
|
||||
)
|
||||
{
|
||||
if (!operand) return static_cast<U*>(0);
|
||||
|
||||
detail::variant::get_visitor<U> v;
|
||||
return operand->apply_visitor(v);
|
||||
}
|
||||
|
||||
template <typename U, BOOST_PP_ENUM_PARAMS(BOOST_VARIANT_LIMIT_TYPES, typename T) >
|
||||
inline U* get(
|
||||
const boost::variant< BOOST_PP_ENUM_PARAMS(BOOST_VARIANT_LIMIT_TYPES, T) >* operand
|
||||
)
|
||||
{
|
||||
if (!operand) return static_cast<U*>(0);
|
||||
|
||||
detail::variant::get_visitor<U> v;
|
||||
return operand->apply_visitor(v);
|
||||
}
|
||||
|
||||
template <typename U, BOOST_PP_ENUM_PARAMS(BOOST_VARIANT_LIMIT_TYPES, typename T) >
|
||||
inline U& get(
|
||||
boost::variant< BOOST_PP_ENUM_PARAMS(BOOST_VARIANT_LIMIT_TYPES, T) >& operand
|
||||
)
|
||||
{
|
||||
U* result = get<U>(&operand);
|
||||
if (!result)
|
||||
throw bad_get();
|
||||
return *result;
|
||||
}
|
||||
|
||||
template <typename U, BOOST_PP_ENUM_PARAMS(BOOST_VARIANT_LIMIT_TYPES, typename T) >
|
||||
inline U& get(
|
||||
const boost::variant< BOOST_PP_ENUM_PARAMS(BOOST_VARIANT_LIMIT_TYPES, T) >& operand
|
||||
)
|
||||
{
|
||||
U* result = get<U>(&operand);
|
||||
if (!result)
|
||||
throw bad_get();
|
||||
return *result;
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_VARIANT_GET_HPP
|
||||
73
include/boost/variant/static_visitor.hpp
Normal file
73
include/boost/variant/static_visitor.hpp
Normal file
@@ -0,0 +1,73 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost visitor/static_visitor.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2002-2003
|
||||
// Eric Friedman
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both the copyright notice and this permission notice appear in
|
||||
// supporting documentation. No representations are made about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
|
||||
#ifndef BOOST_STATIC_VISITOR_HPP
|
||||
#define BOOST_STATIC_VISITOR_HPP
|
||||
|
||||
#include "boost/config.hpp"
|
||||
#include "boost/type_traits/is_base_and_derived.hpp"
|
||||
|
||||
#include "boost/mpl/aux_/lambda_support.hpp" // used by is_static_visitor
|
||||
|
||||
namespace boost {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// class template static_visitor
|
||||
//
|
||||
// An empty base class that typedefs the return type of a deriving static
|
||||
// visitor. The class is analogous to std::unary_function in this role.
|
||||
//
|
||||
|
||||
namespace detail {
|
||||
|
||||
struct is_static_visitor_tag { };
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename R = void>
|
||||
struct static_visitor
|
||||
: public detail::is_static_visitor_tag
|
||||
{
|
||||
typedef R result_type;
|
||||
|
||||
protected:
|
||||
~static_visitor() { }
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// metafunction is_static_visitor
|
||||
//
|
||||
// Value metafunction indicates whether the specified type is a static
|
||||
// visitor of any types.
|
||||
//
|
||||
// NOTE: This template never needs to be specialized!
|
||||
//
|
||||
template <typename T>
|
||||
struct is_static_visitor
|
||||
{
|
||||
typedef typename is_base_and_derived<
|
||||
detail::is_static_visitor_tag
|
||||
, T
|
||||
>::type type;
|
||||
|
||||
BOOST_STATIC_CONSTANT(bool, value = type::value);
|
||||
|
||||
BOOST_MPL_AUX_LAMBDA_SUPPORT(1,is_static_visitor,(T))
|
||||
};
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_STATIC_VISITOR_HPP
|
||||
1163
include/boost/variant/variant.hpp
Normal file
1163
include/boost/variant/variant.hpp
Normal file
File diff suppressed because it is too large
Load Diff
143
include/boost/variant/variant_fwd.hpp
Normal file
143
include/boost/variant/variant_fwd.hpp
Normal file
@@ -0,0 +1,143 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost variant/variant_fwd.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2003
|
||||
// Eric Friedman, Itay Maman
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both the copyright notice and this permission notice appear in
|
||||
// supporting documentation. No representations are made about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
|
||||
#ifndef BOOST_VARIANT_VARIANT_FWD_HPP
|
||||
#define BOOST_VARIANT_VARIANT_FWD_HPP
|
||||
|
||||
#include "boost/config.hpp"
|
||||
#include "boost/preprocessor/enum_params_with_a_default.hpp"
|
||||
#include "boost/preprocessor/enum_params_with_defaults.hpp"
|
||||
#include "boost/mpl/limits/list.hpp"
|
||||
#include "boost/mpl/void.hpp"
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// BOOST_VARIANT_LIMIT_TYPES
|
||||
//
|
||||
// Implementation-defined preprocessor symbol describing the actual
|
||||
// length of variant's pseudo-variadic template parameter list.
|
||||
//
|
||||
#define BOOST_VARIANT_LIMIT_TYPES \
|
||||
BOOST_MPL_LIMIT_LIST_SIZE
|
||||
|
||||
namespace boost {
|
||||
|
||||
namespace detail { namespace variant {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// (detail) class void_ and class template convert_void
|
||||
//
|
||||
// Provides the mechanism by which void(NN) types are converted to
|
||||
// mpl::void_ (and thus can be passed to mpl::list).
|
||||
//
|
||||
// Rationale: This is particularly needed for the using-declarations
|
||||
// workaround (below), but also to avoid associating mpl namespace with
|
||||
// variant in argument dependent lookups (which used to happen because of
|
||||
// defaulting of template parameters to mpl::void_).
|
||||
//
|
||||
|
||||
struct void_;
|
||||
|
||||
template <typename T>
|
||||
struct convert_void
|
||||
{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct convert_void< void_ >
|
||||
{
|
||||
typedef mpl::void_ type;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// (workaround) BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE
|
||||
//
|
||||
// Needed to work around compilers that don't support using-declaration
|
||||
// overloads. (See the variant::initializer workarounds below.)
|
||||
//
|
||||
|
||||
#if defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
|
||||
|
||||
// (detail) tags voidNN -- NN defined on [0, BOOST_VARIANT_LIMIT_TYPES)
|
||||
//
|
||||
// Defines void types that are each unique and specializations of
|
||||
// convert_void that yields mpl::void_ for each voidNN type.
|
||||
//
|
||||
|
||||
#define BOOST_VARIANT_DETAIL_DEFINE_VOID_N(z,N,_) \
|
||||
struct BOOST_PP_CAT(void,N); \
|
||||
\
|
||||
template <> \
|
||||
struct convert_void< BOOST_PP_CAT(void,N) > \
|
||||
{ \
|
||||
typedef mpl::void_ type; \
|
||||
}; \
|
||||
/**/
|
||||
|
||||
BOOST_PP_REPEAT(
|
||||
BOOST_VARIANT_LIMIT_TYPES
|
||||
, BOOST_VARIANT_DETAIL_DEFINE_VOID_N
|
||||
, _
|
||||
)
|
||||
|
||||
#undef BOOST_VARIANT_DETAIL_DEFINE_VOID_N
|
||||
|
||||
#endif // BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE workaround
|
||||
|
||||
}} // namespace detail::variant
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// class template variant (concept inspired by Andrei Alexandrescu)
|
||||
//
|
||||
// Efficient, type-safe bounded discriminated union.
|
||||
//
|
||||
// Preconditions:
|
||||
// - Each type must be unique.
|
||||
// - No type may be const-qualified.
|
||||
//
|
||||
// Proper declaration form:
|
||||
// variant<types> (where types is a type-sequence)
|
||||
// or
|
||||
// variant<T0,T1,...,Tn> (where T0 is NOT a type-sequence)
|
||||
// or
|
||||
// variant<>, which acts like variant<boost::empty>
|
||||
//
|
||||
template <
|
||||
|
||||
#if !defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
|
||||
|
||||
BOOST_PP_ENUM_PARAMS_WITH_A_DEFAULT(
|
||||
BOOST_VARIANT_LIMIT_TYPES
|
||||
, typename T
|
||||
, detail::variant::void_
|
||||
)
|
||||
|
||||
#else// defined(BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE)
|
||||
|
||||
BOOST_PP_ENUM_PARAMS_WITH_DEFAULTS(
|
||||
BOOST_VARIANT_LIMIT_TYPES
|
||||
, typename T
|
||||
, detail::variant::void//NN
|
||||
)
|
||||
|
||||
#endif // BOOST_NO_USING_DECLARATION_OVERLOADS_FROM_TYPENAME_BASE workaround
|
||||
|
||||
>
|
||||
class variant;
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif // BOOST_VARIANT_VARIANT_FWD_HPP
|
||||
82
include/boost/variant/visitor_ptr.hpp
Normal file
82
include/boost/variant/visitor_ptr.hpp
Normal file
@@ -0,0 +1,82 @@
|
||||
//-----------------------------------------------------------------------------
|
||||
// boost variant/visitor_ptr.hpp header file
|
||||
// See http://www.boost.org for updates, documentation, and revision history.
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2002-2003
|
||||
// Eric Friedman
|
||||
//
|
||||
// Permission to use, copy, modify, distribute and sell this software
|
||||
// and its documentation for any purpose is hereby granted without fee,
|
||||
// provided that the above copyright notice appears in all copies and
|
||||
// that both the copyright notice and this permission notice appear in
|
||||
// supporting documentation. No representations are made about the
|
||||
// suitability of this software for any purpose. It is provided "as is"
|
||||
// without express or implied warranty.
|
||||
|
||||
#ifndef BOOST_VARIANT_VISITOR_PTR_HPP
|
||||
#define BOOST_VARIANT_VISITOR_PTR_HPP
|
||||
|
||||
#include "boost/variant/bad_visit.hpp"
|
||||
#include "boost/variant/static_visitor.hpp"
|
||||
|
||||
#include "boost/type_traits/add_reference.hpp"
|
||||
|
||||
namespace boost {
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// function template visitor_ptr
|
||||
//
|
||||
// Adapts a function pointer for use as visitor capable of handling
|
||||
// values of a single type. Throws bad_visit if inappropriately applied.
|
||||
//
|
||||
template <typename T, typename R>
|
||||
class visitor_ptr_t
|
||||
: public static_visitor<R>
|
||||
{
|
||||
private: // representation
|
||||
|
||||
typedef R (*visitor_t)(T);
|
||||
|
||||
visitor_t visitor_;
|
||||
|
||||
public: // typedefs
|
||||
|
||||
typedef R result_type;
|
||||
|
||||
private: // private typedefs
|
||||
|
||||
typedef typename add_reference<T>::type
|
||||
argument_fwd_type;
|
||||
|
||||
public: // structors
|
||||
|
||||
explicit visitor_ptr_t(visitor_t visitor)
|
||||
: visitor_(visitor)
|
||||
{
|
||||
}
|
||||
|
||||
public: // static visitor interfaces
|
||||
|
||||
result_type operator()(argument_fwd_type operand) const
|
||||
{
|
||||
return visitor_(operand);
|
||||
}
|
||||
|
||||
template <typename U>
|
||||
result_type operator()(const U& operand) const
|
||||
{
|
||||
throw bad_visit();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <typename R, typename T>
|
||||
inline visitor_ptr_t<T,R> visitor_ptr(R (*visitor)(T))
|
||||
{
|
||||
return visitor_ptr_t<T,R>(visitor);
|
||||
}
|
||||
|
||||
} // namespace boost
|
||||
|
||||
#endif// BOOST_VISITOR_VISITOR_PTR_HPP
|
||||
Reference in New Issue
Block a user