Skip to content

Add named value accessors to constant_ and variable_ #52

Description

@ipapadop

Motivation

All deferred objects currently use function-call syntax for evaluation:

auto value = object();

That is natural for composed deferred expressions, but less conventional for value wrappers such as constant_ and variable_. Standard C++ wrapper types usually expose named accessors such as value() or get().

Proposed API

Add named accessors while retaining operator() for uniform deferred evaluation:

constant.get();       // const T&
std::move(constant).get(); // T

variable.get();       // T&
std::as_const(variable).get(); // const T&
std::move(variable).get(); // T

value() is another possible name. get() aligns with std::reference_wrapper; value() aligns with std::optional and communicates value access more explicitly.

Design considerations

  • Mirror the existing cv/ref-qualified return types exactly.
  • Preserve noexcept and constexpr.
  • Avoid duplicating implementation: either the named accessor or operator() should delegate to the other.
  • Retain operator() so generic deferred evaluation and existing code remain unchanged.
  • Decide whether mutating access through non-const variable_::get() is intentional and document it.
  • Consider whether named access belongs only on constant_/variable_ or on every deferred expression. Restricting it to wrappers keeps the semantic distinction clear.

Compatibility

This can be a purely additive API change.

Acceptance criteria

  • constant_ exposes a named accessor for const lvalues and rvalues.
  • variable_ exposes named accessors for mutable lvalues, const lvalues, and rvalues.
  • Return types match the corresponding existing operator() overloads.
  • Accessors are constexpr and noexcept where the current operators are.
  • Existing operator() behavior remains supported.
  • Unit tests verify return types, mutation through variable_, and move access.
  • Documentation explains named access versus deferred evaluation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions