2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2014-01-08 07:48:12 +00:00
|
|
|
Copyright (c) 2011-2014 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
=============================================================================*/
|
2011-11-06 01:56:57 +00:00
|
|
|
#ifndef SPROUT_VARIANT_VARIANT_HPP
|
|
|
|
#define SPROUT_VARIANT_VARIANT_HPP
|
|
|
|
|
|
|
|
#include <utility>
|
|
|
|
#include <stdexcept>
|
2012-01-10 16:34:37 +00:00
|
|
|
#include <type_traits>
|
2011-11-06 01:56:57 +00:00
|
|
|
#include <sprout/config.hpp>
|
2014-04-30 07:30:26 +00:00
|
|
|
#include <sprout/workaround/std/cstddef.hpp>
|
2013-04-06 04:06:51 +00:00
|
|
|
#include <sprout/index_tuple/metafunction.hpp>
|
2012-10-05 15:58:56 +00:00
|
|
|
#include <sprout/utility/forward.hpp>
|
|
|
|
#include <sprout/utility/move.hpp>
|
|
|
|
#include <sprout/utility/swap.hpp>
|
2011-11-06 01:56:57 +00:00
|
|
|
#include <sprout/tuple/tuple.hpp>
|
|
|
|
#include <sprout/tuple/functions.hpp>
|
2013-03-31 06:14:10 +00:00
|
|
|
#include <sprout/tuple/indexes.hpp>
|
2013-03-21 13:11:40 +00:00
|
|
|
#include <sprout/type_traits/common_decay.hpp>
|
2012-01-10 16:34:37 +00:00
|
|
|
#include <sprout/type/type_tuple.hpp>
|
2011-11-06 01:56:57 +00:00
|
|
|
#include <sprout/type/algorithm/find_index.hpp>
|
2012-12-19 14:06:08 +00:00
|
|
|
#include <sprout/functional/type_traits/has_type.hpp>
|
|
|
|
#include <sprout/functional/type_traits/weak_result_type.hpp>
|
2013-02-04 16:02:59 +00:00
|
|
|
#include <sprout/variant/variant_fwd.hpp>
|
2012-12-19 15:09:05 +00:00
|
|
|
#include <sprout/variant/visitor_result.hpp>
|
2013-10-05 04:35:26 +00:00
|
|
|
#include <sprout/math/less.hpp>
|
2011-11-06 01:56:57 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace detail {
|
|
|
|
template<typename... Types>
|
|
|
|
class variant_impl {
|
2012-10-28 07:18:40 +00:00
|
|
|
template<typename...>
|
|
|
|
friend class variant;
|
2011-11-06 01:56:57 +00:00
|
|
|
protected:
|
2012-03-23 14:06:06 +00:00
|
|
|
typedef sprout::tuples::tuple<Types...> tuple_type;
|
2013-03-26 17:02:16 +00:00
|
|
|
typedef sprout::types::type_tuple<typename std::decay<Types>::type...> decayed_tuple_type;
|
2011-11-06 01:56:57 +00:00
|
|
|
private:
|
2012-02-28 01:46:39 +00:00
|
|
|
template<typename T, sprout::index_t... Indexes>
|
2011-11-06 01:56:57 +00:00
|
|
|
static SPROUT_CONSTEXPR tuple_type init(T&& operand, sprout::index_tuple<Indexes...>) {
|
2012-03-31 07:24:13 +00:00
|
|
|
return sprout::tuples::make<tuple_type>(
|
2013-03-26 17:02:16 +00:00
|
|
|
sprout::tuples::flexibly_construct,
|
2011-11-06 01:56:57 +00:00
|
|
|
typename sprout::tuples::tuple_element<Indexes, tuple_type>::type()...,
|
2014-02-22 07:32:51 +00:00
|
|
|
SPROUT_FORWARD(T, operand)
|
2011-11-06 01:56:57 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
tuple_type tuple_;
|
|
|
|
int which_;
|
|
|
|
protected:
|
|
|
|
SPROUT_CONSTEXPR variant_impl()
|
|
|
|
: tuple_()
|
|
|
|
, which_()
|
|
|
|
{}
|
|
|
|
template<typename T, typename Index>
|
|
|
|
SPROUT_CONSTEXPR variant_impl(T&& operand, Index)
|
2014-02-22 07:32:51 +00:00
|
|
|
: tuple_(init(SPROUT_FORWARD(T, operand), sprout::make_index_tuple<Index::value>::make()))
|
2011-11-06 01:56:57 +00:00
|
|
|
, which_(Index::value)
|
|
|
|
{
|
|
|
|
static_assert(Index::value < sizeof...(Types), "variant<>: invalid operand");
|
|
|
|
}
|
2012-10-28 07:18:40 +00:00
|
|
|
public:
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR void swap(variant_impl& other)
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(sprout::swap(tuple_, other.tuple_)))
|
2011-11-06 01:56:57 +00:00
|
|
|
{
|
2012-10-05 15:58:56 +00:00
|
|
|
sprout::swap(tuple_, other.tuple_);
|
|
|
|
sprout::swap(which_, other.which_);
|
2011-11-06 01:56:57 +00:00
|
|
|
}
|
|
|
|
variant_impl& operator=(variant_impl const&) = default;
|
|
|
|
};
|
|
|
|
} // namespace detail
|
|
|
|
//
|
|
|
|
// variant
|
|
|
|
//
|
|
|
|
template<typename... Types>
|
|
|
|
class variant
|
|
|
|
: private sprout::detail::variant_impl<Types...>
|
|
|
|
{
|
|
|
|
private:
|
2012-03-23 14:06:06 +00:00
|
|
|
typedef sprout::detail::variant_impl<Types...> impl_type;
|
2013-03-26 17:02:16 +00:00
|
|
|
typedef typename impl_type::decayed_tuple_type decayed_tuple_type;
|
2011-11-06 01:56:57 +00:00
|
|
|
public:
|
2012-03-23 14:06:06 +00:00
|
|
|
typedef typename impl_type::tuple_type tuple_type;
|
2012-12-19 14:06:08 +00:00
|
|
|
private:
|
2012-12-19 15:09:05 +00:00
|
|
|
template<typename Visitor, typename Tuple, typename IndexTuple>
|
|
|
|
struct visitor_result_impl_2;
|
|
|
|
template<typename Visitor, typename Tuple, sprout::index_t... Indexes>
|
2013-03-26 17:02:16 +00:00
|
|
|
struct visitor_result_impl_2<Visitor, Tuple, sprout::index_tuple<Indexes...> >
|
|
|
|
: public Visitor::template visitor_result<
|
2012-12-19 15:09:05 +00:00
|
|
|
decltype((std::declval<Visitor>())(sprout::tuples::get<Indexes>(std::declval<Tuple>())))...
|
2013-03-26 17:02:16 +00:00
|
|
|
>
|
|
|
|
{};
|
2012-12-19 14:06:08 +00:00
|
|
|
template<typename Visitor, typename Tuple, typename IndexTuple>
|
|
|
|
struct visitor_result_impl_1;
|
|
|
|
template<typename Visitor, typename Tuple, sprout::index_t... Indexes>
|
2013-03-26 17:02:16 +00:00
|
|
|
struct visitor_result_impl_1<Visitor, Tuple, sprout::index_tuple<Indexes...> >
|
|
|
|
: public sprout::common_decay<
|
2013-03-21 13:11:40 +00:00
|
|
|
decltype((std::declval<Visitor>())(sprout::tuples::get<Indexes>(std::declval<Tuple>())))...
|
2013-03-26 17:02:16 +00:00
|
|
|
>
|
|
|
|
{};
|
2012-12-19 14:06:08 +00:00
|
|
|
template<typename Visitor, typename Tuple, typename = void>
|
|
|
|
struct visitor_result_impl;
|
|
|
|
template<typename Visitor, typename Tuple>
|
|
|
|
struct visitor_result_impl<
|
|
|
|
Visitor, Tuple,
|
2012-12-19 15:09:05 +00:00
|
|
|
typename std::enable_if<
|
|
|
|
sprout::has_result_type<sprout::weak_result_type<Visitor> >::value
|
|
|
|
>::type
|
|
|
|
> {
|
|
|
|
public:
|
|
|
|
typedef typename sprout::weak_result_type<Visitor>::result_type type;
|
|
|
|
};
|
|
|
|
template<typename Visitor, typename Tuple>
|
|
|
|
struct visitor_result_impl<
|
|
|
|
Visitor, Tuple,
|
|
|
|
typename std::enable_if<
|
|
|
|
sprout::has_visitor_result<Visitor>::value
|
|
|
|
&& !sprout::has_result_type<sprout::weak_result_type<Visitor> >::value
|
|
|
|
>::type
|
2012-12-19 14:06:08 +00:00
|
|
|
>
|
2013-03-31 06:14:10 +00:00
|
|
|
: public visitor_result_impl_2<Visitor, Tuple, typename sprout::tuple_indexes<Tuple>::type>
|
2012-12-19 14:06:08 +00:00
|
|
|
{};
|
|
|
|
template<typename Visitor, typename Tuple>
|
|
|
|
struct visitor_result_impl<
|
|
|
|
Visitor, Tuple,
|
2012-12-19 15:09:05 +00:00
|
|
|
typename std::enable_if<
|
|
|
|
!sprout::has_visitor_result<Visitor>::value
|
|
|
|
&& !sprout::has_result_type<sprout::weak_result_type<Visitor> >::value
|
|
|
|
>::type
|
|
|
|
>
|
2013-03-31 06:14:10 +00:00
|
|
|
: public visitor_result_impl_1<Visitor, Tuple, typename sprout::tuple_indexes<Tuple>::type>
|
2012-12-19 15:09:05 +00:00
|
|
|
{};
|
2012-12-19 14:06:08 +00:00
|
|
|
public:
|
2012-12-19 15:09:05 +00:00
|
|
|
// visitation support
|
2012-12-19 14:06:08 +00:00
|
|
|
template<typename Visitor, typename Visitable>
|
|
|
|
struct visitor_result
|
|
|
|
: public visitor_result_impl<Visitor, typename Visitable::tuple_type>
|
|
|
|
{};
|
|
|
|
template<typename Visitor, typename Visitable>
|
|
|
|
struct visitor_result<Visitor, Visitable const>
|
|
|
|
: public visitor_result_impl<Visitor, typename Visitable::tuple_type const>
|
|
|
|
{};
|
|
|
|
template<typename Visitor, typename Visitable>
|
|
|
|
struct visitor_result<Visitor, Visitable volatile>
|
|
|
|
: public visitor_result_impl<Visitor, typename Visitable::tuple_type volatile>
|
|
|
|
{};
|
|
|
|
template<typename Visitor, typename Visitable>
|
|
|
|
struct visitor_result<Visitor, Visitable const volatile>
|
|
|
|
: public visitor_result_impl<Visitor, typename Visitable::tuple_type const volatile>
|
|
|
|
{};
|
2011-11-06 01:56:57 +00:00
|
|
|
private:
|
|
|
|
template<int I>
|
|
|
|
static SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
I == sizeof...(Types),
|
|
|
|
bool
|
2013-07-22 13:00:09 +00:00
|
|
|
>::type eq(tuple_type const&, tuple_type const&, int) {
|
2011-11-06 01:56:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
template<int I>
|
|
|
|
static SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
I != sizeof...(Types),
|
|
|
|
bool
|
|
|
|
>::type eq(tuple_type const& l, tuple_type const& r, int which) {
|
|
|
|
return I == which
|
|
|
|
? sprout::tuples::get<I>(l) == sprout::tuples::get<I>(r)
|
|
|
|
: eq<I + 1>(l, r, which)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
template<int I>
|
|
|
|
static SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
static_cast<std::size_t>(I) == sizeof...(Types),
|
|
|
|
bool
|
2013-07-22 13:00:09 +00:00
|
|
|
>::type lt(tuple_type const&, tuple_type const&, int) {
|
2011-11-06 01:56:57 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
template<int I>
|
|
|
|
static SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
static_cast<std::size_t>(I) != sizeof...(Types),
|
|
|
|
bool
|
|
|
|
>::type lt(tuple_type const& l, tuple_type const& r, int which) {
|
|
|
|
return I == which
|
|
|
|
? sprout::tuples::get<I>(l) < sprout::tuples::get<I>(r)
|
|
|
|
: lt<I + 1>(l, r, which)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
template<int I, typename Elem, typename Traits>
|
2013-11-02 09:28:18 +00:00
|
|
|
static SPROUT_NON_CONSTEXPR typename std::enable_if<
|
2011-11-06 01:56:57 +00:00
|
|
|
static_cast<std::size_t>(I) == sizeof...(Types),
|
|
|
|
std::basic_ostream<Elem, Traits>&
|
2013-07-22 13:00:09 +00:00
|
|
|
>::type output(std::basic_ostream<Elem, Traits>& os, tuple_type const&, int) {
|
2011-11-06 01:56:57 +00:00
|
|
|
return os;
|
|
|
|
}
|
|
|
|
template<int I, typename Elem, typename Traits>
|
2013-11-02 09:28:18 +00:00
|
|
|
static SPROUT_NON_CONSTEXPR typename std::enable_if<
|
2011-11-06 01:56:57 +00:00
|
|
|
static_cast<std::size_t>(I) != sizeof...(Types),
|
|
|
|
std::basic_ostream<Elem, Traits>&
|
|
|
|
>::type output(std::basic_ostream<Elem, Traits>& os, tuple_type const& t, int which) {
|
|
|
|
return I == which
|
|
|
|
? os << sprout::tuples::get<I>(t)
|
|
|
|
: output<I + 1>(os, t, which)
|
|
|
|
;
|
|
|
|
}
|
2012-12-19 14:06:08 +00:00
|
|
|
template<typename Result, int I, typename Tuple, typename Visitor>
|
2011-11-12 11:24:42 +00:00
|
|
|
static SPROUT_CONSTEXPR typename std::enable_if<
|
2012-12-19 14:06:08 +00:00
|
|
|
I == sizeof...(Types) - 1,
|
|
|
|
Result
|
2013-07-22 13:00:09 +00:00
|
|
|
>::type visit(Tuple&& t, Visitor&& v, int) {
|
2014-02-22 07:32:51 +00:00
|
|
|
return SPROUT_FORWARD(Visitor, v)(sprout::tuples::get<I>(SPROUT_FORWARD(Tuple, t)));
|
2011-11-12 11:24:42 +00:00
|
|
|
}
|
2012-12-19 14:06:08 +00:00
|
|
|
template<typename Result, int I, typename Tuple, typename Visitor>
|
2011-11-12 11:24:42 +00:00
|
|
|
static SPROUT_CONSTEXPR typename std::enable_if<
|
2012-12-19 14:06:08 +00:00
|
|
|
I != sizeof...(Types) - 1,
|
|
|
|
Result
|
2011-11-12 11:24:42 +00:00
|
|
|
>::type visit(Tuple&& t, Visitor&& v, int which) {
|
|
|
|
return I == which
|
2014-02-22 07:32:51 +00:00
|
|
|
? SPROUT_FORWARD(Visitor, v)(sprout::tuples::get<I>(SPROUT_FORWARD(Tuple, t)))
|
|
|
|
: visit<Result, I + 1>(SPROUT_FORWARD(Tuple, t), SPROUT_FORWARD(Visitor, v), which)
|
2011-11-12 11:24:42 +00:00
|
|
|
;
|
|
|
|
}
|
2011-11-06 01:56:57 +00:00
|
|
|
private:
|
|
|
|
using impl_type::tuple_;
|
|
|
|
using impl_type::which_;
|
|
|
|
public:
|
|
|
|
// construct/copy/destruct
|
|
|
|
SPROUT_CONSTEXPR variant()
|
|
|
|
: impl_type()
|
|
|
|
{}
|
|
|
|
variant(variant const&) = default;
|
2011-12-04 16:03:52 +00:00
|
|
|
variant(variant&&) = default;
|
2011-11-06 01:56:57 +00:00
|
|
|
template<typename T>
|
|
|
|
SPROUT_CONSTEXPR variant(T&& operand)
|
2012-01-10 16:34:37 +00:00
|
|
|
: impl_type(
|
2014-02-22 07:32:51 +00:00
|
|
|
SPROUT_FORWARD(T, operand),
|
2013-03-26 17:02:16 +00:00
|
|
|
sprout::types::find_index<decayed_tuple_type, typename std::decay<T>::type>()
|
2012-01-10 16:34:37 +00:00
|
|
|
)
|
2011-11-06 01:56:57 +00:00
|
|
|
{}
|
|
|
|
// modifiers
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR void swap(variant& other)
|
2012-10-28 07:18:40 +00:00
|
|
|
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(std::declval<impl_type&>().swap(other)))
|
2012-10-05 15:58:56 +00:00
|
|
|
{
|
2011-11-06 01:56:57 +00:00
|
|
|
impl_type::swap(other);
|
|
|
|
}
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR variant& operator=(variant const& rhs) {
|
2011-11-06 01:56:57 +00:00
|
|
|
static_cast<impl_type&>(*this) = rhs;
|
|
|
|
return *this;
|
|
|
|
}
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR variant& operator=(variant&& rhs)
|
2012-10-05 15:58:56 +00:00
|
|
|
SPROUT_NOEXCEPT_EXPR(std::is_nothrow_move_assignable<impl_type>::value)
|
|
|
|
{
|
2011-11-06 01:56:57 +00:00
|
|
|
static_cast<impl_type&>(*this) = sprout::move(rhs);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
template<typename T>
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR variant& operator=(T&& rhs) {
|
2014-02-22 07:32:51 +00:00
|
|
|
static_cast<impl_type&>(*this) = variant(SPROUT_FORWARD(T, rhs));
|
2011-11-06 01:56:57 +00:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
// queries
|
|
|
|
SPROUT_CONSTEXPR int which() const {
|
|
|
|
return which_;
|
|
|
|
}
|
|
|
|
SPROUT_CONSTEXPR bool empty() const {
|
2011-11-12 11:24:42 +00:00
|
|
|
return false;
|
2011-11-06 01:56:57 +00:00
|
|
|
}
|
|
|
|
// relational
|
|
|
|
friend SPROUT_CONSTEXPR bool operator==(variant const& lhs, variant const& rhs) {
|
|
|
|
return lhs.which_ == rhs.which_ && eq<0>(lhs.tuple_, rhs.tuple_, lhs.which_);
|
|
|
|
}
|
|
|
|
friend SPROUT_CONSTEXPR bool operator!=(variant const& lhs, variant const& rhs) {
|
|
|
|
return !(lhs == rhs);
|
|
|
|
}
|
|
|
|
friend SPROUT_CONSTEXPR bool operator<(variant const& lhs, variant const& rhs) {
|
|
|
|
return lhs.which_ < rhs.which_
|
|
|
|
|| (lhs.which_ == rhs.which_ && lt<0>(lhs.tuple_, rhs.tuple_, lhs.which_))
|
|
|
|
;
|
|
|
|
}
|
|
|
|
friend SPROUT_CONSTEXPR bool operator>(variant const& lhs, variant const& rhs) {
|
|
|
|
return rhs < lhs;
|
|
|
|
}
|
|
|
|
friend SPROUT_CONSTEXPR bool operator<=(variant const& lhs, variant const& rhs) {
|
|
|
|
return !(rhs < lhs);
|
|
|
|
}
|
|
|
|
friend SPROUT_CONSTEXPR bool operator>=(variant const& lhs, variant const& rhs) {
|
|
|
|
return !(lhs < rhs);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Elem, typename Traits>
|
2013-11-02 09:28:18 +00:00
|
|
|
friend SPROUT_NON_CONSTEXPR std::basic_ostream<Elem, Traits>& operator<<(std::basic_ostream<Elem, Traits>& lhs, variant const& rhs) {
|
2011-11-06 01:56:57 +00:00
|
|
|
return output<0>(lhs, rhs.tuple_, rhs.which_);
|
|
|
|
}
|
2011-11-12 11:24:42 +00:00
|
|
|
// get support
|
2012-01-10 16:34:37 +00:00
|
|
|
template<std::size_t I>
|
|
|
|
SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
I != sizeof...(Types),
|
|
|
|
typename sprout::tuples::tuple_element<I, tuple_type>::type const&
|
|
|
|
>::type get_at() const {
|
2013-03-19 07:32:48 +00:00
|
|
|
return (SPROUT_ASSERT(I == which_), true) ? sprout::tuples::get<I>(tuple_)
|
2013-03-18 10:12:21 +00:00
|
|
|
: sprout::tuples::get<I>(tuple_)
|
2012-01-10 16:34:37 +00:00
|
|
|
;
|
|
|
|
}
|
|
|
|
template<std::size_t I>
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR typename std::enable_if<
|
2012-01-10 16:34:37 +00:00
|
|
|
I != sizeof...(Types),
|
|
|
|
typename sprout::tuples::tuple_element<I, tuple_type>::type&
|
|
|
|
>::type get_at() {
|
2013-03-19 07:32:48 +00:00
|
|
|
return (SPROUT_ASSERT(I == which_), true) ? sprout::tuples::get<I>(tuple_)
|
2013-03-18 10:12:21 +00:00
|
|
|
: sprout::tuples::get<I>(tuple_)
|
2012-01-10 16:34:37 +00:00
|
|
|
;
|
|
|
|
}
|
2011-11-06 01:56:57 +00:00
|
|
|
template<typename U>
|
|
|
|
SPROUT_CONSTEXPR typename std::enable_if<
|
|
|
|
sprout::types::find_index<tuple_type, U>::value != sizeof...(Types),
|
|
|
|
U const&
|
|
|
|
>::type get() const {
|
2012-01-10 16:34:37 +00:00
|
|
|
return get_at<sprout::types::find_index<tuple_type, U>::value>();
|
2011-11-06 01:56:57 +00:00
|
|
|
}
|
|
|
|
template<typename U>
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR typename std::enable_if<
|
2011-11-06 01:56:57 +00:00
|
|
|
sprout::types::find_index<tuple_type, U>::value != sizeof...(Types),
|
|
|
|
U&
|
|
|
|
>::type get() {
|
2012-01-10 16:34:37 +00:00
|
|
|
return get_at<sprout::types::find_index<tuple_type, U>::value>();
|
2011-11-06 01:56:57 +00:00
|
|
|
}
|
2011-11-12 11:24:42 +00:00
|
|
|
// visitation support
|
|
|
|
template<typename Visitor>
|
2012-12-19 14:06:08 +00:00
|
|
|
SPROUT_CONSTEXPR typename visitor_result<typename std::remove_reference<Visitor>::type, variant const>::type
|
|
|
|
apply_visitor(Visitor&& visitor) const {
|
|
|
|
typedef typename visitor_result<typename std::remove_reference<Visitor>::type, variant const>::type result_type;
|
2013-03-18 10:12:21 +00:00
|
|
|
return SPROUT_ASSERT(0 <= which_ && sprout::math::less(which_, sizeof...(Types))),
|
2014-02-22 07:32:51 +00:00
|
|
|
visit<result_type, 0>(tuple_, SPROUT_FORWARD(Visitor, visitor), which_)
|
2013-03-18 10:12:21 +00:00
|
|
|
;
|
2011-11-12 11:24:42 +00:00
|
|
|
}
|
|
|
|
template<typename Visitor>
|
2013-10-30 09:15:57 +00:00
|
|
|
SPROUT_CXX14_CONSTEXPR typename visitor_result<typename std::remove_reference<Visitor>::type, variant>::type
|
2012-12-19 14:06:08 +00:00
|
|
|
apply_visitor(Visitor&& visitor) {
|
|
|
|
typedef typename visitor_result<typename std::remove_reference<Visitor>::type, variant>::type result_type;
|
2013-03-18 10:12:21 +00:00
|
|
|
return SPROUT_ASSERT(0 <= which_ && sprout::math::less(which_, sizeof...(Types))),
|
2014-02-22 07:32:51 +00:00
|
|
|
visit<result_type, 0>(tuple_, SPROUT_FORWARD(Visitor, visitor), which_)
|
2013-03-18 10:12:21 +00:00
|
|
|
;
|
2011-11-12 11:24:42 +00:00
|
|
|
}
|
2011-11-06 01:56:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//
|
|
|
|
// swap
|
|
|
|
//
|
|
|
|
template<typename... Types>
|
2013-10-30 09:15:57 +00:00
|
|
|
inline SPROUT_CXX14_CONSTEXPR void
|
2012-10-05 15:58:56 +00:00
|
|
|
swap(sprout::variant<Types...>& lhs, sprout::variant<Types...>& rhs)
|
|
|
|
SPROUT_NOEXCEPT_EXPR(SPROUT_NOEXCEPT_EXPR(lhs.swap(rhs)))
|
2011-11-06 01:56:57 +00:00
|
|
|
{
|
|
|
|
lhs.swap(rhs);
|
|
|
|
}
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_VARIANT_VARIANT_HPP
|