JH-Toolkit v1.4.1
An engineering-oriented C++20 toolkit with duck-typed concepts, static design, async coroutines, and semantic containers — header-only, RTTI-free, and concurrency-friendly.
Loading...
Searching...
No Matches
jh::concepts::range_storage_traits< R, UseRefWrapper > Struct Template Reference

Trait defining how a range (or equivalent) is held inside a view or wrapper. More...

#include <jh/conceptual/range_traits.h>

Public Types

using stored_t
 Type used internally to hold the source, based on reference category and policy.

Static Public Member Functions

static constexpr auto wrap (R &&v) noexcept(std::is_nothrow_constructible_v< stored_t, R && >)
 Wraps a range/view/sequence according to the defined storage policy.
static constexpr decltype(auto) get (stored_t &v) noexcept
 Retrieves a reference to the underlying source.
static constexpr decltype(auto) get (const stored_t &v) noexcept
 Retrieves a reference to the underlying source.

Static Public Attributes

static constexpr bool is_lvalue = std::is_lvalue_reference_v<R>
 Indicates whether the source is an lvalue reference.

Detailed Description

template<typename R, bool UseRefWrapper = false>
struct jh::concepts::range_storage_traits< R, UseRefWrapper >

Trait defining how a range (or equivalent) is held inside a view or wrapper.

range_storage_traits<R> defines the storage model for wrapper-based view types that internally hold another range, view, or sequence — for example: jh::ranges::range_adaptor and jh::ranges::vis_transform_view.

Policy Overview

  • Rvalues / temporaries — stored by value.
  • Lvalues — stored as references, optionally wrapped in std::reference_wrapper for safety.
  • UseRefWrapper = true — enforces safe reference semantics, ensuring non-dangling access in deferred pipelines.
  • UseRefWrapper = false — uses direct references for lightweight, local usage.

This trait allows range-holding views to remain agnostic to the lifetime and category of their sources, achieving consistent forwarding semantics across the entire jh::ranges ecosystem.

Template Parameters
RSource range type to be stored.
UseRefWrapperWhether lvalues should be stored as std::reference_wrapper.

Member Typedef Documentation

◆ stored_t

template<typename R, bool UseRefWrapper = false>
using jh::concepts::range_storage_traits< R, UseRefWrapper >::stored_t
Initial value:
std::conditional_t<
std::conditional_t<UseRefWrapper,
std::reference_wrapper<std::remove_reference_t<R>>,
R>,
std::remove_cvref_t<R>
>
static constexpr bool is_lvalue
Indicates whether the source is an lvalue reference.
Definition range_traits.h:156

Type used internally to hold the source, based on reference category and policy.

Member Function Documentation

◆ get() [1/2]

template<typename R, bool UseRefWrapper = false>
constexpr decltype(auto) jh::concepts::range_storage_traits< R, UseRefWrapper >::get ( const stored_t & v)
inlinestaticconstexprnoexcept

Retrieves a reference to the underlying source.

Parameters
vStored instance.
Returns
Constant / Mutable reference to the source.

◆ get() [2/2]

template<typename R, bool UseRefWrapper = false>
constexpr decltype(auto) jh::concepts::range_storage_traits< R, UseRefWrapper >::get ( stored_t & v)
inlinestaticconstexprnoexcept

Retrieves a reference to the underlying source.

Parameters
vStored instance.
Returns
Constant / Mutable reference to the source.

◆ wrap()

template<typename R, bool UseRefWrapper = false>
constexpr auto jh::concepts::range_storage_traits< R, UseRefWrapper >::wrap ( R && v)
inlinestaticconstexprnoexcept

Wraps a range/view/sequence according to the defined storage policy.

Parameters
vThe source range to wrap.
Returns
Stored representation (value or reference) suitable for internal retention.

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