asio-grpc v1.6.0
Asynchronous gRPC with Asio/unified executors
agrpc::AllocatorBinder< Target, Allocator > Class Template Reference

Helper class that associates an allocator to an object. More...

#include <agrpc/bindAllocator.hpp>

Public Types

using target_type = Target
 The target type.
 
using executor_type = asio::associated_executor_t< Target >
 The target's associated executor type.
 
using allocator_type = Allocator
 The bound allocator type.
 

Public Member Functions

template<class... Args>
 AllocatorBinder (const Allocator &allocator, Args &&... args)
 Construct from an allocator and argument pack. More...
 
 AllocatorBinder (const AllocatorBinder &other)=default
 Default copy constructor.
 
template<class OtherTarget , class OtherAllocator >
 AllocatorBinder (const AllocatorBinder< OtherTarget, OtherAllocator > &other)
 Copy construct from a different agrpc::AllocatorBinder.
 
template<class OtherTarget , class OtherAllocator >
 AllocatorBinder (const Allocator &allocator, AllocatorBinder< OtherTarget, OtherAllocator > &other)
 Copy construct from a different agrpc::AllocatorBinder and specified allocator.
 
template<class OtherTarget , class OtherAllocator >
 AllocatorBinder (const Allocator &allocator, const AllocatorBinder< OtherTarget, OtherAllocator > &other)
 Copy construct from a different const agrpc::AllocatorBinder and specified allocator.
 
 AllocatorBinder (AllocatorBinder &&other)=default
 Default move constructor.
 
template<class OtherTarget , class OtherAllocator >
 AllocatorBinder (AllocatorBinder< OtherTarget, OtherAllocator > &&other)
 Move construct from a different agrpc::AllocatorBinder.
 
template<class OtherTarget , class OtherAllocator >
 AllocatorBinder (const Allocator &allocator, AllocatorBinder< OtherTarget, OtherAllocator > &&other)
 Move construct from a different agrpc::AllocatorBinder and specified allocator.
 
 ~AllocatorBinder ()=default
 Default destructor.
 
AllocatorBinderoperator= (const AllocatorBinder &other)=default
 Default copy assignment operator.
 
AllocatorBinderoperator= (AllocatorBinder &&other)=default
 Default move assignment operator.
 
target_typeget () noexcept
 Get the target (mutable)
 
const target_typeget () const noexcept
 Get the target (const)
 
executor_type get_executor () const noexcept
 Get the target's associated executor.
 
allocator_type get_allocator () const noexcept
 Get the bound allocator.
 
template<class... Args>
decltype(auto) operator() (Args &&... args) &&
 Invoke target with arguments (rvalue overload)
 
template<class... Args>
decltype(auto) operator() (Args &&... args) &
 Invoke target with arguments (lvalue overload)
 
template<class... Args>
decltype(auto) operator() (Args &&... args) const &
 Invoke target with arguments (const lvalue overload)
 

Detailed Description

template<class Target, class Allocator>
class agrpc::AllocatorBinder< Target, Allocator >

Helper class that associates an allocator to an object.

This class can be used to customize the allocator of an asynchronous operation. Especially useful when the completion token has an associated executor already or when asio::requireing a different allocator from the executor is not possible:

co_await agrpc::writes_done(*writer, agrpc::bind_allocator(my_allocator, asio::use_awaitable));
constexpr detail::WritesDoneFn writes_done
Signal WritesDone to a streaming RPC.
Definition: rpc.hpp:1520
auto bind_allocator(const Allocator &allocator, Target &&target)
Helper function to create an AllocatorBinder.
Definition: bindAllocator.hpp:208

In contrast to asio::bind_allocator this class performs empty class optimization on the provided allocator.

Since
1.5.0

Constructor & Destructor Documentation

◆ AllocatorBinder()

template<class Target , class Allocator >
template<class... Args>
agrpc::AllocatorBinder< Target, Allocator >::AllocatorBinder ( const Allocator &  allocator,
Args &&...  args 
)
inlineexplicit

Construct from an allocator and argument pack.

Supports deduction guide when constructing from a single argument. The following creates an AllocatorBinder<int std::allocator<std::byte>>

agrpc::AllocatorBinder int_binder{std::allocator<std::byte>{}, 1};
Helper class that associates an allocator to an object.
Definition: bindAllocator.hpp:44