Skip to content

Commit f47e517

Browse files
committed
disambiguate set(0)
see lf-lang/lingua-franca#2280
1 parent 1539b11 commit f47e517

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

include/reactor-cpp/port.hh

+6-2
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,12 @@ public:
133133
void set(MutableValuePtr<T>&& value_ptr) { set(ImmutableValuePtr<T>(std::forward<MutableValuePtr<T>>(value_ptr))); }
134134
void set(const T& value) { set(make_immutable_value<T>(value)); }
135135
void set(T&& value) { set(make_immutable_value<T>(std::forward<T>(value))); }
136-
// Setting a port to nullptr is not permitted.
137-
void set(std::nullptr_t) = delete;
136+
137+
// Setting a port to nullptr is not permitted. We use enable_if to only delete
138+
// set() if it is actually called with nullptr. Without enable_if set(0) would
139+
// be ambiguous as 0 can be implicitly casted to nullptr_t.
140+
template <typename V, typename = std::enable_if_t<std::is_same_v<V, std::nullptr_t>>> void set(V) = delete;
141+
138142
void startup() final {}
139143
void shutdown() final {}
140144

0 commit comments

Comments
 (0)