Skip to content

Commit

Permalink
use local HAS_EXCEPTIONS #define (__EXCEPTIONS is g++/clang specific …
Browse files Browse the repository at this point in the history
…macro)
  • Loading branch information
artemp committed Jun 6, 2016
1 parent 372d7c8 commit eedafd3
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions include/mapbox/variant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
#endif
// clang-format on

// Exceptions
#if defined( __EXCEPTIONS) || defined( _MSC_VER)
#define HAS_EXCEPTIONS
#endif

#define VARIANT_MAJOR_VERSION 1
#define VARIANT_MINOR_VERSION 1
#define VARIANT_PATCH_VERSION 0
Expand Down Expand Up @@ -660,7 +665,7 @@ class variant
return *reinterpret_cast<T*>(&data);
}

#ifdef __EXCEPTIONS
#ifdef HAS_EXCEPTIONS
// get<T>()
template <typename T, typename std::enable_if<
(detail::direct_type<T, Types...>::index != detail::invalid_value)>::type* = nullptr>
Expand All @@ -684,7 +689,7 @@ class variant
return *reinterpret_cast<T const*>(&data);
}

#ifdef __EXCEPTIONS
#ifdef HAS_EXCEPTIONS
template <typename T, typename std::enable_if<
(detail::direct_type<T, Types...>::index != detail::invalid_value)>::type* = nullptr>
VARIANT_INLINE T const& get() const
Expand All @@ -708,7 +713,7 @@ class variant
return (*reinterpret_cast<recursive_wrapper<T>*>(&data)).get();
}

#ifdef __EXCEPTIONS
#ifdef HAS_EXCEPTIONS
// get<T>() - T stored as recursive_wrapper<T>
template <typename T, typename std::enable_if<
(detail::direct_type<recursive_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr>
Expand All @@ -732,7 +737,7 @@ class variant
return (*reinterpret_cast<recursive_wrapper<T> const*>(&data)).get();
}

#ifdef __EXCEPTIONS
#ifdef HAS_EXCEPTIONS
template <typename T, typename std::enable_if<
(detail::direct_type<recursive_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr>
VARIANT_INLINE T const& get() const
Expand All @@ -756,7 +761,7 @@ class variant
return (*reinterpret_cast<std::reference_wrapper<T>*>(&data)).get();
}

#ifdef __EXCEPTIONS
#ifdef HAS_EXCEPTIONS
// get<T>() - T stored as std::reference_wrapper<T>
template <typename T, typename std::enable_if<
(detail::direct_type<std::reference_wrapper<T>, Types...>::index != detail::invalid_value)>::type* = nullptr>
Expand All @@ -780,7 +785,7 @@ class variant
return (*reinterpret_cast<std::reference_wrapper<T const> const*>(&data)).get();
}

#ifdef __EXCEPTIONS
#ifdef HAS_EXCEPTIONS
template <typename T, typename std::enable_if<
(detail::direct_type<std::reference_wrapper<T const>, Types...>::index != detail::invalid_value)>::type* = nullptr>
VARIANT_INLINE T const& get() const
Expand Down Expand Up @@ -927,7 +932,7 @@ auto VARIANT_INLINE apply_visitor(F&& f, V& v0, V& v1) -> decltype(V::binary_vis

// getter interface

#ifdef __EXCEPTIONS
#ifdef HAS_EXCEPTIONS
template <typename ResultType, typename T>
auto get(T& var)->decltype(var.template get<ResultType>())
{
Expand All @@ -941,7 +946,7 @@ ResultType& get_unchecked(T& var)
return var.template get_unchecked<ResultType>();
}

#ifdef __EXCEPTIONS
#ifdef HAS_EXCEPTIONS
template <typename ResultType, typename T>
auto get(T const& var)->decltype(var.template get<ResultType>())
{
Expand Down

0 comments on commit eedafd3

Please sign in to comment.