Ultra 0.9.4
Loading...
Searching...
No Matches
ultra::alps_layer_pair< Layer > Class Template Reference

#include <alps.h>

Public Member Functions

 alps_layer_pair (Layer &l) noexcept
 alps_layer_pair (Layer &p, Layer &s) noexcept
constexpr std::size_t size () const noexcept
constexpr bool has_secondary () const noexcept
constexpr auto begin () const noexcept
constexpr auto end () const noexcept
constexpr Layer & primary () const noexcept
constexpr Layer & secondary () const noexcept
Layer & random (double p_pri) const

Detailed Description

template<class Layer>
class ultra::alps_layer_pair< Layer >

Lightweight view over one or two ALPS layers.

Template Parameters
Layerlayer type. Can be const to model read-only access.

This class stores references to a primary layer and, optionally, a secondary layer. It's designed to avoid dynamic allocation in helper functions that, by policy, return either one or two eligible layers.

The object is iterable. When no secondary layer is present, size() is 1 and the iteration covers only the primary layer.

Warning
alps_layer_pair does not own the layers. The referenced layers must outlive the alps_layer_pair instance.
Note
When constructed with a single layer, the internal storage keeps two copies of the primary reference, but size()/iteration expose only one element.

Constructor & Destructor Documentation

◆ alps_layer_pair() [1/2]

template<class Layer>
ultra::alps_layer_pair< Layer >::alps_layer_pair ( Layer & l)
inlinenoexcept

Builds a pair with a single eligible layer (primary only).

Parameters
[in]lprimary layer

After construction size() == 1 and has_secondary() == false.

◆ alps_layer_pair() [2/2]

template<class Layer>
ultra::alps_layer_pair< Layer >::alps_layer_pair ( Layer & p,
Layer & s )
inlinenoexcept

Builds a pair with two eligible layers (primary and secondary).

Parameters
[in]pprimary layer
[in]ssecondary layer

After construction size() == 2 and has_secondary() == true.

Member Function Documentation

◆ begin()

template<class Layer>
auto ultra::alps_layer_pair< Layer >::begin ( ) const
inlinenodiscardconstexprnoexcept
Returns
iterator to the first exposed layer reference

◆ end()

template<class Layer>
auto ultra::alps_layer_pair< Layer >::end ( ) const
inlinenodiscardconstexprnoexcept
Returns
iterator one past the last exposed layer reference

◆ has_secondary()

template<class Layer>
bool ultra::alps_layer_pair< Layer >::has_secondary ( ) const
inlinenodiscardconstexprnoexcept
Returns
true if a secondary layer is present

◆ primary()

template<class Layer>
Layer & ultra::alps_layer_pair< Layer >::primary ( ) const
inlinenodiscardconstexprnoexcept
Returns
the primary layer

◆ random()

template<class Layer>
Layer & ultra::alps_layer_pair< Layer >::random ( double p_pri) const
inlinenodiscard

Picks a layer at random.

Parameters
[in]p_priprobability of selecting the primary layer
Returns
either primary() (with probability p_pri) or secondary() (with probability 1 - p_pri)
Precondition
0.0 < p_pri && p_pri <= 1.0.
Note
If no secondary layer is present, this function always returns primary(), regardless of p_pri.

◆ secondary()

template<class Layer>
Layer & ultra::alps_layer_pair< Layer >::secondary ( ) const
inlinenodiscardconstexprnoexcept
Returns
the secondary layer
Precondition
has_secondary() == true

◆ size()

template<class Layer>
std::size_t ultra::alps_layer_pair< Layer >::size ( ) const
inlinenodiscardconstexprnoexcept
Returns
number of exposed layers (1 or 2)

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