Skip to content

Commit 3012020

Browse files
committed
Improved static_assert error messages.
1 parent 12d72a5 commit 3012020

2 files changed

Lines changed: 54 additions & 20 deletions

File tree

‎include/react/Domain.h‎

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ auto MakeContinuation(TransactionFlagsT flags, const Signal<D,S>& trigger, FIn&&
195195
-> Continuation<D,DOut>
196196
{
197197
static_assert(DOut::is_concurrent,
198-
"MakeContinuation requires support for concurrent input to target domain.");
198+
"MakeContinuation: Target domain does not support concurrent input.");
199199

200200
using REACT_IMPL::SignalContinuationNode;
201201
using F = typename std::decay<FIn>::type;
@@ -232,7 +232,7 @@ auto MakeContinuation(TransactionFlagsT flags, const Events<D,E>& trigger, FIn&&
232232
-> Continuation<D,DOut>
233233
{
234234
static_assert(DOut::is_concurrent,
235-
"MakeContinuation requires support for concurrent input to target domain.");
235+
"MakeContinuation: Target domain does not support concurrent input.");
236236

237237
using REACT_IMPL::EventContinuationNode;
238238
using REACT_IMPL::AddContinuationRangeWrapper;
@@ -245,9 +245,16 @@ auto MakeContinuation(TransactionFlagsT flags, const Events<D,E>& trigger, FIn&&
245245
typename std::conditional<
246246
IsCallableWith<F,void, EventRange<E>>::value,
247247
F,
248-
AddContinuationRangeWrapper<E, F>
248+
typename std::conditional<
249+
IsCallableWith<F, void, E>::value,
250+
AddContinuationRangeWrapper<E, F>,
251+
void
252+
>::type
249253
>::type;
250254

255+
static_assert(! std::is_same<WrapperT,void>::value,
256+
"MakeContinuation: Passed function does not match any of the supported signatures.");
257+
251258
return Continuation<D,DOut>(
252259
std::make_shared<EventContinuationNode<D,DOut,E,WrapperT>>(
253260
flags, GetNodePtr(trigger), std::forward<FIn>(func)));
@@ -282,7 +289,7 @@ auto MakeContinuation(TransactionFlagsT flags, const Events<D,E>& trigger,
282289
-> Continuation<D,DOut>
283290
{
284291
static_assert(DOut::is_concurrent,
285-
"MakeContinuation requires support for concurrent input to target domain.");
292+
"MakeContinuation: Target domain does not support concurrent input.");
286293

287294
using REACT_IMPL::SyncedContinuationNode;
288295
using REACT_IMPL::AddContinuationRangeWrapper;
@@ -295,9 +302,16 @@ auto MakeContinuation(TransactionFlagsT flags, const Events<D,E>& trigger,
295302
typename std::conditional<
296303
IsCallableWith<F, void, EventRange<E>, TDepValues ...>::value,
297304
F,
298-
AddContinuationRangeWrapper<E, F, TDepValues ...>
305+
typename std::conditional<
306+
IsCallableWith<F, void, E, TDepValues ...>::value,
307+
AddContinuationRangeWrapper<E, F, TDepValues ...>,
308+
void
309+
>::type
299310
>::type;
300311

312+
static_assert(! std::is_same<WrapperT,void>::value,
313+
"MakeContinuation: Passed function does not match any of the supported signatures.");
314+
301315
struct NodeBuilder_
302316
{
303317
NodeBuilder_(TransactionFlagsT flags, const Events<D,E>& trigger, FIn&& func) :
@@ -364,7 +378,8 @@ void DoTransaction(TransactionFlagsT flags, F&& func)
364378
template <typename D, typename F>
365379
void AsyncTransaction(F&& func)
366380
{
367-
static_assert(D::is_concurrent, "AsyncTransaction requires concurrent domain.");
381+
static_assert(D::is_concurrent,
382+
"AsyncTransaction: Domain does not support concurrent input.");
368383

369384
using REACT_IMPL::DomainSpecificInputManager;
370385
DomainSpecificInputManager<D>::Instance()
@@ -374,7 +389,8 @@ void AsyncTransaction(F&& func)
374389
template <typename D, typename F>
375390
void AsyncTransaction(TransactionFlagsT flags, F&& func)
376391
{
377-
static_assert(D::is_concurrent, "AsyncTransaction requires concurrent domain.");
392+
static_assert(D::is_concurrent,
393+
"AsyncTransaction: Domain does not support concurrent input.");
378394

379395
using REACT_IMPL::DomainSpecificInputManager;
380396
DomainSpecificInputManager<D>::Instance()
@@ -384,7 +400,8 @@ void AsyncTransaction(TransactionFlagsT flags, F&& func)
384400
template <typename D, typename F>
385401
void AsyncTransaction(TransactionStatus& status, F&& func)
386402
{
387-
static_assert(D::is_concurrent, "AsyncTransaction requires concurrent domain.");
403+
static_assert(D::is_concurrent,
404+
"AsyncTransaction: Domain does not support concurrent input.");
388405

389406
using REACT_IMPL::DomainSpecificInputManager;
390407

@@ -395,7 +412,8 @@ void AsyncTransaction(TransactionStatus& status, F&& func)
395412
template <typename D, typename F>
396413
void AsyncTransaction(TransactionFlagsT flags, TransactionStatus& status, F&& func)
397414
{
398-
static_assert(D::is_concurrent, "AsyncTransaction requires concurrent domain.");
415+
static_assert(D::is_concurrent,
416+
"AsyncTransaction: Domain does not support concurrent input.");
399417

400418
using REACT_IMPL::DomainSpecificInputManager;
401419
DomainSpecificInputManager<D>::Instance()

‎include/react/Observer.h‎

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -179,15 +179,15 @@ auto Observe(const Signal<D,S>& subject, FIn&& func)
179179

180180
// If return value of passed function is void, add ObserverAction::next as
181181
// default return value.
182-
using TNode = typename std::conditional<
182+
using NodeT = typename std::conditional<
183183
std::is_same<void,R>::value,
184184
SignalObserverNode<D,S,WrapperT>,
185185
SignalObserverNode<D,S,F>
186186
>::type;
187187

188188
const auto& subjectPtr = GetNodePtr(subject);
189189

190-
std::unique_ptr<ObserverNode<D>> nodePtr( new TNode(subjectPtr, std::forward<FIn>(func)) );
190+
std::unique_ptr<ObserverNode<D>> nodePtr( new NodeT(subjectPtr, std::forward<FIn>(func)) );
191191
ObserverNode<D>* rawNodePtr = nodePtr.get();
192192

193193
subjectPtr->RegisterObserver(std::move(nodePtr));
@@ -227,17 +227,25 @@ auto Observe(const Events<D,E>& subject, FIn&& func)
227227
typename std::conditional<
228228
IsCallableWith<F, void, EventRange<E>>::value,
229229
AddDefaultReturnValueWrapper<F,ObserverAction,ObserverAction::next>,
230-
AddObserverRangeWrapper<E,
231-
AddDefaultReturnValueWrapper<F,ObserverAction,ObserverAction::next>>
230+
typename std::conditional<
231+
IsCallableWith<F, void, E>::value,
232+
AddObserverRangeWrapper<E,
233+
AddDefaultReturnValueWrapper<F,ObserverAction,ObserverAction::next>>,
234+
void
235+
>::type
232236
>::type
233237
>::type
234238
>::type;
239+
240+
static_assert(
241+
! std::is_same<WrapperT,void>::value,
242+
"Observe: Passed function does not match any of the supported signatures.");
235243

236-
using TNode = EventObserverNode<D,E,WrapperT>;
244+
using NodeT = EventObserverNode<D,E,WrapperT>;
237245

238246
const auto& subjectPtr = GetNodePtr(subject);
239247

240-
std::unique_ptr<ObserverNode<D>> nodePtr( new TNode(subjectPtr, std::forward<FIn>(func)) );
248+
std::unique_ptr<ObserverNode<D>> nodePtr( new NodeT(subjectPtr, std::forward<FIn>(func)) );
241249
ObserverNode<D>* rawNodePtr = nodePtr.get();
242250

243251
subjectPtr->RegisterObserver(std::move(nodePtr));
@@ -279,14 +287,22 @@ auto Observe(const Events<D,E>& subject,
279287
typename std::conditional<
280288
IsCallableWith<F, void, EventRange<E>, TDepValues ...>::value,
281289
AddDefaultReturnValueWrapper<F, ObserverAction ,ObserverAction::next>,
282-
AddObserverRangeWrapper<E,
283-
AddDefaultReturnValueWrapper<F,ObserverAction,ObserverAction::next>,
284-
TDepValues...>
290+
typename std::conditional<
291+
IsCallableWith<F, void, E, TDepValues ...>::value,
292+
AddObserverRangeWrapper<E,
293+
AddDefaultReturnValueWrapper<F,ObserverAction,ObserverAction::next>,
294+
TDepValues...>,
295+
void
296+
>::type
285297
>::type
286298
>::type
287299
>::type;
288300

289-
using TNode = SyncedObserverNode<D,E,WrapperT,TDepValues ...>;
301+
static_assert(
302+
! std::is_same<WrapperT,void>::value,
303+
"Observe: Passed function does not match any of the supported signatures.");
304+
305+
using NodeT = SyncedObserverNode<D,E,WrapperT,TDepValues ...>;
290306

291307
struct NodeBuilder_
292308
{
@@ -298,7 +314,7 @@ auto Observe(const Events<D,E>& subject,
298314
auto operator()(const Signal<D,TDepValues>& ... deps)
299315
-> ObserverNode<D>*
300316
{
301-
return new TNode(
317+
return new NodeT(
302318
GetNodePtr(MySubject), std::forward<FIn>(MyFunc), GetNodePtr(deps) ... );
303319
}
304320

0 commit comments

Comments
 (0)