meta::sentinel_for

Defined in header <mgs/meta/concepts/sentinel_for.hpp>.

template <typename S, typename I>
  concept sentinel_for =
    meta::semiregular<S> &&
    meta::input_or_output_iterator<I> &&
    meta::weakly_equality_comparable_with<S, I>

Pre-C++20 implementation of the std::sentinel_for concept.


Concept emulation

namespace mgs {
namespace meta {

template <typename S, typename I>
struct is_sentinel_for { /* ... */ };

template <typename S, typename I>
constexpr auto is_sentinel_for_v = is_sentinel_for<S, I>::value;

template <typename S, typename I,
          typename = std::enable_if_t<is_sentinel_for_v<S, I>>>
using sentinel_for = S;

} // namespace meta
} // namespace mgs

Example

#include <mgs/meta/concepts/sentinel_for.hpp>

using namespace mgs::meta;

struct pointer_sentinel {};

bool operator==(char*, pointer_sentinel);
bool operator!=(char*, pointer_sentinel);

bool operator==(pointer_sentinel, char*);
bool operator!=(pointer_sentinel, char*);

static_assert(is_sentinel_for_v<char*, char*>, "");
static_assert(is_sentinel_for_v<pointer_sentinel, char*>, "");
static_assert(!is_sentinel_for_v<pointer_sentinel, std::vector<int>::iterator>, "");