37#include "kamping/assertion_levels.hpp"
40#include "kamping/kabool.hpp"
42#include "kamping/span.hpp"
43#include "kassert/kassert.hpp"
57#if KASSERT_ENABLED(KAMPING_ASSERTION_LEVEL_NORMAL)
66#if KASSERT_ENABLED(KAMPING_ASSERTION_LEVEL_NORMAL)
71#if KASSERT_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;
175 std::is_same_v<typename std::remove_cv_t<std::remove_reference_t<T>>::value_type,
bool>;
186template <
typename Container>
193template <
typename Container>
213template <
template <
typename...>
typename Container>
217 template <
typename...
Ts>
222template <
template <
typename...>
typename Container>
230template <
template <
typename...>
typename Container>
261template <
typename,
typename =
void>
280template <BufferOwnership ownership>
333template <
typename MemberType>
370 typename ValueType = default_value_type_tag>
373 static_assert(!std::is_const_v<MemberType>,
"Member Type should not be const qualified.");
400 std::conditional_t<is_modifiable, MemberType, MemberType const>;
430 std::is_same_v<ValueType, default_value_type_tag> || std::is_same_v<ValueType, value_type>,
431 "The requested value type of the buffer does not match the value type of the underlying container"
434 std::conditional_t<is_modifiable, value_type, value_type const>;
438 "A constant data buffer requires the that the resize policy is no_resize."
442 "A single element data buffer requires the that the resize policy is no_resize."
447 "The underlying container does not provide a resize function, which is required by the resize policy."
452 template <
bool enabled = ownership == BufferOwnership::referencing, std::enable_if_t<enabled,
bool> = true>
457 template <
bool enabled = ownership == BufferOwnership::owning, std::enable_if_t<enabled,
bool> = true>
461 template <
bool enabled = allocation == BufferAllocation::lib_allocated, std::enable_if_t<enabled,
bool> = true>
463 static_assert(
ownership == BufferOwnership::owning,
"Lib allocated buffers must be owning");
464 static_assert(
is_modifiable,
"Lib allocated buffers must be modifiable");
486 typename std::enable_if_t<_resize_policy == resize_to_fit, bool> =
true>
501 typename std::enable_if_t<_resize_policy == grow_only, bool> =
true>
504 if (this->
size() < size) {
511 typename std::enable_if_t<_resize_policy == no_resize, bool> =
true>
520 template <
typename SizeFunc>
553 return {this->
data(), this->
size()};
560 return {this->
data(), this->
size()};
565 template <
bool enabled = is_single_element, std::enable_if_t<enabled,
bool> = true>
578 "Buffers based on std::vector<bool> are not supported, use std::vector<kamping::kabool> instead."
585 template <
bool enabled = modifiability == BufferModifiability::modifiable, std::enable_if_t<enabled,
bool> = true>
591 "Buffers based on std::vector<bool> are not supported, use std::vector<kamping::kabool> instead."
600 template <
bool enabled = is_owning, std::enable_if_t<enabled,
bool> = true>
604 "Moving out of a reference should not be done because it would leave "
605 "a users container in an unspecified state."
609 "Buffers based on std::vector<bool> are not supported, use std::vector<kamping::kabool> instead."
662 std::conditional_t<is_modifiable, MemberType, MemberType const>;
674 template <
bool enabled = ownership == BufferOwnership::referencing, std::enable_if_t<enabled,
bool> = true>
679 template <
bool enabled = ownership == BufferOwnership::owning, std::enable_if_t<enabled,
bool> = true>
691 template <
bool enabled = modifiability == BufferModifiability::modifiable, std::enable_if_t<enabled,
bool> = true>
701 template <
bool enabled = is_owning, std::enable_if_t<enabled,
bool> = true>
705 "Moving out of a reference should not be done because it would leave "
706 "a users container in an unspecified state."
721template <
typename Data, ParameterType type, BufferType buffer_type_param>
760 template <
typename SizeFunc>
769template <
typename T, ParameterType type, BufferType buffer_type_param>
800 std::is_rvalue_reference_v<Data&&> ? BufferOwnership::owning : BufferOwnership::referencing;
809 std::remove_const_t<std::remove_reference_t<Data>>,
816 BufferAllocation::user_allocated,
841 typename ValueType = default_value_type_tag,
848 BufferModifiability::modifiable,
849 BufferOwnership::owning,
852 BufferAllocation::lib_allocated,
877 typename ValueType = default_value_type_tag,
878 template <
typename...>
883 !std::is_same_v<ValueType, default_value_type_tag>,
884 "Value type for new library allocated container can not be deduced."
890 BufferModifiability::modifiable,
891 BufferOwnership::owning,
894 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:371
DataBuffer(MemberType container)
Constructor for owning ContainerBasedBuffer.
Definition data_buffer.hpp:458
value_type const * data() const
Get const access to the underlying container.
Definition data_buffer.hpp:529
static constexpr bool is_lib_allocated
Indicates whether the buffer is allocated by KaMPIng.
Definition data_buffer.hpp:389
std::conditional_t< is_owning, MemberType, MemberTypeWithConstAndRef > StorageType
Definition data_buffer.hpp:417
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:521
Span< value_type const > get() const
Get read-only access to the underlying storage.
Definition data_buffer.hpp:551
static constexpr TParameterType parameter_type
The type of parameter this buffer represents.
Definition data_buffer.hpp:375
value_type const get_single_element() const
Get the single element wrapped by this object.
Definition data_buffer.hpp:566
std::conditional_t< ownership==BufferOwnership::owning, MemberTypeWithConst, MemberTypeWithConst & > MemberTypeWithConstAndRef
Definition data_buffer.hpp:411
static constexpr bool is_single_element
Definition data_buffer.hpp:396
static constexpr bool is_owning
Indicates whether the buffer owns its underlying storage.
Definition data_buffer.hpp:391
Span< value_type_with_const > get()
Get access to the underlying storage.
Definition data_buffer.hpp:558
static constexpr BufferType buffer_type
The type of the buffer, i.e., in, out, or in_out.
Definition data_buffer.hpp:378
static constexpr BufferResizePolicy resize_policy
The policy specifying in which cases the buffer shall be resized.
Definition data_buffer.hpp:380
size_t size() const
The size of the underlying container.
Definition data_buffer.hpp:468
StorageType extract()
Extract the underlying container. This will leave the DataBuffer in an unspecified state.
Definition data_buffer.hpp:601
value_type_with_const * data()
Get access to the underlying container.
Definition data_buffer.hpp:540
MemberType const & underlying() const
Provides access to the underlying data.
Definition data_buffer.hpp:573
static constexpr bool is_modifiable
Indicates whether the underlying storage is modifiable.
Definition data_buffer.hpp:394
DataBuffer(MemberTypeWithConst &container)
Constructor for referencing ContainerBasedBuffer.
Definition data_buffer.hpp:453
void resize(size_t size)
Resizes the underlying container such that it holds exactly size elements of value_type.
Definition data_buffer.hpp:487
std::conditional_t< is_modifiable, MemberType, MemberType const > MemberTypeWithConst
Definition data_buffer.hpp:399
typename ValueTypeWrapper<!is_single_element, MemberType >::value_type value_type
Value type of the buffer.
Definition data_buffer.hpp:427
std::conditional_t< is_modifiable, value_type, value_type const > value_type_with_const
Definition data_buffer.hpp:433
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:385
DataBuffer()
Constructor for lib allocated ContainerBasedBuffer.
Definition data_buffer.hpp:462
MemberType & underlying()
Provides access to the underlying data.
Definition data_buffer.hpp:586
Empty buffer that can be used as default argument for optional buffer parameters.
Definition data_buffer.hpp:722
static constexpr BufferType buffer_type
The type of the buffer, usually ignore for this special buffer.
Definition data_buffer.hpp:728
size_t size() const
Get the number of elements in the underlying storage.
Definition data_buffer.hpp:739
static constexpr bool is_single_element
An empty buffer contains no elements.
Definition data_buffer.hpp:734
static constexpr bool is_modifiable
This pseudo buffer is not modifiable since it represents no actual buffer.
Definition data_buffer.hpp:725
Span< value_type > get() const
Returns a span containing a nullptr.
Definition data_buffer.hpp:751
static constexpr bool is_out_buffer
An empty buffer is never output.
Definition data_buffer.hpp:732
value_type const * data() const
Get a nullptr.
Definition data_buffer.hpp:745
static constexpr ParameterType parameter_type
The type of parameter this buffer represents.
Definition data_buffer.hpp:724
static constexpr bool is_lib_allocated
An empty buffer is not allocated.
Definition data_buffer.hpp:733
static constexpr bool is_owning
An empty buffer does not own anything.
Definition data_buffer.hpp:735
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:761
static constexpr BufferResizePolicy resize_policy
An empty buffer can not be resized.
Definition data_buffer.hpp:731
A more generic version of a DataBuffer which stores an object of type.
Definition data_buffer.hpp:641
MemberType const & underlying() const
Provides access to the underlying data.
Definition data_buffer.hpp:684
static constexpr BufferType buffer_type
The type of the buffer, i.e., in, out, or in_out.
Definition data_buffer.hpp:646
std::conditional_t< is_modifiable, MemberType, MemberType const > MemberTypeWithConst
Definition data_buffer.hpp:661
std::conditional_t< ownership==BufferOwnership::owning, MemberTypeWithConst, MemberTypeWithConst & > MemberTypeWithConstAndRef
Definition data_buffer.hpp:666
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:650
GenericDataBuffer(MemberType container)
Constructor for owning GenericDataBuffer.
Definition data_buffer.hpp:680
GenericDataBuffer(MemberTypeWithConst &container)
Constructor for referencing GenericDataBuffer.
Definition data_buffer.hpp:675
MemberTypeWithConst extract()
Extract the underlying container. This will leave the DataBuffer in an unspecified state.
Definition data_buffer.hpp:702
static constexpr TParameterType parameter_type
The type of parameter this buffer represents.
Definition data_buffer.hpp:643
static constexpr bool is_owning
Indicates whether the buffer owns its underlying storage.
Definition data_buffer.hpp:653
MemberType & underlying()
Provides access to the underlying data.
Definition data_buffer.hpp:692
static constexpr bool is_modifiable
Indicates whether the underlying storage is modifiable.
Definition data_buffer.hpp:656
typename T::value_type value_type
The value type of T.
Definition data_buffer.hpp:327
Wrapper to get the value type of a non-container type (aka the type itself).
Definition data_buffer.hpp:314
T value_type
The value type of T.
Definition data_buffer.hpp:316
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:302
constexpr BufferResizePolicy resize_to_fit
Definition data_buffer.hpp:305
static constexpr bool is_alloc_new_using_v
Helper to decide if an allocation tag is an AllocNewUsingT.
Definition data_buffer.hpp:227
static constexpr auto alloc_container_of
Convenience wrapper for creating library allocated containers. See AllocContainerOfT for details.
Definition data_buffer.hpp:248
BufferResizePolicy
Enum to specify in which cases a buffer is resized.
Definition data_buffer.hpp:291
static constexpr bool is_alloc_new_v
Helper to decide if an allocation tag is an AllocNewT.
Definition data_buffer.hpp:198
static constexpr bool is_alloc_container_of_v
Helper to decide if an allocation tag is an AllocContainerOfT.
Definition data_buffer.hpp:252
static constexpr auto alloc_new_using
Convenience wrapper for creating library allocated containers. See AllocNewUsingT for details.
Definition data_buffer.hpp:223
constexpr BufferResizePolicy no_resize
Definition data_buffer.hpp:299
static constexpr auto alloc_new
Convenience wrapper for creating library allocated containers. See AllocNewT for details.
Definition data_buffer.hpp:194
@ 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:272
constexpr BufferResizePolicy maximum_viable_resize_policy
for a given
Definition data_buffer.hpp:334
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:284
constexpr bool is_empty_data_buffer_v
Helper to decide if a type is an instance of EmptyDataBuffer.
Definition data_buffer.hpp:766
BufferOwnership
Enum to specify whether a buffer owns its data.
Definition data_buffer.hpp:277
constexpr bool enable_copy_construction_v
Check whether copy construction is allowed for the given ownership.
Definition data_buffer.hpp:281
BufferModifiability
Enum to specify whether a buffer is modifiable.
Definition data_buffer.hpp:275
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:798
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:287
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:570
Buffer allocation tag used for indicating that a buffer of type T should be allocated by KaMPIng.
Definition data_buffer.hpp:241
T value_type
The value type to use for the allocated buffer.
Definition data_buffer.hpp:243
Buffer allocation tag used for indicating that a buffer should be allocated by KaMPIng.
Definition data_buffer.hpp:187
Buffer allocation tag used for indicating that a buffer should be allocated by KaMPIng.
Definition data_buffer.hpp:214
tag type to indicate that the value_type should be inferred from the container
Definition data_buffer.hpp:320
Helper to decide if data type has .data() method.
Definition data_buffer.hpp:262
Type trait to check if a type is an instance of a templated type.
Definition data_buffer.hpp:134