REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
Loading...
Searching...
No Matches
real::compat::detail::lazy_std_engine< StdRegex > Class Template Reference

An engine built on first use and published once: a reader after the build takes no lock, and a copy made while another thread builds sees the finished engine or none (and then builds its own). Copyable, so the regex that holds it stays copyable. More...

#include <regex_core.hpp>

Public Member Functions

 lazy_std_engine (const lazy_std_engine &other)
 Copies other's engine if it is published.
 
 lazy_std_engine (lazy_std_engine &&other) noexcept
 Takes other's engine if it is published; other is left without one.
 
lazy_std_engine & operator= (const lazy_std_engine &other)
 Replaces this engine with a copy of other's, if published.
 
lazy_std_engine & operator= (lazy_std_engine &&other) noexcept
 Replaces this engine with other's, if published; other is left without one.
 
const StdRegex * get () const noexcept
 The published engine.
 
const StdRegex & publish (StdRegex &&engine) const
 Publishes engine; the caller holds the build lock and has seen get return null.
 
void reset () noexcept
 Drops the engine; not concurrent with any other use of this object.
 
void swap (lazy_std_engine &other) noexcept
 Exchanges the engines; not concurrent with any other use of either object.
 

Private Member Functions

void copy_from (const lazy_std_engine &other)
 Copies other's engine if published; this one holds none.
 

Private Attributes

std::optional< StdRegex > value_
 The engine, set once under the build lock.
 
std::atomic< bool > ready_ {false}
 Released after value_ is set: acquire it before reading.
 

Detailed Description

template<typename StdRegex>
class real::compat::detail::lazy_std_engine< StdRegex >

An engine built on first use and published once: a reader after the build takes no lock, and a copy made while another thread builds sees the finished engine or none (and then builds its own). Copyable, so the regex that holds it stays copyable.

Template Parameters
StdRegexThe engine: a std::basic_regex, or the end_variants of a REAL pattern.

Constructor & Destructor Documentation

◆ lazy_std_engine() [1/2]

template<typename StdRegex >
real::compat::detail::lazy_std_engine< StdRegex >::lazy_std_engine ( const lazy_std_engine< StdRegex > &  other)
inline

Copies other's engine if it is published.

Parameters
[in]otherThe source.

◆ lazy_std_engine() [2/2]

template<typename StdRegex >
real::compat::detail::lazy_std_engine< StdRegex >::lazy_std_engine ( lazy_std_engine< StdRegex > &&  other)
inlinenoexcept

Takes other's engine if it is published; other is left without one.

Parameters
[in,out]otherThe source.

Member Function Documentation

◆ copy_from()

template<typename StdRegex >
void real::compat::detail::lazy_std_engine< StdRegex >::copy_from ( const lazy_std_engine< StdRegex > &  other)
inlineprivate

Copies other's engine if published; this one holds none.

Parameters
[in]otherThe source.

◆ get()

template<typename StdRegex >
const StdRegex * real::compat::detail::lazy_std_engine< StdRegex >::get ( ) const
inlinenoexcept

The published engine.

Returns
It, or null before publish.

◆ operator=() [1/2]

template<typename StdRegex >
lazy_std_engine & real::compat::detail::lazy_std_engine< StdRegex >::operator= ( const lazy_std_engine< StdRegex > &  other)
inline

Replaces this engine with a copy of other's, if published.

Parameters
[in]otherThe source.
Returns
This.

◆ operator=() [2/2]

template<typename StdRegex >
lazy_std_engine & real::compat::detail::lazy_std_engine< StdRegex >::operator= ( lazy_std_engine< StdRegex > &&  other)
inlinenoexcept

Replaces this engine with other's, if published; other is left without one.

Parameters
[in,out]otherThe source.
Returns
This.

◆ publish()

template<typename StdRegex >
const StdRegex & real::compat::detail::lazy_std_engine< StdRegex >::publish ( StdRegex &&  engine) const
inline

Publishes engine; the caller holds the build lock and has seen get return null.

Parameters
[in]engineThe built engine.
Returns
The published engine.

◆ swap()

template<typename StdRegex >
void real::compat::detail::lazy_std_engine< StdRegex >::swap ( lazy_std_engine< StdRegex > &  other)
inlinenoexcept

Exchanges the engines; not concurrent with any other use of either object.

Parameters
[in,out]otherThe other engine.

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