Proposed resolution for US104: Allocator-aware regular expressions (rev 4)

Similar documents
Proposed resolution for US104: Allocator-aware regular expressions (rev 3)

Proposed resolution for US104: Allocator-aware regular expressions (rev 3)

p0506r2 - use string_view for library function parameters instead of const string &/const char *

p0407r2 - Allocator-aware basic_stringbuf

p0408r4 - Efficient Access to basic_stringbuf s Buffer Including wording from p0407 Allocator-aware basic_stringbuf

p0448r0 - A strstream replacement using span<chart> as

Apply the following edits to N4741, the working draft of the Standard. The feature test macros cpp_lib_latch and cpp_lib_barrier should be created.

Initializer Lists for Standard Containers

Document Number: P0429R4 Date: Reply to: 0.1 Revisions... 1

p0448r1 - A strstream replacement using span<chart> as buffer

Revised Latches and Barriers for C++20

Splicing Maps and Sets (Revision 1)

Making std::vector constexpr

Variant: a type-safe union without undefined behavior (v2).

Iterator Concepts for the C++0x Standard Library

Proposed Wording for Concurrent Data Structures: Hazard Pointer and Read Copy Update (RCU)

A Unit Type for C++ Introduction. Related proposals. Proposed changes

Summary. Design. Layout

Variant: a typesafe union. ISO/IEC JTC1 SC22 WG21 N4218

p0408r2 - Efficient Access to basic_stringbuf s Buffer

A Standard flat_set. This paper outlines what a (mostly) API-compatible, non-node-based set might look like.

Allocators for stringstream (US140)

A jthread automatically signals an interrupt at the end of its lifetime to the started thread (if still joinable) and joins:

Working Draft, Technical Specification for C++ Extensions for Parallelism

A Standard flat_map. 1 Revisions. 2 Introduction. 3 Motivation and Scope. 1.1 Changes from R Changes from R0

Controlling Thread Stack Size at Creation Time

A polymorphic value-type for C++

Concepts for the C++0x Standard Library: Iterators (Revision 2)

Source-Code Information Capture

A Cooperatively Interruptible Joining Thread, Rev 4 New in R4

Bring Back the Obvious Definition of count()

Bind Returned/Initialized Objects to the Lifetime of Parameters, Rev0

Fixing Atomic Initialization, Rev1

Revising the wording of stream input operations

Concepts for the C++0x Standard Library: Iterators

Proposed Resolution to TR1 Issues 3.12, 3.14, and 3.15

Doc. No.: WG21/N0937=X3J16/ Date: 28 May 1996 Project: C++ Standard Library Reply to: Nathan Myers

Adding std::*_semaphore to the atomics clause.

Variant: a type-safe union that is rarely invalid (v5).

Polymorphic Memory Resources - r2

Harmonizing Effects and Returns Elements in Clause 21

Efficient concurrent waiting for C++20

Hazard Pointers. Safe Resource Reclamation for Optimistic Concurrency

Proposal to Simplify pair (rev 4)

Polymorphic Allocators

Constraining unique_ptr

Integrating std::string_view and std::string

Efficient waiting for concurrent programs

A Standard flat_map. Drop the requirement on container contiguity; sequence container will do.

contiguous_container proposal

Doc. no.: N2035= Date: Project: Programming Language C++ Subgroup: Library Reply to: Matthew Austern

Interrupt Tokens and a Joining Thread, Rev 7 New in R7

Explicitly Implicifying explicit Constructors

Variant: a type-safe union (v3).

Standard Library Reference

A polymorphic value-type for C++

Proposed Wording for Concurrent Data Structures: Hazard Pointer and Read Copy Update (RCU)

Improving improved shared_ptr. 1.Overview. 2.Motivation. 3.Proposed text [util.smartptr.shared]

P0591r4 Utility functions to implement uses-allocator construction

Template for comments and secretariat observations Date: Document: WG21 N4708 Project: 19216

[[nodiscard]] in the Library, Rev1

Allocators post Removal of C++ Concepts

A Parallel Algorithms Library N3724

More Improvements to std::future<t> - Revision 1

Working Draft, Technical Specification for C++ Extensions for Parallelism, Revision 1

A polymorphic value type for C++

async and ~future (Revision 3)

Introduction to N1031. Components of N1031. Guiding Principles. Walk through, issues, and rationale

Generalized pointer casts

Concepts for the C++0x Standard Library: Containers

