Skip to content

Instantly share code, notes, and snippets.

@hkaiser
Forked from gonidelis/is_sentinel_for.hpp
Last active June 5, 2020 12:51
Show Gist options
  • Save hkaiser/d81697a0c83212fbd4ea67a06d9d7508 to your computer and use it in GitHub Desktop.
Save hkaiser/d81697a0c83212fbd4ea67a06d9d7508 to your computer and use it in GitHub Desktop.
#include <hpx/type_support/always_void.hpp>
#include <utility>
namespace hpx { namespace traits {
///////////////////////////////////////////////////////////////////////////
namespace detail {
template <typename T, typename U, typename Enable = void>
struct equality_result
{
};
template <typename T, typename U>
struct equality_result<T, U,
typename util::always_void<decltype(
std::declval<const T&>() == std::declval<const U&>())>::type>
{
using type =
decltype(std::declval<const T&>() == std::declval<const U&>());
};
template <typename T, typename U, typename Enable = void>
struct inequality_result
{
};
template <typename T, typename U>
struct inequality_result<T, U,
typename util::always_void<decltype(
std::declval<const T&>() != std::declval<const U&>())>::type>
{
using type =
decltype(std::declval<const T&>() != std::declval<const U&>());
};
} // namespace detail
template <typename Iter, typename Sent, typename Enable = void>
struct is_sentinel_for : std::false_type
{
};
template <typename Iter, typename Sent>
struct is_sentinel_for<Iter, Sent,
typename util::always_void<
typename detail::equality_result<Iter, Sent>::type,
typename detail::equality_result<Sent, Iter>::type,
typename detail::inequality_result<Iter, Sent>::type,
typename detail::inequality_result<Sent, Iter>::type
>::type>
: std::true_type
{
};
}} // namespace hpx::traits
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment