Sequoia
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
sequoia::assignment_helper Struct Reference

Helper class to assist with copy assignment for allocator-aware types. More...

#include <AssignmentUtilities.hpp>

Static Public Member Functions

template<class T , std::invocable< T >... AllocGetters>
static constexpr void assign (T &to, const T &from, AllocGetters... allocGetters)
 

Detailed Description

Helper class to assist with copy assignment for allocator-aware types.

Consider a type, T, which is allocator-aware and for which copy assignment cannot be defaulted. Suppose that T wraps containers Cs.... To utilize the this helper, do the following:

  1. Ensure assignment_helper is befriended by T.
  2. Furnish T with a reset method, the arguments of which are the allocators associated with Cs.... Internally, reset should construct instances Cs... using the allocators and copy assign these to the wrapped containers. It is important that copy assignment is used since allocator propagation may differ between copying and moving.
  3. Utilize assignment_helper to define copy assignment. A single allocator example is provided by sequoia::data_structures::bucketed_sequence and a two allocator example is provided by sequoia::data_structures::partitioned_sequence_base. The basic idea is that assignment_helper::assign takes references to two instances of T, together with a sequence of function objects which return the requisite allocators.

This pattern has an extra layer of generality, an example of which may be seen in sequoia::maths::connectivity. Depending on how its template arguments are chosen, sequoia::maths::connectivity may wrap either one or two allocator-aware types. To deal with these situations homogeneously, assignment_helper::assign ignores any of the supplied function objects if they return void.

Member Function Documentation

◆ assign()

template<class T , std::invocable< T >... AllocGetters>
static constexpr void sequoia::assignment_helper::assign ( T &  to,
const T &  from,
AllocGetters...  allocGetters 
)
inlinestaticconstexpr

Can be used to implement non-defaultable copy assignment for allocator-aware classes


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