Open 3D Engine AzCore API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
AZ::EBusReduceResult< T &, Aggregator > Struct Template Reference

#include <Results.h>

Public Member Functions

 EBusReduceResult (T &rhs, const Aggregator &aggregator=Aggregator())
 
void operator= (T &&rhs)
 
void operator= (const T &rhs)
 
EBusReduceResultoperator= (const EBusReduceResult &)=delete
 

Public Attributes

T & value
 
Aggregator unary
 

Detailed Description

template<class T, class Aggregator>
struct AZ::EBusReduceResult< T &, Aggregator >

Aggregates results returned by all handlers of an EBus event. Also puts the aggregated value into the input value that is passed by reference. You can use this structure to add results, apply a logical AND to results, and so on.

Template Parameters
TThe output type of the aggregator.
AggregatorA function object that aggregates results. The return type must match T. For examples of function objects that you can use as aggregators, see functional_basic.h.

The following example replaces the value returned by a handler with the sum of the value and previous handler return values.

int myExistingInt = 5;
MyBus::BroadcastResult(result, &MyBus::Events::GetANumber);
AZ_Printf("%d", result.value); // or AZ_Printf("%d", myExistingInt);
Definition: Results.h:51

The following example determines whether all handlers, including the latest handler, return true. Also replaces the latest handler result with the aggregated result.

bool myExistingBool = true;
MyBus::BroadcastResult(result, &MyBus::Events::IsDoneDoingThing);
// myExistingBool is now only true if all handlers returned true.
AZ_Printf("%d", myExistingBool);

Constructor & Destructor Documentation

◆ EBusReduceResult()

template<class T , class Aggregator >
AZ::EBusReduceResult< T &, Aggregator >::EBusReduceResult ( T &  rhs,
const Aggregator &  aggregator = Aggregator() 
)
inlineexplicit

Creates an instance of the class, sets the reference to the initial value, and sets the function object to use as the aggregator.

Parameters
rhsA reference to the initial value, which new values will be aggregated with.
aggregatorA function object to aggregate the values. For examples of function objects that you can use as aggregators, see functional_basic.h.

Member Function Documentation

◆ operator=() [1/3]

template<class T , class Aggregator >
EBusReduceResult & AZ::EBusReduceResult< T &, Aggregator >::operator= ( const EBusReduceResult< T &, Aggregator > &  )
delete

Disallows copying an EBusReduceResult object by reference.

◆ operator=() [2/3]

template<class T , class Aggregator >
void AZ::EBusReduceResult< T &, Aggregator >::operator= ( const T &  rhs)
inline

Overloads the assignment operator to aggregate a new value with the existing aggregated value. Used only when the return type is const, or const&

◆ operator=() [3/3]

template<class T , class Aggregator >
void AZ::EBusReduceResult< T &, Aggregator >::operator= ( T &&  rhs)
inline

Overloads the assignment operator to aggregate a new value with the existing aggregated value using rvalue-ref

Member Data Documentation

◆ unary

template<class T , class Aggregator >
Aggregator AZ::EBusReduceResult< T &, Aggregator >::unary

The function object that aggregates a new value with an existing value.

◆ value

template<class T , class Aggregator >
T& AZ::EBusReduceResult< T &, Aggregator >::value

A reference to the current value, which new values will be aggregated with.


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