Cleaning up noexcept in the Library (Rev 3) Changes in Revisions. Motivation. Background of the Problem

simd<t> Finding the right set of traits for Document Number: P0964R1 Date: Matthias Kretz Target: Parallelism TS 2

Variant: Discriminated Union with Value Semantics

ADD TEST POLYMORPHIC MEMORY RESOURCE TO THE STANDARD LIBRARY

C++ For Science and Engineering Lecture 27

A Cooperatively Interruptible Joining Thread, Rev 2

Class Types in Non-Type Template Parameters

Concepts for the C++0x Standard Library: Containers (Revision 1)

Source-Code Information Capture

Qualified std::function signatures

Allowing Class Template Specializations in Associated Namespaces (revision 1)

ValuedOrError and ValueOrNone types. Table of Contents. Introduction. Date: ISO/IEC JTC1 SC22 WG21 Programming Language C++

Introduction. Contents. Homogeneous interface for variant<ts...>, any and optional<t>

by Pearson Education, Inc. All Rights Reserved. 2

A Standard flat_map. 1 Introduction. 2 Motivation and Scope

Explicit Conversion Operator Draft Working Paper

Class Types in Non-Type Template Parameters

Exercise 6.2 A generic container class

Sizes Should Only span Unsigned

EECE.3220: Data Structures Spring 2017

Project: ISO C++ Date: Doc. No.: J16/ = WG21/N1160 Author: Nathan Myers

TS Further Interoperability of Fortran with C WG5/N1917

Cleaning up Clause 20

Hazard Pointers. Safe Resource Reclamation for Optimistic Concurrency

Auxiliary class interfaces

Basic Types, Variables, Literals, Constants

Exploring the design space of contract specifications for C++

polymorphic_allocator<> as a vocabulary type

Template for comments and secretariat observations Date: Document: SC22 WG21 N4616 Project: 19568

Data-Parallel Vector T ypes & Operations

Transcription:

Document number: P0269R0 Revision of: N4255 Date: 2016-02-14 Reply-to: mike_spertus@symantec.com Authors : Michael Spertus - mike_spertus@symantec.com John Maddock - boost.regex@virgin.net Audience: Library Working Group Proposed resolution for US104: Allocator-aware regular expressions (rev 4) Rationale The standard library contains many data structures that hold user data, such as containers (23), strings (21), string streams (27.8), and string buffers (27.8). These data structures are allocator-aware, using storage allocators (20.2.5) to manage their storage requirements and internal pointer representations. However, regular expressions (28) are not allocator-aware. Such inconsistent treatment creates complexity by giving C++ programmers another inconsistency to remember. More importantly, the reasons for making the above data structures allocator-aware apply equally well to regular expressions. At Symantec, we have had to engineer around the lack of allocatorsupport in regular expressions because tr1::regex objects cannot be placed in shared memory as they cannot be assigned a shared memory allocator. While the overall notion of allocators has generated some controversy within the C++ community, it seems clear that as long as other C++ containers are allocator-aware, regular expressions should be also. Finally, it should be noted that C++0x regular expressions already differ fromtr1 regular expressions, so it is possible to rectify this situation for C++0x, but once normatively standardized, it will be extremely difficult if not impossible to make such a breaking change. Approach The proposed wording below was arrived at mutatis mutandis from the corresponding wording from string. However, a few comments are in order. 1. Class match_results (28.10) currently uses an allocator. This allocator has no relationship to the allocator used internally in the regular expression, as has always been the case (regarding the current regex as regular expression using the standard allocator). Similar comments apply to string allocators. 2. Although most C++ containers consistently use pointer traits internally, regex_traits use locales, so they cannot be, say, shared using an interprocess allocator. Note that basic_stringstream and basic_stringbuf already use both allocators and locales, so supporting allocators in regular expressions do not introduce any new problems. Although these locale considerations prevent regular expressions using std::regex_traits from being shared between processes, there is no reason to prevent users from defining their own allocator-aware regex traits. To facilitate this, based on uses_allocator<traits, Allocator>, std::basic_regex either default constructs regex_traits (e.g.

std::regex_traits ) or construct s from an allocator. We allow imbue to throw a regex_error (although std::regex_traits doesn t) as user-defined regex_traits may not be able to handle all possible locales (e.g., some custom locales). Status A working implementation is available. In addition, an exemplary user-defined regex_traits is available that allows locales to be passed between process based on their locale names. Wording In 17.6.3.5p1, change the final sentence to All of the string types (Clause 21), containers (Clause 23) (except array (Clause 23)), string buffers and string streams (Clause 27), regular expressions (clause 28), and match_results (Clause 28) are parameterized in terms of allocators. Apply the following changes to clause 28. Note that if this is applied to a TS, include wording to the effect that the text from clause 28 should be included with the following changes. 28.3 Requirements [re.req] In the entry for u.imbue in table 137 add: Reports an error by throwing an exception of type regex_error At the end of 28.3, add the following paragraph. Class template basic_regex satisfies the requirements for an Allocator-aware container (Table 99), except that basic_regex does not construct or destroy any objects using allocator_traits<alloc>::construct and allocator_traits<alloc>::destroy 28.4 Header <regex> synopsis // 28.8, class template basic_regex: template <class chart, class traits = regex_traits<chart>, class Allocator = allocator<chart> > class basic_regex; // 28.8.6, basic_regex swap: template <class chart, class traits, class Allocator> void swap(basic_regex<chart, traits, Allocator>& e1, basic_regex<chart, traits, Allocator>& e2) noexcept(noexcept(e1.swap(e2)); // 28.11.2, function template regex_match: template <class BidirectionalIterator, class AllocatorMA, class chart, class traits, class MA> bool regex_match(bidirectionaliterator first, BidirectionalIterator last, match_results<bidirectionaliterator, AllocatorMA>& m,

