KaMPIng 0.2.1
(Near) zero-overhead MPI wrapper for C++
Loading...
Searching...
No Matches
kabool.hpp
Go to the documentation of this file.
1// This file is part of KaMPIng.
2//
3// Copyright 2021-2024, 2026 The KaMPIng Authors
4//
5// KaMPIng is free software : you can redistribute it and/or modify it under the terms of the GNU Lesser General Public
6// License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later
7// version. KaMPIng is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the
8// implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
9// for more details.
10//
11// You should have received a copy of the GNU Lesser General Public License along with KaMPIng. If not, see
12// <https://www.gnu.org/licenses/>.
13
14/// @file
15/// @brief Boolean wrapper type for use with MPI containers.
16
17#pragma once
18
19namespace kamping::types {
20
21/// @addtogroup kamping_types
22/// @{
23
24/// @brief Wrapper around bool to allow handling containers of boolean values.
25///
26/// `std::vector<bool>` uses bit-packing which is incompatible with MPI's buffer model.
27/// Use `std::vector<kabool>` instead: `kabool` maps to `MPI_CXX_BOOL` and stores one
28/// `bool` per byte.
29class kabool {
30public:
31 /// @brief default constructor for a \c kabool with value \c false
32 constexpr kabool() noexcept : _value() {}
33 /// @brief constructor to construct a \c kabool out of a \c bool
34 constexpr kabool(bool value) noexcept : _value(value) {}
35
36 /// @brief implicit cast of \c kabool to \c bool
37 inline constexpr operator bool() const noexcept {
38 return _value;
39 }
40
41private:
42 bool _value; ///< The wrapped boolean value.
43};
44
45/// @}
46
47} // namespace kamping::types
STL-compatible allocator for requesting memory using the builtin MPI allocator.
Definition allocator.hpp:32
Wrapper around bool to allow handling containers of boolean values.
Definition kabool.hpp:29
constexpr kabool() noexcept
default constructor for a kabool with value false
Definition kabool.hpp:32
constexpr kabool(bool value) noexcept
constructor to construct a kabool out of a bool
Definition kabool.hpp:34