My Project
Public Types | Public Member Functions | List of all members
bsl::reference_wrapper< T > Class Template Reference

reference_wrapper prototype More...

#include <is_reference_wrapper.hpp>

Public Types

using type = T
 alias for: T
 

Public Member Functions

constexpr reference_wrapper (T &val) noexcept
 Used to initialize a reference_wrapper by getting an address to the provided "val" and storing the address for use later. More...
 
constexpr T & get () const noexcept
 Returns a reference to the thing that is wrapped. This is done by taking the stored address and returning a reference instead of an address. More...
 
template<typename... ARGS>
constexpr invoke_result_t< T &, ARGS... > operator() (ARGS &&... a) const
 Invokes the reference_wrapper as if it were a function. More...
 

Detailed Description

template<typename T>
class bsl::reference_wrapper< T >

reference_wrapper prototype

bsl::reference_wrapper is a class template that wraps a reference. Unlike the std::reference_wrapper, the implicit conversion operator is not supported as that would not be compliant with AUTOSAR. We also do not add the assignment operator as that would result in needing to define the rule of 5 which is not needed (there is no harm in allowing moves as they result in the same thing as a copy).

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_reference_wrapper_overview() noexcept
{
constexpr bsl::int32 expected{42};
bsl::int32 data{};
bsl::reference_wrapper const rw{data};
rw.get() = expected;
if (expected == data) {
bsl::print() << "success\n";
}
}
}
Template Parameters
Tthe type of reference to wrap

Constructor & Destructor Documentation

◆ reference_wrapper()

template<typename T >
constexpr bsl::reference_wrapper< T >::reference_wrapper ( T &  val)
inlineexplicitnoexcept

Used to initialize a reference_wrapper by getting an address to the provided "val" and storing the address for use later.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_reference_wrapper_constructor() noexcept
{
constexpr bsl::int32 expected{42};
bsl::int32 data{};
bsl::reference_wrapper const rw{data};
rw.get() = expected;
if (expected == data) {
bsl::print() << "success\n";
}
}
}
Parameters
valthe thing to get the address of and store.

Member Function Documentation

◆ get()

template<typename T >
constexpr T& bsl::reference_wrapper< T >::get ( ) const
inlinenoexcept

Returns a reference to the thing that is wrapped. This is done by taking the stored address and returning a reference instead of an address.

#include <bsl/debug.hpp>
namespace bsl
{
inline void
example_reference_wrapper_get() noexcept
{
bsl::int32 const data{42};
bsl::reference_wrapper const rw{data};
if (rw.get() == data) {
bsl::print() << "success\n";
}
}
}
Returns
Returns a reference to the wrapped thing

◆ operator()()

template<typename T >
template<typename... ARGS>
constexpr invoke_result_t<T &, ARGS...> bsl::reference_wrapper< T >::operator() ( ARGS &&...  a) const
inline

Invokes the reference_wrapper as if it were a function.

#include <bsl/debug.hpp>
#include "../example_function.hpp"
namespace bsl
{
inline void
example_reference_wrapper_functor() noexcept
{
bsl::reference_wrapper const rw{example_function};
if (rw(true)) {
bsl::print() << "success\n";
}
}
}
Template Parameters
ARGSthe types of arguments to pass to the wrapped function.
Parameters
athe arguments to pass to the wrapped function.
Returns
Returns the result of the wrapped function given the provided arguments.
Exceptions
throwsif the wrapped function throws

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