template <class BidirectionalIterator, class chart, class traits, class RA> bool regex_match(bidirectionaliterator first, BidirectionalIterator last, template <class chart, class AllocatorMA, class traits, class RA> bool regex_match(const chart* str, match_results<const chart*, AllocatorMA> &m, const basic_regex<chart, traits, RA> &e, template <class ST, class SA, class AllocatorMA,class chart, class traits, class RA> bool regex_match(const basic_string<chart, ST, SA>& s, match_results< typename basic_string<chart, ST, SA>::const_iterator, AllocatorMA>& m, template <class chart, class traits, class RA> bool regex_match(const chart* str, template <class ST, class SA, class chart, class traits, class RA> bool regex_match(const basic_string<chart, ST, SA>& s, // 28.11.3, function template regex_search: template <class BidirectionalIterator, class AllocatorMA, class chart, class traits, class RA> bool regex_search(bidirectionaliterator first, BidirectionalIterator last, match_results<bidirectionaliter, AllocatorMA>& m, template <class BidirectionalIterator, class chart, class traits, class RA> bool regex_search(bidirectionaliterator first, BidirectionalIterator last, template <class chart, class Allocator, class traits, class RA> bool regex_search(const chart* str, match_results<const chart*, Allocator>& m, template <class chart, class traits, class RA> bool regex_search(const chart* str, const basic_regex<chart, traits, RA >& e, template <class ST, class SA, class chart, class traits, class RA> bool regex_search(const basic_string<chart, ST, SA>& s, template <class ST, class SA, class, class AllocatorMA, class chart, class traits, class RA> bool regex_search(const basic_string<chart, ST, SA>& s, match_results< typename basic_string<chart, ST, SA>::const_iterator, AllocatorMA>& m,

// 28.11.4, function template regex_replace: template <class OutputIterator, class BidirectionalIterator, class traits, class chart, class ST, class SA, class RA> OutputIterator regex_replace(outputiterator out, BidirectionalIterator first, BidirectionalIterator last, const basic_string<chart, ST, SA>& fmt, template <class OutputIterator, class BidirectionalIterator, class traits, class chart, class RA> OutputIterator regex_replace(outputiterator out, BidirectionalIterator first, BidirectionalIterator last, const chart* fmt, template <class traits, class chart, class ST, class SA, class FST, class FSA, class RA> basic_string<chart, ST, SA> regex_replace(const basic_string<chart, ST, SA>& s, const basic_regex<chart, traits, RA >& e, onst basic_string<chart, FST, FSA>& fmt, template <class traits, class chart, class ST, class SA, class RA> basic_string<chart, ST, SA> regex_replace(const basic_string<chart, ST, SA>& s, const chart* fmt, regex_constants::match_flag_type flags = template <class traits, class chart, class ST, class SA, class RA> basic_string<chart> regex_replace(const chart* s, const basic_string<chart, ST, SA>& fmt, template <class traits, class chart, class RA> basic_string<chart> regex_replace(const chart* s, const chart* fmt, 28.5.3 Implementation-defined error_type [re.err]

namespace std::regex_constants { typedef T3 error_type; constexpr error_type error_collate = unspecified ; constexpr error_type error_ctype = unspecified ; constexpr error_type error_escape = unspecified ; constexpr error_type error_backref = unspecified ; constexpr error_type error_brack = unspecified ; constexpr error_type error_paren = unspecified ; constexpr error_type error_brace = unspecified ; constexpr error_type error_badbrace = unspecified ; constexpr error_type error_range = unspecified ; constexpr error_type error_space = unspecified ; constexpr error_type error_badrepeat = unspecified ; constexpr error_type error_complexity = unspecified ; constexpr error_type error_stack = unspecified ; constexpr error_type error_locale = unspecified ; } The type error_type is an implementation-defined enumerated type (17.5.2.1.2). Values of type error_type represent the error conditions described in Table 139: Table 139 error_type values in the C locale Value Error condition error_collate The expression contained an invalid collating element name. error_ctype The expression contained an invalid character class name. error_escape The expression contained an invalid escaped character, or a trailing escape. error_backref The expression contained an invalid back reference. error_brack The expression contained mismatched [ and ]. error_paren The expression contained mismatched ( and ). error_brace The expression contained mismatched { and }. error_badbrace error_range error_space error_badrepeat error_complexity error_stack error_locale The expression contained an invalid range in a {} expression The expression contained an invalid character range, such as [b-a] in most encodings. There was insufficient memory to convert the expression into a finite state machine. One of *?+{ was not preceded by a valid regular expression. The complexity of an attempted match against a regular expression exceeded a pre-set level. There was insufficient memory to determine whether the regular expression could match the specified character sequence. Unable to imbue with a locale 28.8 Class template basic_regex [re.regex] namespace std { template <class chart, class traits = regex_traits<chart>, class Allocator = allocator<chart> > class basic_regex { public: // types: typedef chart value_type; typedef regex_constants::syntax_option_type flag_type; typedef typename traits::locale_type locale_type; typedef Allocator allocator_type;

// 28.8.2, construct/copy/destroy: basic_regex() noexcept(noexcept(allocator())): basic_regex(allocator()) {} explicit basic_regex(const Allocator& a); explicit basic_regex(const chart* p, flag_type f = regex_constants::ecmascript, const Allocator& a = Allocator()); basic_regex(const chart* p, size_t len, flag_type f, const Allocator& a = Allocator()); basic_regex(const basic_regex&); basic_regex(const basic_regex&, const Allocator&); basic_regex(basic_regex&&) noexcept; basic_regex(const basic_regex&&, const Allocator&); template <class ST, class SA> explicit basic_regex(const basic_string<chart, ST, SA>& p, flag_type f = regex_constants::ecmascript, const Allocator& a = Allocator()); template <class ForwardIterator> basic_regex(forwarditerator first, ForwardIterator last, flag_type f = regex_constants::ecmascript, const Allocator& a = Allocator()); basic_regex(initializer_list<chart>, flag_type = regex_constants::ecmascript, const Allocator& a = Allocator()); ~basic_regex(); basic_regex& operator=(const basic_regex&); basic_regex& operator=(basic_regex&&) noexcept; noexcept(allocator_traits<allocator>::propagate_on_container_move_assignment::value allocator_traits<allocator>::is_always_equal::value); /* no changes until */ // 28.8.6, swap: void swap(basic_regex&); noexcept(allocator_traits<allocator>>::propagate_on_conatainer_swap::value allocator_traits<allocator>::is_always_equal::value); // 28.8.10, allocator (Section number may be chosen editorially): allocator_type get_allocator() const noexcept; 28.8.2 basic_regex constructors [re.regex.construct] basic_regex(); explicit basic_regex(const Allocator& a); Effects: Constructs an object of class basic_regex that does not match any character sequence. explicit basic_regex(const chart* p, flag_type f = regex_constants::ecmascript, const Allocator& a = Allocator()); Requires: p shall not be a null pointer. Throws: regex_error if p is not a valid regular expression. Effects: Constructs an object of class basic_regex; the object s internal finite state machine is constructed from the regular expression contained in the array of chart of length char_traits<chart>:: length(p) whose first element is designated by p, and interpreted according to the flags f. Postconditions: flags() returns f. mark_count() returns the number of marked sub-expressions within the expression. basic_regex(const chart* p, size_t len, flag_type f, const Allocator& a = Allocator()); Requires: p shall not be a null pointer. Throws: regex_error if p is not a valid regular expression. Effects: Constructs an object of class basic_regex; the object s internal finite state machine is constructed from the regular expression contained in the sequence of characters [p,p+len), and interpreted according the flags specified in f. Postconditions: flags() returns f. mark_count() returns the number of marked sub-expressions within the expression. basic_regex(const basic_regex& e); basic_regex(const basic_regex& e, const Allocator&); Effects: Constructs and object of class basic_regex as a copy of the object e. Postconditions: flags() and mark_count() return e.flags() and e.mark_count(), respectively. basic_regex(const basic_regex&& e) noexcept;

basic_regex(const basic_regex&& e, const Allocator&); Effects: Constructs and object of class basic_regex as a copy of the object e. Postconditions: flags() and mark_count() return the values that e.flags() and e.mark_count(), respectively, had before construction. e is in a valid state with unspecified value. template <class ST, class SA> basic_regex(const basic_string<chart, ST, SA>& s, flag_type f = regex_constants::ecmascript, const Allocator& a = Allocator()); Throws: regex_error if s is not a valid regular expression. Effects: Constructs an object of class basic_regex; the object s internal finite state machine is constructed from the regular expression contained in the string s, and interpreted according to the flags specified in f. Postconditions: flags() returns f. mark_count() returns the number of marked sub-expressions within the expression. template <class ForwardIterator> basic_regex(forwarditerator first, ForwardIterator last, flag_type f = regex_constants::ecmascript const Allocator& a = Allocator()); Throws: regex_error if the sequence [first,last) is not a valid regular expression. Effects: Constructs an object of class basic_regex; the object s internal finite state machine is constructed from the regular expression contained in the sequence [first,last), and interpreted according to the flags specified in f. Postconditions: flags() returns f. mark_count() returns the number of marked sub-expressions within the expression. basic_regex(initializer_list<chart> il, flag_type f = regex_constants::ecmascript const Allocator& a = Allocator()); Effects: Same as basic_regex(il.begin(), il.end(), f, a). 28.8.5 basic_regex locale [re.regex.locale] locale_type imbue(locale_type loc); Effects: Returns the result of traits_inst.imbue(loc) where traits_inst is a (default initialized if uses_allocator<traits, Allocator> (20.9.2.2) has a base characteristic (20.7.1) of false and initialized from get_allocator() if uses_allocator<traits, Allocator> has a base characteristic of true) instance of the template type argument traits stored within the object. After a call to imbue the basic_regex object does not match any character sequence. locale_type getloc() const; Effects: Returns the result of traits_inst.getloc() where traits_inst is a (default initialized if uses_allocator<traits, Allocator> has a base characteristic (20.7.1) of false and initialized from get_allocator() if uses_allocator<traits, Allocator> has a base characteristic of true) instance of the template parameter traits stored within the object. 28.8.6 basic_regex swap [re.regex.swap] void swap(basic_regex& e) noexcept(allocator_traits<allocator>::propagate_on_container_move_assignment::value allocator_traits<allocator>::is_always_equal::value); Effects: Swaps the contents of the two regular expressions. Postcondition: *this contains the regular expression that was in e, e contains the regular expression that was in *this. Complexity: Constant time. 28.8.8 basic_regex allocator [re.regex.allocator] allocator_type get_allocator() const noexcept; Returns: a copy of the Allocator object used to construct the basic_regex or, if that allocator has been replaced, a copy of the most recent replacement.

28.11.2 regex_match [re.alg.match] template<class BidirectionalIterator, class AllocatorMA, class chart, class Traits, class RA> bool regex_match(bidirectionaliterator first, BidirectionalIterator last, match_results<bidirectionaliterator, AllocatorMA> &m, const basic_regex<chart, traits, RA>& e, (until after paragraph 3) template <class BidirectionalIterator, class chart, class traits, class RA> bool regex_match(bidirectionaliterator first, BidirectionalIterator last, Effects: Behaves as if by constructing an instance of match_results<bidirectionaliterator> what, and then returning the result of regex_match(first, last, what, e, flags). template <class chart, class AllocatorMA> bool regex_match(const chart* str, match_results<const chart*, AllocatorMA>& m, const basic_regex<chart, traits, RA>&e, Returns: regex_match(str, str + char_traits<chart>::length(str), m, e, flags). template <class ST, class SA, class AllocatorMA, class chart, class traits, class RA> bool regex_match(const basic_string<chart, ST, SA>& s, match_results<typename basic_string<chart, ST, SA>::const_iterator, AllocatorMA>& m, const basic_regex<chart, traits, RA> &e, Returns: regex_match(s.begin(), s.end(), m, e, flags). template <class chart, class traits, class RA > bool regex_match(const chart* str, const basic_regex<chart, traits, RA >& e, Returns: regex_match(str, str + char_traits<chart>::length(str), e, flags) template <class ST, class SA, class chart, class traits, class RA> bool regex_match(const basic_string<chart, ST, SA>& s, Returns: regex_match(s.begin(), s.end(), e, flags). 28.11.3 regex_search [re.alg.search] template <class BidirectionalIterator, class AllocatorMA, class chart, class traits, class RA> bool regex_search(bidirectionaliterator first, BidirectionalIterator last, match_results<bidirectionaliterator, AllocatorMA> &m,

(until after paragraph 3) template <class chart, class AllocatorMA, class traits, class RA> bool regex_search(const chart* str, match_results<const chart*, AllocatorMA>& m, Returns: The result of regex_search(str, str + char_traits<chart>::length(str), m, e, flags). template <class ST, class SA, class chart, class traits, class RA>bool regex_search(const basic_string<chart, ST, SA>& s, Returns: The result of regex_search(s.begin(), s.end(), m, e, flags). template <class BidirectionalIterator, class chart, class traits, class RA> bool regex_search(bidirectionaliterator first, BidirectionalIterator last, Effects: Behaves as if by constructing an object what of type match_results<bidirectionaliterator>, and then returning the result of regex_search(first, last, what, e, flags). template <class chart, class traits, class RA> bool regex_search(const chart* str, Returns: regex_search(str, str + char_traits<chart>::length(str), e, flags). template <class ST, class SA, class chart, class traits, class RA> bool regex_search(const basic_string<chart, ST, SA>& s, Returns: regex_search(s.begin(), s.end(), e, flags). 28.11.4 regex_replace [re.alg.replace] template <class OutputIterator, class BidirectionalIterator, class traits, class chart, class ST, class SA, class RA> OutputIterator regex_replace(outputiterator out, BidirectionalIterator first, BidirectionalIterator last, const basic_string<chart, ST, SA>& fmt, template <class OutputIterator, class BidirectionalIterator, class traits, class chart, class RA> OutputIterator regex_replace(outputiterator out, BidirectionalIterator first, BidirectionalIterator last, const chart* fmt,

(until after paragraph 2) template <class traits, class chart, class ST, class SA, class FST, class FSA, class RA> basic_string<chart, ST, SA> regex_replace(const basic_string<chart, ST, SA>& s, const basic_string<chart, FST, FSA>& fmt, template <class traits, class chart, class ST, class SA, class RA> basic_string<chart, ST, SA>regex_replace(const basic_string<chart, ST, SA>& s, const chart* fmt, regex_constants::match_flag_type flags = Effects: Constructs an empty string result of type basic_string<chart, ST, SA> and calls regex_replace(back_inserter(result), s.begin(), s.end(), e, fmt, flags). Returns: result. template <class traits, class chart, class ST, class SA, class RA> basic_string<chart> regex_replace(const chart* s, const basic_string<chart, ST, SA>& fmt, template <class traits, class chart, class RA> basic_string<chart> regex_replace(const chart* s, const chart* fmt, regex_constants::match_flag_type flags = Effects: Constructs an empty string result of type basic_string<chart> and calls regex_replace(back_inserter(result), s, s + char_traits<chart>::length(s), e, fmt, flags). Returns: result. 28.13 Modified ECMAScript regular expression grammar [re.grammar] The regular expression grammar recognized by basic_regex objects constructed with the ECMAScript flag is that specified by ECMA-262, except as specified below. Objects of type specialization of basic_regex store within themselves an default-constructed instance of their traits template parameter, henceforth referred to as traits_inst. It is default constructed if uses_allocator<traits, Allocator> has a base characteristic (20.7.1) of false and constructed from get_allocator() if uses_allocator<traits, Allocator> has a base characteristic of true. This traits_inst object is used to support localization of the regular expression; basic_regex member functions shall not call any locale dependent C or C++ API, including the formatted string input functions. Instead they shall call the appropriate traits member function to achieve the required effect.