Skip to content

Move Buffer::overloaded dispatch helper to top level #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions cpp/include/rapidsmpf/buffer/buffer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,18 @@ enum class MemoryType : int {
/// @brief Array of all the different memory types.
constexpr std::array<MemoryType, 2> MEMORY_TYPES{{MemoryType::DEVICE, MemoryType::HOST}};

namespace {
/// @brief Helper for overloaded lambdas using std::visit.
template <class... Ts>
struct overloaded : Ts... {
using Ts::operator()...;
};
/// @brief Explicit deduction guide
template <class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;

} // namespace

/**
* @brief Buffer representing device or host memory.
*
Expand All @@ -48,15 +60,6 @@ class Buffer {
*/
using StorageT = std::variant<DeviceStorageT, HostStorageT>;

/// @brief Helper for overloaded lambdas for Storage types in StorageT
template <class... Ts>
struct overloaded : Ts... {
using Ts::operator()...;
};
/// @brief Explicit deduction guide
template <class... Ts>
overloaded(Ts...) -> overloaded<Ts...>;

/**
* @brief Access the underlying host memory buffer (const).
*
Expand Down Expand Up @@ -112,7 +115,7 @@ class Buffer {
*
* @throws std::logic_error if the buffer is not initialized.
*/
MemoryType constexpr mem_type() const {
[[nodiscard]] MemoryType constexpr mem_type() const {
return std::visit(
overloaded{
[](const HostStorageT&) -> MemoryType { return MemoryType::HOST; },
Expand Down