Namespaces
Variants

std::execution::prop

From cppreference.com
 
 
Execution control library
Concepts
 
Defined in header <execution>
template< class QueryTag, class ValueType >
struct prop;
(since C++26)

The class template prop builds a queryable object from a query object and a value. Its query member returns the stored value when called with a query tag of type QueryTag; any additional arguments are ignored.

The program is ill-formed unless std::callable<QueryTag, prop_like<ValueType>> is modeled, where prop_like is the following exposition-only class template:

template<class ValueType>
struct prop_like
{
    const ValueType& query(auto) const noexcept;
};

Specializations of prop are not assignable.

Template parameters

QueryTag - the type of the query object
ValueType - the type of the stored value

Member functions

query
returns the stored value for the matching query tag
(public member function)
constexpr const ValueType& query( QueryTag, auto&&... ) const noexcept;
(since C++26)

Returns a reference to the stored value.

Deduction guides

template< class QueryTag, class ValueType >
prop( QueryTag, ValueType ) -> prop<QueryTag, std::unwrap_reference_t<ValueType>>;
(since C++26)

This deduction guide unwraps std::reference_wrapper so that the property can hold a reference.

Example


The execution control library components may not be available in the online compilers yet, so this link runs the example on Compiler Explorer with stdexec (one of the reference implementations).

#include <iostream>
#include <print>
namespace ex = std::execution;

struct get_priority_t
{
    template<class Env>
    constexpr int operator()(const Env& e) const noexcept
    { return e.query(*this); }
};
inline constexpr get_priority_t get_priority{};

int main()
{
    auto p = ex::prop(get_priority, 42);
    std::println("priority: {}", get_priority(p));
}

Output:

priority: 42

See also

returns the associated queryable object for its given argument
(customization point object)[edit]
creates a sender that queries its receiver's associated environment
(customization point object)[edit]
adapts a sender so that the operations inside it see extra or different values in their execution environment
(customization point object)[edit]