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) 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. */