Skip to content

Commit ef127e6

Browse files
Enforce value type requirements (#83)
* Enforce value type requirements * Set release version
1 parent 663cd1a commit ef127e6

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
cmake_minimum_required(VERSION 3.15)
2-
project(cpp_channel VERSION 1.3.0)
2+
project(cpp_channel VERSION 1.3.1)
33

44
set(CMAKE_CXX_STANDARD 11 CACHE STRING "C++ standard")
55
set(CMAKE_CXX_STANDARD_REQUIRED ON)

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Exceptions:
5151

5252
* Thread-safe push and fetch.
5353
* Use stream operators to push (<<) and fetch (>>) items.
54-
* Value type must be default constructible.
54+
* Value type must be default constructible, move constructible, move assignable, and destructible.
5555
* Blocking (forever waiting to fetch).
5656
* Range-based for loop supported.
5757
* Close to prevent pushing and stop waiting to fetch.

include/msd/channel.hpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,27 @@ class closed_channel : public std::runtime_error {
3939
template <typename T>
4040
using default_storage = queue_storage<T>;
4141

42+
/**
43+
* @brief Trait to check if a type is supported by msd::channel.
44+
*
45+
* This trait ensures the type meets all requirements to be safely used
46+
* within the channel:
47+
* - Default constructible: must be able to create a default instance.
48+
* - Move constructible: must be movable to allow efficient element transfer.
49+
* - Move assignable: must support move assignment for storage management.
50+
* - Destructible: must have a valid destructor.
51+
*
52+
* @tparam T The type to check.
53+
*/
54+
template <typename T>
55+
struct is_supported_type {
56+
/**
57+
* @brief Indicates if the type meets all channel requirements.
58+
*/
59+
static constexpr bool value = std::is_default_constructible<T>::value && std::is_move_constructible<T>::value &&
60+
std::is_move_assignable<T>::value && std::is_destructible<T>::value;
61+
};
62+
4263
/**
4364
* @brief Trait to check if a storage type has a static **capacity** member.
4465
*/
@@ -65,6 +86,8 @@ struct is_static_storage<Storage, decltype((void)Storage::capacity, void())> : s
6586
template <typename T, typename Storage = default_storage<T>>
6687
class channel {
6788
public:
89+
static_assert(is_supported_type<T>::value, "Type T does not meet all requirements.");
90+
6891
/**
6992
* @brief The type of elements stored in the channel.
7093
*/

0 commit comments

Comments
 (0)