Skip to content

Commit d284be0

Browse files
omartijnsangelovic
authored andcommitted
Convert some static_asserts to concept constraints
1 parent b4b4ef3 commit d284be0

2 files changed

Lines changed: 11 additions & 13 deletions

File tree

include/sdbus-c++/VTableItems.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <sdbus-c++/Types.h>
3131
#include <sdbus-c++/TypeTraits.h>
3232

33+
#include <concepts>
3334
#include <string>
3435
#include <variant>
3536
#include <vector>
@@ -40,9 +41,9 @@ namespace sdbus {
4041
{
4142
template <typename Function> MethodVTableItem&& implementedAs(Function&& callback) &&;
4243
MethodVTableItem&& withInputParamNames(std::vector<std::string> names) &&;
43-
template <typename... String> MethodVTableItem&& withInputParamNames(String... names) &&;
44+
template <std::convertible_to<std::string>... String> MethodVTableItem&& withInputParamNames(String... names) &&;
4445
MethodVTableItem&& withOutputParamNames(std::vector<std::string> names) &&;
45-
template <typename... String> MethodVTableItem&& withOutputParamNames(String... names) &&;
46+
template <std::convertible_to<std::string>... String> MethodVTableItem&& withOutputParamNames(String... names) &&;
4647
MethodVTableItem&& markAsDeprecated() &&;
4748
MethodVTableItem&& markAsPrivileged() &&;
4849
MethodVTableItem&& withNoReply() &&;
@@ -63,7 +64,9 @@ namespace sdbus {
6364
{
6465
template <typename... Args> SignalVTableItem&& withParameters() &&;
6566
template <typename... Args> SignalVTableItem&& withParameters(std::vector<std::string> names) &&;
66-
template <typename... Args, typename... String> SignalVTableItem&& withParameters(String... names) &&;
67+
template <typename... Args, std::convertible_to<std::string>... String>
68+
requires(sizeof...(Args) == sizeof...(String))
69+
SignalVTableItem&& withParameters(String... names) &&;
6770
SignalVTableItem&& markAsDeprecated() &&;
6871

6972
SignalName name;

include/sdbus-c++/VTableItems.inl

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <sdbus-c++/Error.h>
3030
#include <sdbus-c++/TypeTraits.h>
3131

32+
#include <concepts>
3233
#include <string>
3334
#include <type_traits>
3435
#include <vector>
@@ -81,11 +82,9 @@ namespace sdbus {
8182
return std::move(*this);
8283
}
8384

84-
template <typename... String>
85+
template <std::convertible_to<std::string>... String>
8586
inline MethodVTableItem&& MethodVTableItem::withInputParamNames(String... names) &&
8687
{
87-
static_assert(std::conjunction_v<std::is_convertible<String, std::string>...>, "Parameter names must be (convertible to) strings");
88-
8988
return std::move(*this).withInputParamNames({names...});
9089
}
9190

@@ -96,11 +95,9 @@ namespace sdbus {
9695
return std::move(*this);
9796
}
9897

99-
template <typename... String>
98+
template <std::convertible_to<std::string>... String>
10099
inline MethodVTableItem&& MethodVTableItem::withOutputParamNames(String... names) &&
101100
{
102-
static_assert(std::conjunction_v<std::is_convertible<String, std::string>...>, "Parameter names must be (convertible to) strings");
103-
104101
return std::move(*this).withOutputParamNames({names...});
105102
}
106103

@@ -155,12 +152,10 @@ namespace sdbus {
155152
return std::move(*this).template withParameters<Args...>();
156153
}
157154

158-
template <typename... Args, typename... String>
155+
template <typename... Args, std::convertible_to<std::string>... String>
156+
requires(sizeof...(Args) == sizeof...(String))
159157
inline SignalVTableItem&& SignalVTableItem::withParameters(String... names) &&
160158
{
161-
static_assert(std::conjunction_v<std::is_convertible<String, std::string>...>, "Parameter names must be (convertible to) strings");
162-
static_assert(sizeof...(Args) == sizeof...(String), "Numbers of signal parameters and their names don't match");
163-
164159
return std::move(*this).template withParameters<Args...>({names...});
165160
}
166161

0 commit comments

Comments
 (0)