37#include "kamping/assertion_levels.hpp"
40#include "kamping/kabool.hpp"
41#include "kamping/kassert/kassert.hpp"
43#include "kamping/span.hpp"
57#if KAMPING_ASSERT_ENABLED(KAMPING_ASSERTION_LEVEL_NORMAL)
66#if KAMPING_ASSERT_ENABLED(KAMPING_ASSERTION_LEVEL_NORMAL)
71#if KAMPING_ASSERT_ENABLED(KAMPING_ASSERTION_LEVEL_NORMAL)
84template <
bool =
false>
119template <
typename,
typename =
void>
133template <
class T,
template <
class...>
class Template>
149template <
template <
class...>
class Template,
class...
Args>
155template <
typename T,
typename =
void>
166 typename std::enable_if<!has_value_type_v<std::remove_cv_t<std::remove_reference_t<T>>>>::type> =
false;
176 std::is_same_v<typename std::remove_cv_t<std::remove_reference_t<T>>::value_type,
bool>;
187template <
typename Container>
194template <
typename Container>
214template <
template <
typename...>
typename Container>
218 template <
typename...
Ts>
223template <
template <
typename...>
typename Container>
231template <
template <
typename...>
typename Container>
262template <
typename,
typename =
void>
281template <BufferOwnership ownership>
334template <
typename MemberType>
371 typename ValueType = default_value_type_tag>
374 static_assert(!std::is_const_v<MemberType>,
"Member Type should not be const qualified.");
401 std::conditional_t<is_modifiable, MemberType, MemberType const>;
431 std::is_same_v<ValueType, default_value_type_tag> || std::is_same_v<ValueType, value_type>,
432 "The requested value type of the buffer does not match the value type of the underlying container"
435 std::conditional_t<is_modifiable, value_type, value_type const>;
439 "A constant data buffer requires the that the resize policy is no_resize."
443 "A single element data buffer requires the that the resize policy is no_resize."
448 "The underlying container does not provide a resize function, which is required by the resize policy."
453 template <
bool enabled = ownership == BufferOwnership::referencing, std::enable_if_t<enabled,
bool> = true>
458 template <
bool enabled = ownership == BufferOwnership::owning, std::enable_if_t<enabled,
bool> = true>
462 template <
bool enabled = allocation == BufferAllocation::lib_allocated, std::enable_if_t<enabled,
bool> = true>
464 static_assert(
ownership == BufferOwnership::owning,
"Lib allocated buffers must be owning");
465 static_assert(
is_modifiable,
"Lib allocated buffers must be modifiable");
487 typename std::enable_if_t<_resize_policy == resize_to_fit, bool> =
true>
502 typename std::enable_if_t<_resize_policy == grow_only, bool> =
true>
505 if (this->
size() < size) {
512 typename std::enable_if_t<_resize_policy == no_resize, bool> =
true>
521 template <
typename SizeFunc>
554 return {this->
data(), this->
size()};
561 return {this->
data(), this->
size()};
566 template <
bool enabled = is_single_element, std::enable_if_t<enabled,
bool> = true>
579 "Buffers based on std::vector<bool> are not supported, use std::vector<kamping::kabool> instead."
586 template <
bool enabled = modifiability == BufferModifiability::modifiable, std::enable_if_t<enabled,
bool> = true>
592 "Buffers based on std::vector<bool> are not supported, use std::vector<kamping::kabool> instead."
601 template <
bool enabled = is_owning, std::enable_if_t<enabled,
bool> = true>
605 "Moving out of a reference should not be done because it would leave "
606 "a users container in an unspecified state."
610 "Buffers based on std::vector<bool> are not supported, use std::vector<kamping::kabool> instead."
663 std::conditional_t<is_modifiable, MemberType, MemberType const>;
675 template <
bool enabled = ownership == BufferOwnership::referencing, std::enable_if_t<enabled,
bool> = true>
680 template <
bool enabled = ownership == BufferOwnership::owning, std::enable_if_t<enabled,
bool> = true>
692 template <
bool enabled = modifiability == BufferModifiability::modifiable, std::enable_if_t<enabled,
bool> = true>
702 template <
bool enabled = is_owning, std::enable_if_t<enabled,
bool> = true>
706 "Moving out of a reference should not be done because it would leave "
707 "a users container in an unspecified state."
722template <
typename Data, ParameterType type, BufferType buffer_type_param>
761 template <
typename SizeFunc>
770template <
typename T, ParameterType type, BufferType buffer_type_param>
801 std::is_rvalue_reference_v<Data&&> ? BufferOwnership::owning : BufferOwnership::referencing;
810 std::remove_const_t<std::remove_reference_t<Data>>,
817 BufferAllocation::user_allocated,
842 typename ValueType = default_value_type_tag,
849 BufferModifiability::modifiable,
850 BufferOwnership::owning,
853 BufferAllocation::lib_allocated,
878 typename ValueType = default_value_type_tag,
879 template <
typename...>
884 !std::is_same_v<ValueType, default_value_type_tag>,
885 "Value type for new library allocated container can not be deduced."
891 BufferModifiability::modifiable,
892 BufferOwnership::owning,
895 BufferAllocation::lib_allocated,
Helper functions that make casts safer.
STL-compatible allocator for requesting memory using the builtin MPI allocator.
Definition allocator.hpp:32
CopyMoveEnabler & operator=(CopyMoveEnabler const &)=delete
Copy assignment operator is deleted as buffers should only be moved.
CopyMoveEnabler(CopyMoveEnabler const &)=default
Copy constructor is enabled (this is okay for buffers which only reference their data)
CopyMoveEnabler & operator=(CopyMoveEnabler &&)=default
Move assignment operator.
CopyMoveEnabler(CopyMoveEnabler &&)=default
Move constructor.
Class optionally containing a copy constructor while supporting move assignment/construction.
Definition data_buffer.hpp:85
CopyMoveEnabler(CopyMoveEnabler &&)=default
Move constructor.
CopyMoveEnabler & operator=(CopyMoveEnabler const &)=delete
Copy assignment operator is deleted as buffers should only be moved.
CopyMoveEnabler(CopyMoveEnabler const &)=delete
Copy constructor is deleted as buffers should only be moved.
CopyMoveEnabler & operator=(CopyMoveEnabler &&)=default
Move assignment operator.
Data buffer used for named parameters.
Definition data_buffer.hpp:372
DataBuffer(MemberType container)
Constructor for owning ContainerBasedBuffer.
Definition data_buffer.hpp:459
value_type const * data() const
Get const access to the underlying container.
Definition data_buffer.hpp:530
static constexpr bool is_lib_allocated
Indicates whether the buffer is allocated by KaMPIng.
Definition data_buffer.hpp:390
std::conditional_t< is_owning, MemberType, MemberTypeWithConstAndRef > StorageType
Definition data_buffer.hpp:418
void resize_if_requested(SizeFunc &&compute_required_size)
Resizes the underlying container if the buffer the buffer's resize policy allows and resizing is nece...
Definition data_buffer.hpp:522
Span< value_type const > get() const
Get read-only access to the underlying storage.
Definition data_buffer.hpp:552
static constexpr TParameterType parameter_type
The type of parameter this buffer represents.
Definition data_buffer.hpp:376
value_type const get_single_element() const
Get the single element wrapped by this object.
Definition data_buffer.hpp:567
std::conditional_t< ownership==BufferOwnership::owning, MemberTypeWithConst, MemberTypeWithConst & > MemberTypeWithConstAndRef
Definition data_buffer.hpp:412
static constexpr bool is_single_element
Definition data_buffer.hpp:397
static constexpr bool is_owning
Indicates whether the buffer owns its underlying storage.
Definition data_buffer.hpp:392
Span< value_type_with_const > get()
Get access to the underlying storage.
Definition data_buffer.hpp:559
static constexpr BufferType buffer_type
The type of the buffer, i.e., in, out, or in_out.
Definition data_buffer.hpp:379
static constexpr BufferResizePolicy resize_policy
The policy specifying in which cases the buffer shall be resized.
Definition data_buffer.hpp:381
size_t size() const
The size of the underlying container.
Definition data_buffer.hpp:469
StorageType extract()
Extract the underlying container. This will leave the DataBuffer in an unspecified state.
Definition data_buffer.hpp:602
value_type_with_const * data()
Get access to the underlying container.
Definition data_buffer.hpp:541
MemberType const & underlying() const
Provides access to the underlying data.
Definition data_buffer.hpp:574
static constexpr bool is_modifiable
Indicates whether the underlying storage is modifiable.
Definition data_buffer.hpp:395
DataBuffer(MemberTypeWithConst &container)
Constructor for referencing ContainerBasedBuffer.
Definition data_buffer.hpp:454
void resize(size_t size)
Resizes the underlying container such that it holds exactly size elements of value_type.
Definition data_buffer.hpp:488
std::conditional_t< is_modifiable, MemberType, MemberType const > MemberTypeWithConst
Definition data_buffer.hpp:400
typename ValueTypeWrapper<!is_single_element, MemberType >::value_type value_type
Value type of the buffer.
Definition data_buffer.hpp:428
std::conditional_t< is_modifiable, value_type, value_type const > value_type_with_const
Definition data_buffer.hpp:434
static constexpr bool is_out_buffer
true if the buffer is an out or in/out buffer that results will be written to and false otherwise.
Definition data_buffer.hpp:386
DataBuffer()
Constructor for lib allocated ContainerBasedBuffer.
Definition data_buffer.hpp:463
MemberType & underlying()
Provides access to the underlying data.
Definition data_buffer.hpp:587
Empty buffer that can be used as default argument for optional buffer parameters.
Definition data_buffer.hpp:723
static constexpr BufferType buffer_type
The type of the buffer, usually ignore for this special buffer.
Definition data_buffer.hpp:729
size_t size() const
Get the number of elements in the underlying storage.
Definition data_buffer.hpp:740
static constexpr bool is_single_element
An empty buffer contains no elements.
Definition data_buffer.hpp:735
static constexpr bool is_modifiable
This pseudo buffer is not modifiable since it represents no actual buffer.
Definition data_buffer.hpp:726
Span< value_type > get() const
Returns a span containing a nullptr.
Definition data_buffer.hpp:752
static constexpr bool is_out_buffer
An empty buffer is never output.
Definition data_buffer.hpp:733
value_type const * data() const
Get a nullptr.
Definition data_buffer.hpp:746
static constexpr ParameterType parameter_type
The type of parameter this buffer represents.
Definition data_buffer.hpp:725
static constexpr bool is_lib_allocated
An empty buffer is not allocated.
Definition data_buffer.hpp:734
static constexpr bool is_owning
An empty buffer does not own anything.
Definition data_buffer.hpp:736
void resize_if_requested(SizeFunc &&compute_required_size)
Resizes the underlying container if the buffer the buffer's resize policy allows and resizing is nece...
Definition data_buffer.hpp:762
static constexpr BufferResizePolicy resize_policy
An empty buffer can not be resized.
Definition data_buffer.hpp:732
A more generic version of a DataBuffer which stores an object of type.
Definition data_buffer.hpp:642
MemberType const & underlying() const
Provides access to the underlying data.
Definition data_buffer.hpp:685
static constexpr BufferType buffer_type
The type of the buffer, i.e., in, out, or in_out.
Definition data_buffer.hpp:647
std::conditional_t< is_modifiable, MemberType, MemberType const > MemberTypeWithConst
Definition data_buffer.hpp:662
std::conditional_t< ownership==BufferOwnership::owning, MemberTypeWithConst, MemberTypeWithConst & > MemberTypeWithConstAndRef
Definition data_buffer.hpp:667
static constexpr bool is_out_buffer
true if the buffer is an out or in/out buffer that results will be written to and false otherwise.
Definition data_buffer.hpp:651
GenericDataBuffer(MemberType container)
Constructor for owning GenericDataBuffer.
Definition data_buffer.hpp:681
GenericDataBuffer(MemberTypeWithConst &container)
Constructor for referencing GenericDataBuffer.
Definition data_buffer.hpp:676
MemberTypeWithConst extract()
Extract the underlying container. This will leave the DataBuffer in an unspecified state.
Definition data_buffer.hpp:703
static constexpr TParameterType parameter_type
The type of parameter this buffer represents.
Definition data_buffer.hpp:644
static constexpr bool is_owning
Indicates whether the buffer owns its underlying storage.
Definition data_buffer.hpp:654
MemberType & underlying()
Provides access to the underlying data.
Definition data_buffer.hpp:693
static constexpr bool is_modifiable
Indicates whether the underlying storage is modifiable.
Definition data_buffer.hpp:657
typename T::value_type value_type
The value type of T.
Definition data_buffer.hpp:328
Wrapper to get the value type of a non-container type (aka the type itself).
Definition data_buffer.hpp:315
T value_type
The value type of T.
Definition data_buffer.hpp:317
constexpr int normal
Default assertion level. This level is used if no assertion level is specified.
Definition assertion_levels.hpp:19
constexpr BufferResizePolicy grow_only
Definition data_buffer.hpp:303
constexpr BufferResizePolicy resize_to_fit
Definition data_buffer.hpp:306
static constexpr bool is_alloc_new_using_v
Helper to decide if an allocation tag is an AllocNewUsingT.
Definition data_buffer.hpp:228
static constexpr auto alloc_container_of
Convenience wrapper for creating library allocated containers. See AllocContainerOfT for details.
Definition data_buffer.hpp:249
BufferResizePolicy
Enum to specify in which cases a buffer is resized.
Definition data_buffer.hpp:292
static constexpr bool is_alloc_new_v
Helper to decide if an allocation tag is an AllocNewT.
Definition data_buffer.hpp:199
static constexpr bool is_alloc_container_of_v
Helper to decide if an allocation tag is an AllocContainerOfT.
Definition data_buffer.hpp:253
static constexpr auto alloc_new_using
Convenience wrapper for creating library allocated containers. See AllocNewUsingT for details.
Definition data_buffer.hpp:224
constexpr BufferResizePolicy no_resize
Definition data_buffer.hpp:300
static constexpr auto alloc_new
Convenience wrapper for creating library allocated containers. See AllocNewT for details.
Definition data_buffer.hpp:195
@ no_resize
Policy indicating that the underlying buffer shall never be resized.
ParameterType
Each input parameter to one of the MPI calls wrapped by KaMPIng needs to has one of the following tag...
Definition named_parameter_types.hpp:33
Macros for generating concept-like type traits to check for member functions of objects.
#define KAMPING_MAKE_HAS_MEMBER(Member)
Macro for generating has_member_xxx and has_member_xxx_v templates. They return true if the type give...
Definition has_member.hpp:91
File containing the parameter types used by the KaMPIng library.
constexpr bool has_data_member_v
Boolean value helping to decide if data type has .data() method.
Definition data_buffer.hpp:273
constexpr BufferResizePolicy maximum_viable_resize_policy
for a given
Definition data_buffer.hpp:335
static constexpr bool is_vector_bool_v
Boolean value helping to check if a type is an instance of std::vector<bool>.
Definition data_buffer.hpp:156
static constexpr bool has_value_type_v
Boolean value helping to decide if type has a value_type member type.
Definition data_buffer.hpp:120
BufferAllocation
Enum to specify whether a buffer is allocated by the library or the user.
Definition data_buffer.hpp:285
constexpr bool is_empty_data_buffer_v
Helper to decide if a type is an instance of EmptyDataBuffer.
Definition data_buffer.hpp:767
BufferOwnership
Enum to specify whether a buffer owns its data.
Definition data_buffer.hpp:278
constexpr bool enable_copy_construction_v
Check whether copy construction is allowed for the given ownership.
Definition data_buffer.hpp:282
BufferModifiability
Enum to specify whether a buffer is modifiable.
Definition data_buffer.hpp:276
auto make_data_buffer(Data &&data)
Creates a user allocated DataBuffer containing the supplied data (a container or a single element)
Definition data_buffer.hpp:799
BufferType
Enum to specify whether a buffer is an in buffer of an out buffer. Out buffer will be used to directl...
Definition data_buffer.hpp:288
constexpr internal::ignore_t< T > ignore
Tag for parameters that can be omitted on some PEs (e.g., root PE, or non-root PEs).
Definition parameter_objects.hpp:571
Buffer allocation tag used for indicating that a buffer of type T should be allocated by KaMPIng.
Definition data_buffer.hpp:242
T value_type
The value type to use for the allocated buffer.
Definition data_buffer.hpp:244
Buffer allocation tag used for indicating that a buffer should be allocated by KaMPIng.
Definition data_buffer.hpp:188
Buffer allocation tag used for indicating that a buffer should be allocated by KaMPIng.
Definition data_buffer.hpp:215
tag type to indicate that the value_type should be inferred from the container
Definition data_buffer.hpp:321
Helper to decide if data type has .data() method.
Definition data_buffer.hpp:263
Type trait to check if a type is an instance of a templated type.
Definition data_buffer.hpp:134