REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
Loading...
Searching...
No Matches
real::compat::regex_iterator< BidirIt, CharT, Traits > Class Template Reference

Iterates the non-overlapping matches of a pattern in a sequence (std::regex_iterator). More...

#include <regex_iter.hpp>

Collaboration diagram for real::compat::regex_iterator< BidirIt, CharT, Traits >:
[legend]

Public Types

using value_type = match_results< BidirIt >
 Yielded match.
 
using difference_type = std::ptrdiff_t
 Iterator traits.
 
using pointer = const value_type *
 Arrow type.
 
using reference = const value_type &
 Dereference type.
 
using iterator_category = std::forward_iterator_tag
 std::regex_iterator parity.
 
using regex_type = basic_regex< CharT, Traits >
 The pattern type.
 

Public Member Functions

 regex_iterator ()=default
 Constructs the end sentinel.
 
 regex_iterator (BidirIt first, BidirIt last, const regex_type &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 Constructs a begin iterator over [first, last) and finds the first match.
 
 regex_iterator (const regex_iterator &other)
 Copies the iteration position but not the walker (an accelerator over real_pos_). Cloning its VM scratch, or sharing it copy-on-write, would cost every it++; a copy builds its own walker only if it advances.
 
regex_iterator & operator= (const regex_iterator &other)
 Copy-assigns the iteration position, dropping any walker this iterator owned.
 
 regex_iterator (regex_iterator &&) noexcept=default
 Moves the walker along with the position.
 
regex_iterator & operator= (regex_iterator &&) noexcept=default
 Move-assigns, carrying the walker along with the position.
 
 ~regex_iterator ()=default
 Releases the walker, if any.
 
 regex_iterator (BidirIt first, BidirIt last, const regex_type &&re, regex_constants::match_flag_type flags=regex_constants::match_default)=delete
 Constructing from a temporary regex would dangle (std::regex_iterator parity).
 
reference operator* () const
 The current match.
 
pointer operator-> () const
 The current match.
 
regex_iterator & operator++ ()
 Advances to the next match, becoming the end sentinel when there is none.
 
regex_iterator operator++ (int)
 Advances to the next match, returning the previous position.
 
bool operator== (const regex_iterator &other) const
 Equality. Two non-end iterators compare equal only for the same regex, sequence, flags and current match — not for a coincidental same position across different patterns.
 
bool operator!= (const regex_iterator &other) const
 Inequality, the negation of operator==.
 

Private Types

using walker_type = real::basic_match_iterator< real::detail::dynamic_storage >
 The REAL walker: an accelerator only, real_pos_ stays the source of truth.
 

Private Member Functions

bool same_position (const regex_iterator &other) const
 operator== between two live iterators.
 
void next_real ()
 Advances the real path: one step of the walker, built on first use at real_pos_.
 
template<typename RealMatch >
void emit (const RealMatch &result)
 Makes result the current match, and the place the next one is searched from.
 
void sync_std ()
 Syncs the std path from the wrapped std::regex_iterator.
 

Private Attributes

detail::subject_for< BidirIt > subject_
 Non-contiguous range: the copy REAL walks; declared before the walker, which views it.
 
std::unique_ptr< walker_type > walker_
 Owned, never copied – see the copy constructor.
 
BidirIt begin_ {}
 Start of the sequence.
 
BidirIt end_ {}
 End of the sequence.
 
const regex_type * re_ {nullptr}
 The pattern, borrowed.
 
regex_constants::match_flag_type flags_ {regex_constants::match_default}
 Match flags this iteration was built with.
 
bool real_path_ {false}
 Whether the REAL engine drives the traversal rather than the std backend.
 
std::size_t real_pos_ {}
 REAL path: byte offset the next region search starts at.
 
std::size_t matched_ {}
 REAL path: matches made so far, saturating at 2 (only the first is retried without context).
 
bool last_empty_ {}
 REAL path: the current match is empty.
 
std::optional< std::regex_iterator< BidirIt > > std_it_
 std path: the wrapped iterator (engaged only off the REAL path).
 
value_type match_
 The current match, refilled by each increment.
 
bool at_end_ {true}
 Whether this is the end sentinel.
 

Detailed Description

template<typename BidirIt, typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
class real::compat::regex_iterator< BidirIt, CharT, Traits >

Iterates the non-overlapping matches of a pattern in a sequence (std::regex_iterator).

REAL drives the traversal when basic_regex::uses_real_traversal holds and detail::real_honors accepts the flags; otherwise this wraps a std::regex_iterator. Default-constructed, it is the end sentinel.

Template Parameters
BidirItA bidirectional iterator into the searched sequence.

Constructor & Destructor Documentation

◆ regex_iterator() [1/2]

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
real::compat::regex_iterator< BidirIt, CharT, Traits >::regex_iterator ( BidirIt  first,
BidirIt  last,
const regex_type &  re,
regex_constants::match_flag_type  flags = regex_constants::match_default 
)
inline

Constructs a begin iterator over [first, last) and finds the first match.

Parameters
[in]firstStart of the character sequence.
[in]lastEnd of the character sequence.
[in]reThe pattern; it must outlive this iterator.
[in]flagsMatch flags; a constraining one routes the iteration to std.

◆ regex_iterator() [2/2]

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
real::compat::regex_iterator< BidirIt, CharT, Traits >::regex_iterator ( const regex_iterator< BidirIt, CharT, Traits > &  other)
inline

Copies the iteration position but not the walker (an accelerator over real_pos_). Cloning its VM scratch, or sharing it copy-on-write, would cost every it++; a copy builds its own walker only if it advances.

Parameters
[in]otherThe iterator to copy.

Member Function Documentation

◆ emit()

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
template<typename RealMatch >
void real::compat::regex_iterator< BidirIt, CharT, Traits >::emit ( const RealMatch &  result)
inlineprivate

Makes result the current match, and the place the next one is searched from.

Template Parameters
RealMatchA match with the subject's offsets.
Parameters
[in]resultThe match.

◆ next_real()

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
void real::compat::regex_iterator< BidirIt, CharT, Traits >::next_real ( )
inlineprivate

Advances the real path: one step of the walker, built on first use at real_pos_.

Note
One walker serves the whole iteration: it carries the per-haystack routing state (prefilter density verdicts, DFA warmup), which a fresh search() per match would re-derive every time. It is never copied; see the copy constructor.

◆ operator!=()

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
bool real::compat::regex_iterator< BidirIt, CharT, Traits >::operator!= ( const regex_iterator< BidirIt, CharT, Traits > &  other) const
inline

Inequality, the negation of operator==.

Parameters
[in]otherThe iterator to compare against.
Returns
Whether the two denote different iteration positions.

◆ operator*()

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
reference real::compat::regex_iterator< BidirIt, CharT, Traits >::operator* ( ) const
inline

The current match.

Returns
A reference to it, valid until the next increment.

◆ operator++() [1/2]

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
regex_iterator & real::compat::regex_iterator< BidirIt, CharT, Traits >::operator++ ( )
inline

Advances to the next match, becoming the end sentinel when there is none.

Returns
*this.

◆ operator++() [2/2]

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
regex_iterator real::compat::regex_iterator< BidirIt, CharT, Traits >::operator++ ( int  )
inline

Advances to the next match, returning the previous position.

Returns
A copy of *this as it was before the increment.

◆ operator->()

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
pointer real::compat::regex_iterator< BidirIt, CharT, Traits >::operator-> ( ) const
inline

The current match.

Returns
A pointer to it, valid until the next increment.

◆ operator=() [1/2]

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
regex_iterator & real::compat::regex_iterator< BidirIt, CharT, Traits >::operator= ( const regex_iterator< BidirIt, CharT, Traits > &  other)
inline

Copy-assigns the iteration position, dropping any walker this iterator owned.

Parameters
[in]otherThe iterator to copy.
Returns
*this.

◆ operator=() [2/2]

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
regex_iterator & real::compat::regex_iterator< BidirIt, CharT, Traits >::operator= ( regex_iterator< BidirIt, CharT, Traits > &&  )
defaultnoexcept

Move-assigns, carrying the walker along with the position.

Returns
*this.

◆ operator==()

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
bool real::compat::regex_iterator< BidirIt, CharT, Traits >::operator== ( const regex_iterator< BidirIt, CharT, Traits > &  other) const
inline

Equality. Two non-end iterators compare equal only for the same regex, sequence, flags and current match — not for a coincidental same position across different patterns.

Parameters
[in]otherThe iterator to compare against.
Returns
Whether the two denote the same iteration position.

◆ same_position()

template<typename BidirIt , typename CharT = typename std::iterator_traits<BidirIt>::value_type, typename Traits = std::regex_traits<CharT>>
bool real::compat::regex_iterator< BidirIt, CharT, Traits >::same_position ( const regex_iterator< BidirIt, CharT, Traits > &  other) const
inlineprivate

operator== between two live iterators.

Out of line so that operator== itself inlines: it != std::sregex_iterator() builds and compares an end sentinel at every step, and with this comparison inline clang kept the whole operator out of line.

Parameters
[in]otherA live iterator.
Returns
Whether both denote the same match of the same iteration.

The documentation for this class was generated from the following file: