std::regex_...gex_iterator(3)
okay bestie, this is the std::regex_...gex_iterator(3) page from the C++ Standard Library manual, and we're talking about the std::regex_iterator::regex_iterator constructor. Yes, the name is giving βI am my own iconβ β constructor realness π
.
πΈ NAME πΈ
std::regex_iterator::regex_iteratorβstd::regex_iterator::regex_iterator. That's the constructor, bestie; it's literally named after the class and we respect it.
π Synopsis π
regex_iterator();
(1) (since C++11)
regex_iterator( BidirIt a, BidirIt b,
const regex_type& re,
(2) (since C++11)
std::regex_constants::match_flag_type m =
std::regex_constants::match_default );
regex_iterator( const regex_iterator& );
(3) (since C++11)
regex_iterator( BidirIt, BidirIt,
const regex_type&&,
std::regex_constants::match_flag_type =
(4) (since C++11)
std::regex_constants::match_default ) =
delete;
Constructs a new regex_iterator. All four overloads are (since C++11), and they are doing very different things:
(1)β default constructor. Constructs an end-of-sequence iterator.(2)β constructs aregex_iteratorfrom the sequence of characters[a, b), the regular expressionre, and a flagmthat governs matching behavior. This constructor performs an initial call tostd::regex_searchwith this data. If the result of this initial call isfalse,*thisis set to an end-of-sequence iterator.(3)β copies aregex_iterator.(4)β the overload(2)is not allowed to be called with a temporary regex, since the returned iterator would be immediately invalidated.
temporary regex + overload(2)= immediately invalidated iterator, which is why overload(4)is= delete;. The compiler is literally guarding the vibe πβ¨
π Parameters π
aβLegacyBidirectionalIteratorto the beginning of the target character sequence.bβLegacyBidirectionalIteratorto the end of the target character sequence.reβ regular expression used to search the target character sequence.mβ flags that govern the behavior ofre.
π Example π
// Run this code
#include <iostream>
#include <regex>
#include <string_view>
int main()
{
constexpr std::string_view str{R"(
#ONE: *p = &Mass;
#Two: MOV %rd, 42
)"};
const std::regex re("[a-w]");
// create regex_iterator, overload (2)
auto it = std::regex_iterator<std::string_view::iterator>
{
str.cbegin(), str.cend(),
re // re is lvalue; if an immediate expression was used
// instead, e.g. std::regex{"[a-z]"}, this would
// produce an error since overload (4) is deleted
};
for (decltype(it) last /* overload (1) */; it != last; ++it)
std::cout << (*it).str();
std::cout << '\n';
}
Output:
password
π©Ή Defect reports π©Ή
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
- DR:
LWG 2332- Applied to:
C++11 - Behavior as published: a
regex_iteratorconstructed from a temporarybasic_regexbecame invalid immediately - Correct behavior: such construction is disallowed via a deleted overload
- Applied to:
That's the whole page, bestie β source/version: cppreference.com, dated 2024.06.10. Go forth and let your iterators slay π
β¨π«Ά
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms