REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
Loading...
Searching...
No Matches
real::detail::name_context_box Class Reference

A uniquely-owning, deep-copying box for owned_name_context that survives constant evaluation. More...

#include <storage.hpp>

Collaboration diagram for real::detail::name_context_box:
[legend]

Public Member Functions

constexpr name_context_box () noexcept=default
 Constructs an empty box, owning nothing.
 
constexpr name_context_box (const name_context_box &other)
 Deep-copies the other box's context, if it has one.
 
constexpr name_context_box (name_context_box &&other) noexcept
 Takes over the other box's context, leaving it empty.
 
constexpr name_context_boxoperator= (const name_context_box &other)
 Deep-copy assignment.
 
constexpr name_context_boxoperator= (name_context_box &&other) noexcept
 Move assignment.
 
constexpr ~name_context_box ()
 Releases the owned context, if any.
 
constexpr void emplace (std::string pattern, std::vector< named_group > names)
 Replaces the owned context with one built from pattern and names.
 
constexpr const owned_name_contextget () const noexcept
 Returns the owned context, or nullptr when the box is empty.
 

Private Member Functions

constexpr void adopt (const owned_name_context &src)
 Allocates and copy-constructs a context from src.
 
constexpr void release () noexcept
 Releases the owned context. Precondition: the box owns one.
 
constexpr void reset () noexcept
 Destroys and deallocates the owned context, if any.
 

Private Attributes

owned_name_contextptr_ {nullptr}
 The owned context, or nullptr.
 

Detailed Description

A uniquely-owning, deep-copying box for owned_name_context that survives constant evaluation.

std::shared_ptr is the obvious handle here and cannot be used: a real::regex is constant-evaluable, so the result type it yields must stay literal, and no standard smart pointer is. std::allocator is the only constexpr-usable source in C++20 – the same reason small_vec grows through it – and its blocks are transient, so this releases unconditionally.

Deep copy rather than shared: the box is null on every result that borrows, which is every result a walk or an lvalue regex produces, so nothing on the path that matters ever copies one. What the borrowing path pays is a pointer and a null test.

Constructor & Destructor Documentation

◆ name_context_box() [1/2]

constexpr real::detail::name_context_box::name_context_box ( const name_context_box other)
inlineconstexpr

Deep-copies the other box's context, if it has one.

Parameters
[in]otherThe box to copy.

◆ name_context_box() [2/2]

constexpr real::detail::name_context_box::name_context_box ( name_context_box &&  other)
inlineconstexprnoexcept

Takes over the other box's context, leaving it empty.

Parameters
[in,out]otherThe box to move from.

Member Function Documentation

◆ adopt()

constexpr void real::detail::name_context_box::adopt ( const owned_name_context src)
inlineconstexprprivate

Allocates and copy-constructs a context from src.

Cold: only a result detached from a temporary regex ever owns a context, and only a copy of one ever reaches here. Left warm it bids for the translation unit's inline budget against the scan routes, and takes it from them – the same non-monotonic budget effect build_byte_program is annotated for.

Parameters
[in]srcThe context to copy.

◆ emplace()

constexpr void real::detail::name_context_box::emplace ( std::string  pattern,
std::vector< named_group names 
)
inlineconstexpr

Replaces the owned context with one built from pattern and names.

Parameters
[in]patternThe pattern text to own.
[in]namesThe named-group table to own.

◆ get()

constexpr const owned_name_context * real::detail::name_context_box::get ( ) const
inlineconstexprnoexcept

Returns the owned context, or nullptr when the box is empty.

Returns
The owned context, or nullptr.

◆ operator=() [1/2]

constexpr name_context_box & real::detail::name_context_box::operator= ( const name_context_box other)
inlineconstexpr

Deep-copy assignment.

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

◆ operator=() [2/2]

constexpr name_context_box & real::detail::name_context_box::operator= ( name_context_box &&  other)
inlineconstexprnoexcept

Move assignment.

Parameters
[in,out]otherThe box to move from.
Returns
*this.

◆ release()

constexpr void real::detail::name_context_box::release ( )
inlineconstexprprivatenoexcept

Releases the owned context. Precondition: the box owns one.

Split out of reset, and cold for the same reason as the copy path above: every result on the borrowing path runs the null test and nothing else.


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