Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/iterator/unreachable sentinel t"

From cppreference.com
< cpp‎ | iterator
(unreachable_sentinel)
 
m
Line 17: Line 17:
 
===Non-member functions===
 
===Non-member functions===
 
{{dsc begin}}
 
{{dsc begin}}
{{dsc tfun | cpp/iterator/unreachable_sentinel_t | inlinemem=true | title=operator== | compare {{tt|unreachable_sentinel_t}} with any value of {{lconcept|weakly_incrementable}} type | notes={{mark c++20}} }}
+
{{dsc tfun | cpp/iterator/unreachable_sentinel_t | inlinemem=true | title=operator== | compares an {{tt|unreachable_sentinel_t}} with a value of any {{lconcept|weakly_incrementable}} type | notes={{mark c++20}} }}
 
{{dsc end}}
 
{{dsc end}}
  

Revision as of 06:19, 2 February 2020

 
 
Iterator library
Iterator concepts
Iterator primitives
Algorithm concepts and utilities
Indirect callable concepts
Common algorithm requirements
(C++20)
(C++20)
(C++20)
Utilities
(C++20)
Iterator adaptors
unreachable_sentinel_tunreachable_sentinel
(C++20)(C++20)
Range access
(C++11)(C++14)
(C++14)(C++14)  
(C++11)(C++14)
(C++14)(C++14)  
(C++17)(C++20)
(C++17)
(C++17)
 
Defined in header <iterator>
struct unreachable_sentinel_t;
(1) (since C++20)
inline constexpr unreachable_sentinel_t unreachable_sentinel{};
(2) (since C++20)
1) unreachable_sentinel_t is an empty class type that can be used to denote the “upper bound” of an unbounded interval.
2) unreachable_sentinel is a constant of type unreachable_sentinel_t.

Contents

Non-member functions

operator==
(C++20)
compares an unreachable_sentinel_t with a value of any weakly_incrementable type
(function template)

operator==(std::unreachable_sentinel_t)

template<std::weakly_incrementable I>

friend constexpr operator==( unreachable_sentinel_t, const I& ) noexcept

{ return false; }
(since C++20)

unreachable_sentinel_t can be compared with any weakly_incrementable type and the result is always false.

This function template is not visible to ordinary unqualified or qualified lookup, and can only be found by argument-dependent lookup when std::unreachable_sentinel_t is an associated class of the arguments.

Example

#include <cstddef>
#include <iterator>
#include <algorithm>
#include <iostream>
 
template<class CharT>
std::size_t ntcts_len(const CharT *s)
{
    return std::ranges::find(s, std::unreachable_sentinel, CharT{}) - s;
}
 
int main()
{
    std::cout
        << ntcts_len("The quick brown fox jumps over the lazy dog.") << '\n';
}

Output:

44

See also

a view consisting of a sequence generated by repeatedly incrementing an initial value
(class template) (customization point object)[edit]