From 548bc91e6a3aa8690216073f9a24a0736edfd21e Mon Sep 17 00:00:00 2001 From: Andrei Avram <6795248+andreiavrammsd@users.noreply.github.com> Date: Tue, 17 Jun 2025 17:33:24 +0000 Subject: [PATCH 1/2] Enforce value type requirements --- README.md | 2 +- include/msd/channel.hpp | 23 +++++++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 48b96ee..bb6937e 100644 --- a/README.md +++ b/README.md @@ -51,7 +51,7 @@ Exceptions: * Thread-safe push and fetch. * Use stream operators to push (<<) and fetch (>>) items. -* Value type must be default constructible. +* Value type must be default constructible, move constructible, move assignable, and destructible. * Blocking (forever waiting to fetch). * Range-based for loop supported. * Close to prevent pushing and stop waiting to fetch. diff --git a/include/msd/channel.hpp b/include/msd/channel.hpp index 36f89a3..ae49078 100644 --- a/include/msd/channel.hpp +++ b/include/msd/channel.hpp @@ -39,6 +39,27 @@ class closed_channel : public std::runtime_error { template using default_storage = queue_storage; +/** + * @brief Trait to check if a type is supported by msd::channel. + * + * This trait ensures the type meets all requirements to be safely used + * within the channel: + * - Default constructible: must be able to create a default instance. + * - Move constructible: must be movable to allow efficient element transfer. + * - Move assignable: must support move assignment for storage management. + * - Destructible: must have a valid destructor. + * + * @tparam T The type to check. + */ +template +struct is_supported_type { + /** + * @brief Indicates if the type meets all channel requirements. + */ + static constexpr bool value = std::is_default_constructible::value && std::is_move_constructible::value && + std::is_move_assignable::value && std::is_destructible::value; +}; + /** * @brief Trait to check if a storage type has a static **capacity** member. */ @@ -65,6 +86,8 @@ struct is_static_storage : s template > class channel { public: + static_assert(is_supported_type::value, "Type T does not meet all requirements."); + /** * @brief The type of elements stored in the channel. */ From cd70ba98d896d35c598438e58008cbe913ecd130 Mon Sep 17 00:00:00 2001 From: Andrei Avram <6795248+andreiavrammsd@users.noreply.github.com> Date: Tue, 17 Jun 2025 17:47:53 +0000 Subject: [PATCH 2/2] Set version --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 60788b9..4420af8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.15) -project(cpp_channel VERSION 1.3.0) +project(cpp_channel VERSION 1.3.1) set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard") set(CMAKE_CXX_STANDARD_REQUIRED ON)