56 changes: 28 additions & 28 deletions include/boost/variant/polymorphic_get.hpp
Expand Up @@ -137,13 +137,13 @@ struct get_polymorphic_visitor
#endif

//////////////////////////////////////////////////////////////////////////////////////////////////////////
// polymorphic_unsafe_get
// polymorphic_relaxed_get
//

template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_pointer<U>::type
polymorphic_unsafe_get(
polymorphic_relaxed_get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
) BOOST_NOEXCEPT
Expand All @@ -158,7 +158,7 @@ polymorphic_unsafe_get(
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_pointer<const U>::type
polymorphic_unsafe_get(
polymorphic_relaxed_get(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
) BOOST_NOEXCEPT
Expand All @@ -173,13 +173,13 @@ polymorphic_unsafe_get(
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_reference<U>::type
polymorphic_unsafe_get(
polymorphic_relaxed_get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
typedef typename add_pointer<U>::type U_ptr;
U_ptr result = polymorphic_unsafe_get<U>(&operand);
U_ptr result = polymorphic_relaxed_get<U>(&operand);

if (!result)
boost::throw_exception(bad_polymorphic_get());
Expand All @@ -189,27 +189,27 @@ polymorphic_unsafe_get(
template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_reference<const U>::type
polymorphic_unsafe_get(
polymorphic_relaxed_get(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
typedef typename add_pointer<const U>::type U_ptr;
U_ptr result = polymorphic_unsafe_get<const U>(&operand);
U_ptr result = polymorphic_relaxed_get<const U>(&operand);

if (!result)
boost::throw_exception(bad_polymorphic_get());
return *result;
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////
// polymorphic_safe_get
// polymorphic_strict_get
//

template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_pointer<U>::type
polymorphic_safe_get(
polymorphic_strict_get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
) BOOST_NOEXCEPT
Expand All @@ -220,13 +220,13 @@ polymorphic_safe_get(
"call to boost::polymorphic_get<U>(boost::variant<T...>*) will always return NULL"
);

return polymorphic_unsafe_get<U>(operand);
return polymorphic_relaxed_get<U>(operand);
}

template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_pointer<const U>::type
polymorphic_safe_get(
polymorphic_strict_get(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >* operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
) BOOST_NOEXCEPT
Expand All @@ -237,13 +237,13 @@ polymorphic_safe_get(
"call to boost::polymorphic_get<U>(const boost::variant<T...>*) will always return NULL"
);

return polymorphic_unsafe_get<U>(operand);
return polymorphic_relaxed_get<U>(operand);
}

template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_reference<U>::type
polymorphic_safe_get(
polymorphic_strict_get(
boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
Expand All @@ -254,13 +254,13 @@ polymorphic_safe_get(
"call to boost::polymorphic_get<U>(boost::variant<T...>&) will always throw boost::bad_polymorphic_get exception"
);

return polymorphic_unsafe_get<U>(operand);
return polymorphic_relaxed_get<U>(operand);
}

template <typename U, BOOST_VARIANT_ENUM_PARAMS(typename T) >
inline
typename add_reference<const U>::type
polymorphic_safe_get(
polymorphic_strict_get(
const boost::variant< BOOST_VARIANT_ENUM_PARAMS(T) >& operand
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
Expand All @@ -271,7 +271,7 @@ polymorphic_safe_get(
"call to boost::polymorphic_get<U>(const boost::variant<T...>&) will always throw boost::bad_polymorphic_get exception"
);

return polymorphic_unsafe_get<U>(operand);
return polymorphic_relaxed_get<U>(operand);
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand All @@ -286,10 +286,10 @@ polymorphic_get(
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
) BOOST_NOEXCEPT
{
#ifdef BOOST_VARIANT_USE_UNSAFE_GET_BY_DEFAULT
return polymorphic_unsafe_get<U>(operand);
#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
return polymorphic_relaxed_get<U>(operand);
#else
return polymorphic_safe_get<U>(operand);
return polymorphic_strict_get<U>(operand);
#endif

}
Expand All @@ -302,10 +302,10 @@ polymorphic_get(
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
) BOOST_NOEXCEPT
{
#ifdef BOOST_VARIANT_USE_UNSAFE_GET_BY_DEFAULT
return polymorphic_unsafe_get<U>(operand);
#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
return polymorphic_relaxed_get<U>(operand);
#else
return polymorphic_safe_get<U>(operand);
return polymorphic_strict_get<U>(operand);
#endif
}

Expand All @@ -317,10 +317,10 @@ polymorphic_get(
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
#ifdef BOOST_VARIANT_USE_UNSAFE_GET_BY_DEFAULT
return polymorphic_unsafe_get<U>(operand);
#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
return polymorphic_relaxed_get<U>(operand);
#else
return polymorphic_safe_get<U>(operand);
return polymorphic_strict_get<U>(operand);
#endif
}

Expand All @@ -332,10 +332,10 @@ polymorphic_get(
BOOST_VARIANT_AUX_GET_EXPLICIT_TEMPLATE_TYPE(U)
)
{
#ifdef BOOST_VARIANT_USE_UNSAFE_GET_BY_DEFAULT
return polymorphic_unsafe_get<U>(operand);
#ifdef BOOST_VARIANT_USE_RELAXED_GET_BY_DEFAULT
return polymorphic_relaxed_get<U>(operand);
#else
return polymorphic_safe_get<U>(operand);
return polymorphic_strict_get<U>(operand);
#endif
}
} // namespace boost
Expand Down
4 changes: 2 additions & 2 deletions test/test8.cpp
Expand Up @@ -58,11 +58,11 @@ T& check_pass(Variant& v, T value)
template <typename T, typename Variant>
void check_fail(Variant& v)
{
BOOST_CHECK(!unsafe_get<T>(&v));
BOOST_CHECK(!relaxed_get<T>(&v));

try
{
T& r = unsafe_get<T>(v);
T& r = relaxed_get<T>(v);
(void)r; // suppress warning about r not being used
BOOST_CHECK(false && &r); // should never reach
}
Expand Down
66 changes: 33 additions & 33 deletions test/variant_get_test.cpp
Expand Up @@ -41,17 +41,17 @@ inline void check_polymorphic_get_on_types_impl_single_type(V* v)
if (!!boost::is_same<T, TestType>::value) {
BOOST_CHECK(boost::polymorphic_get<TestType>(v));
BOOST_CHECK(boost::polymorphic_get<const TestType>(v));
BOOST_CHECK(boost::polymorphic_safe_get<TestType>(v));
BOOST_CHECK(boost::polymorphic_safe_get<const TestType>(v));
BOOST_CHECK(boost::polymorphic_unsafe_get<TestType>(v));
BOOST_CHECK(boost::polymorphic_unsafe_get<const TestType>(v));
BOOST_CHECK(boost::polymorphic_strict_get<TestType>(v));
BOOST_CHECK(boost::polymorphic_strict_get<const TestType>(v));
BOOST_CHECK(boost::polymorphic_relaxed_get<TestType>(v));
BOOST_CHECK(boost::polymorphic_relaxed_get<const TestType>(v));
} else {
BOOST_CHECK(!boost::polymorphic_get<TestType>(v));
BOOST_CHECK(!boost::polymorphic_get<const TestType>(v));
BOOST_CHECK(!boost::polymorphic_safe_get<TestType>(v));
BOOST_CHECK(!boost::polymorphic_safe_get<const TestType>(v));
BOOST_CHECK(!boost::polymorphic_unsafe_get<TestType>(v));
BOOST_CHECK(!boost::polymorphic_unsafe_get<const TestType>(v));
BOOST_CHECK(!boost::polymorphic_strict_get<TestType>(v));
BOOST_CHECK(!boost::polymorphic_strict_get<const TestType>(v));
BOOST_CHECK(!boost::polymorphic_relaxed_get<TestType>(v));
BOOST_CHECK(!boost::polymorphic_relaxed_get<const TestType>(v));
}
}

Expand All @@ -61,17 +61,17 @@ inline void check_get_on_types_impl_single_type(V* v)
if (!!boost::is_same<T, TestType>::value) {
BOOST_CHECK(boost::get<TestType>(v));
BOOST_CHECK(boost::get<const TestType>(v));
BOOST_CHECK(boost::safe_get<TestType>(v));
BOOST_CHECK(boost::safe_get<const TestType>(v));
BOOST_CHECK(boost::unsafe_get<TestType>(v));
BOOST_CHECK(boost::unsafe_get<const TestType>(v));
BOOST_CHECK(boost::strict_get<TestType>(v));
BOOST_CHECK(boost::strict_get<const TestType>(v));
BOOST_CHECK(boost::relaxed_get<TestType>(v));
BOOST_CHECK(boost::relaxed_get<const TestType>(v));
} else {
BOOST_CHECK(!boost::get<TestType>(v));
BOOST_CHECK(!boost::get<const TestType>(v));
BOOST_CHECK(!boost::safe_get<TestType>(v));
BOOST_CHECK(!boost::safe_get<const TestType>(v));
BOOST_CHECK(!boost::unsafe_get<TestType>(v));
BOOST_CHECK(!boost::unsafe_get<const TestType>(v));
BOOST_CHECK(!boost::strict_get<TestType>(v));
BOOST_CHECK(!boost::strict_get<const TestType>(v));
BOOST_CHECK(!boost::relaxed_get<TestType>(v));
BOOST_CHECK(!boost::relaxed_get<const TestType>(v));
}
}

Expand All @@ -93,29 +93,29 @@ inline void check_get_on_types_impl(V* v)
check_polymorphic_get_on_types_impl_single_type<T, V, std::string>(v);

// Never exist in here
BOOST_CHECK(!boost::unsafe_get<short>(v));
BOOST_CHECK(!boost::unsafe_get<const short>(v));
BOOST_CHECK(!boost::unsafe_get<char>(v));
BOOST_CHECK(!boost::unsafe_get<char*>(v));
BOOST_CHECK(!boost::unsafe_get<bool>(v));
BOOST_CHECK(!boost::unsafe_get<const bool>(v));

BOOST_CHECK(!boost::polymorphic_unsafe_get<short>(v));
BOOST_CHECK(!boost::polymorphic_unsafe_get<const short>(v));
BOOST_CHECK(!boost::polymorphic_unsafe_get<char>(v));
BOOST_CHECK(!boost::polymorphic_unsafe_get<char*>(v));
BOOST_CHECK(!boost::polymorphic_unsafe_get<bool>(v));
BOOST_CHECK(!boost::polymorphic_unsafe_get<const bool>(v));
BOOST_CHECK(!boost::relaxed_get<short>(v));
BOOST_CHECK(!boost::relaxed_get<const short>(v));
BOOST_CHECK(!boost::relaxed_get<char>(v));
BOOST_CHECK(!boost::relaxed_get<char*>(v));
BOOST_CHECK(!boost::relaxed_get<bool>(v));
BOOST_CHECK(!boost::relaxed_get<const bool>(v));

BOOST_CHECK(!boost::polymorphic_relaxed_get<short>(v));
BOOST_CHECK(!boost::polymorphic_relaxed_get<const short>(v));
BOOST_CHECK(!boost::polymorphic_relaxed_get<char>(v));
BOOST_CHECK(!boost::polymorphic_relaxed_get<char*>(v));
BOOST_CHECK(!boost::polymorphic_relaxed_get<bool>(v));
BOOST_CHECK(!boost::polymorphic_relaxed_get<const bool>(v));

boost::get<T>(*v); // Must compile
boost::get<const T>(*v); // Must compile
boost::safe_get<T>(*v); // Must compile
boost::safe_get<const T>(*v); // Must compile
boost::strict_get<T>(*v); // Must compile
boost::strict_get<const T>(*v); // Must compile

boost::polymorphic_get<T>(*v); // Must compile
boost::polymorphic_get<const T>(*v); // Must compile
boost::polymorphic_safe_get<T>(*v); // Must compile
boost::polymorphic_safe_get<const T>(*v); // Must compile
boost::polymorphic_strict_get<T>(*v); // Must compile
boost::polymorphic_strict_get<const T>(*v); // Must compile
}

template <class T, class V>
Expand Down