This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of C++14 status.
std::regex_replaceSection: 28.6.10.4 [re.alg.replace] Status: C++14 Submitter: Pete Becker Opened: 2012-11-08 Last modified: 2017-07-05
Priority: 0
View all other issues in [re.alg.replace].
View all issues with C++14 status.
Discussion:
In 28.6.10.4 [re.alg.replace], the first two variants of std::regex_replace take an output iterator named
"out" as their first argument. Paragraph 2 of that section says that the functions return "out". When I first implemented
this, many years ago, I wrote it to return the value of the output iterator after all the insertions (cf. std::copy),
which seems like the most useful behavior. But looking at the requirement now, it like the functions should return the
original value of "out" (i.e. they have to keep a copy of the iterator for no reason except to return it). Is that
really what was intended?
[Issaquah 2014-02-11: Move to Immediate]
Proposed resolution:
This wording is relative to N3485.
Edit 28.6.10.4 [re.alg.replace] as indicated:
template <class OutputIterator, class BidirectionalIterator, class traits, class charT, class ST, class SA> OutputIterator regex_replace(OutputIterator out, BidirectionalIterator first, BidirectionalIterator last, const basic_regex<charT, traits>& e, const basic_string<charT, ST, SA>& fmt, regex_constants::match_flag_type flags = regex_constants::match_default); template <class OutputIterator, class BidirectionalIterator, class traits, class charT> OutputIterator regex_replace(OutputIterator out, BidirectionalIterator first, BidirectionalIterator last, const basic_regex<charT, traits>& e, const charT* fmt, regex_constants::match_flag_type flags = regex_constants::match_default);-1- Effects: Constructs a
-2- Returns:regex_iteratorobjectias if byregex_iterator<BidirectionalIterator, charT, traits> i(first, last, e, flags), and usesito enumerate through all of the matchesmof typematch_results<BidirectionalIterator>that occur within the sequence[first, last). If no such matches are found and!(flags & regex_constants ::format_no_copy)then callsout = std::copy(first, last, out). If any matches are found then, for each such match, if!(flags & regex_constants::format_no_copy), callsout = std::copy(m.prefix().first, m.prefix().second, out), and then callsout = m.format(out, fmt, flags)for the first form of the function andout = m.format(out, fmt, fmt + char_traits<charT>::length(fmt), flags)for the second. Finally, if such a match is found and!(flags & regex_constants ::format_no_copy), callsout = std::copy(last_m.suffix().first, last_m.suffix().second, out)wherelast_mis a copy of the last match found. Ifflags & regex_constants::format_first_onlyis non-zero then only the first match found is replaced.out.