@@ -259,10 +259,6 @@ CheckSignedAndIntegerTraitsForComplexTypes(const char * const name)
259
259
std::cout << " \t ERROR: NumericTraits< " << name << " >::IsInteger definition is true." << std::endl;
260
260
std::cout << " \t Complex types are not integers" << std::endl;
261
261
}
262
- else
263
- {
264
- didTestPass = true ;
265
- }
266
262
267
263
// IsSigned same for complex and basic types??
268
264
if (itk::NumericTraits<T>::IsSigned != itk::NumericTraits<typename itk::NumericTraits<T>::ValueType>::IsSigned)
@@ -283,7 +279,6 @@ CheckSignedAndIntegerTraitsForComplexTypes(const char * const name)
283
279
std::cout << " \t SUCCESS: IsSigned definition for complex type matches value of basic type" << std::endl;
284
280
std::cout << " \t Signed Value for:\t < " << name << " >\t is:\t "
285
281
<< (itk::NumericTraits<T>::IsSigned ? " true" : " false" ) << std::endl;
286
- didTestPass = true ;
287
282
}
288
283
std::cout << std::endl;
289
284
return didTestPass;
@@ -338,7 +333,7 @@ CheckAllSignedAndIntegerTraits()
338
333
339
334
if (didAllTestsPass)
340
335
{
341
- std::cout << " SUCESS !!: All IsSigned and IsInteger tests Passed!!!" << std::endl;
336
+ std::cout << " SUCCESS !!: All IsSigned and IsInteger tests Passed!!!" << std::endl;
342
337
}
343
338
else
344
339
{
@@ -350,38 +345,27 @@ CheckAllSignedAndIntegerTraits()
350
345
}
351
346
352
347
// Check a few types and make sure that they have the correct value for IsComplex
353
- bool
348
+ void
354
349
CheckIsComplexTraits ()
355
350
{
356
- bool didTestsPass = true ;
357
- std::cout << " Testing non complex types for IsComplex trait" << std::endl;
358
- if (itk::NumericTraits<float >::IsComplex || itk::NumericTraits<double >::IsComplex ||
359
- itk::NumericTraits<char >::IsComplex || itk::NumericTraits<int >::IsComplex ||
360
- itk::NumericTraits<unsigned long >::IsComplex)
361
- {
362
- std::cout << " Test FAILED!!\n " << std::endl;
363
- std::cout << " Not all non complex types have the correct IsComplex trait" << std::endl;
364
- didTestsPass = false ;
365
- }
366
- else
367
- {
368
- std::cout << " Test Passed\n " << std::endl;
369
- }
370
-
371
- std::cout << " Testing complex types for IsComplex trait" << std::endl;
372
- if (!itk::NumericTraits<std::complex <float >>::IsComplex || !itk::NumericTraits<std::complex <double >>::IsComplex ||
373
- !itk::NumericTraits<std::complex <char >>::IsComplex || !itk::NumericTraits<std::complex <int >>::IsComplex ||
374
- !itk::NumericTraits<std::complex <unsigned long >>::IsComplex)
375
- {
376
- std::cout << " Test FAILED!!\n " << std::endl;
377
- std::cout << " Not all complex types have the correct IsComplex trait" << std::endl;
378
- didTestsPass = false ;
379
- }
380
- else
381
- {
382
- std::cout << " Test Passed\n " << std::endl;
383
- }
384
- return didTestsPass;
351
+ // Use static asserts to do compile-time testing of traits
352
+ // std::cout << "Testing non complex types for IsComplex trait" << std::endl;
353
+ static_assert (!itk::NumericTraits<float >::IsComplex, " float is not complex" );
354
+ static_assert (!itk::NumericTraits<double >::IsComplex, " double is not complex" );
355
+ static_assert (!itk::NumericTraits<char >::IsComplex, " char is not complex" );
356
+ static_assert (!itk::NumericTraits<int >::IsComplex, " int is not complex" );
357
+ static_assert (!itk::NumericTraits<unsigned long >::IsComplex, " unsigned long is not complex" );
358
+
359
+ static_assert (itk::NumericTraits<std::complex <float >>::IsComplex,
360
+ " std::complex<float> does not have the correct IsComplex trait" );
361
+ static_assert (itk::NumericTraits<std::complex <double >>::IsComplex,
362
+ " std::complex<double> does not have the correct IsComplex trait" );
363
+ static_assert (itk::NumericTraits<std::complex <char >>::IsComplex,
364
+ " std::complex<char> does not have the correct IsComplex trait" );
365
+ static_assert (itk::NumericTraits<std::complex <int >>::IsComplex,
366
+ " std::complex<int> does not have the correct IsComplex trait" );
367
+ static_assert (itk::NumericTraits<std::complex <unsigned long >>::IsComplex,
368
+ " std::complex<unsigned long> does not have the correct IsComplex trait" );
385
369
} // End CheckIsComplexTraits()
386
370
387
371
} // end anonymous namespace
@@ -391,13 +375,13 @@ itkNumericTraitsTest(int, char *[])
391
375
{
392
376
bool testPassedStatus = true ;
393
377
394
- CheckTraits (" char" , static_cast <char >(0 ));
395
- CheckTraits (" signed char" , static_cast <signed char >(0 ));
396
- CheckTraits (" unsigned char" , static_cast <unsigned char >(0 ));
378
+ CheckTraits (" char" , static_cast <char >(' a ' ));
379
+ CheckTraits (" signed char" , static_cast <signed char >(' a ' ));
380
+ CheckTraits (" unsigned char" , static_cast <unsigned char >(' a ' ));
397
381
398
- CheckTraits (" short" , static_cast <short >(0 ));
399
- CheckTraits (" signed short" , static_cast <signed short >(0 ));
400
- CheckTraits (" unsigned short" , static_cast <unsigned short >(0 ));
382
+ CheckTraits (" short" , static_cast <short >(- 1 ));
383
+ CheckTraits (" signed short" , static_cast <signed short >(- 1 ));
384
+ CheckTraits (" unsigned short" , static_cast <unsigned short >(1 ));
401
385
402
386
CheckTraits (" int" , static_cast <int >(0 ));
403
387
CheckTraits (" signed int" , static_cast <signed int >(0 ));
@@ -1272,8 +1256,8 @@ itkNumericTraitsTest(int, char *[])
1272
1256
// check the new Integer and Signed traits
1273
1257
testPassedStatus &= CheckAllSignedAndIntegerTraits ();
1274
1258
1275
- // Check IsComplex traits
1276
- testPassedStatus &= CheckIsComplexTraits ();
1259
+ // CompileTime Checks IsComplex traits does not return
1260
+ CheckIsComplexTraits ();
1277
1261
1278
1262
return (testPassedStatus) ? EXIT_SUCCESS : EXIT_FAILURE;
1279
1263
}
0 commit comments