Skip to content

Commit

Permalink
ENH: replace itkStaticAssert by STL's static_assert
Browse files Browse the repository at this point in the history
This is a follow-up to d3e151f.
  • Loading branch information
dzenanz committed Sep 10, 2021
1 parent 342845e commit cd43985
Showing 1 changed file with 44 additions and 49 deletions.
93 changes: 44 additions & 49 deletions Modules/Core/Common/test/itkMetaProgrammingLibraryTest.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -19,77 +19,72 @@
#include <type_traits>

#include "itkMetaProgrammingLibrary.h"
#include "itkStaticAssert.h"


int
itkMetaProgrammingLibraryTest(int, char *[])
{
using namespace itk::mpl;

#if !defined(ITK_LEGACY_REMOVE)

// Or between constants
itkStaticAssert((OrC<true, true, true>::Value == true), "Unit test failed");
itkStaticAssert((OrC<true, false, true>::Value == true), "Unit test failed");
itkStaticAssert((OrC<true, true, false>::Value == true), "Unit test failed");
itkStaticAssert((OrC<false, false, true>::Value == true), "Unit test failed");
itkStaticAssert((OrC<true, false, false>::Value == true), "Unit test failed");
itkStaticAssert((OrC<false, true, false>::Value == true), "Unit test failed");
itkStaticAssert((OrC<false, false, false>::Value == false), "Unit test failed");

itkStaticAssert((OrC<true, true>::Value == true), "Unit test failed");
itkStaticAssert((OrC<true, false>::Value == true), "Unit test failed");
itkStaticAssert((OrC<false, true>::Value == true), "Unit test failed");
itkStaticAssert((OrC<false, false>::Value == false), "Unit test failed");
static_assert((OrC<true, true, true>::Value == true), "Unit test failed");
static_assert((OrC<true, false, true>::Value == true), "Unit test failed");
static_assert((OrC<true, true, false>::Value == true), "Unit test failed");
static_assert((OrC<false, false, true>::Value == true), "Unit test failed");
static_assert((OrC<true, false, false>::Value == true), "Unit test failed");
static_assert((OrC<false, true, false>::Value == true), "Unit test failed");
static_assert((OrC<false, false, false>::Value == false), "Unit test failed");

static_assert((OrC<true, true>::Value == true), "Unit test failed");
static_assert((OrC<true, false>::Value == true), "Unit test failed");
static_assert((OrC<false, true>::Value == true), "Unit test failed");
static_assert((OrC<false, false>::Value == false), "Unit test failed");

// Or between types
itkStaticAssert((std::is_same<Or<TrueType, TrueType, TrueType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<TrueType, FalseType, TrueType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<TrueType, TrueType, FalseType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<FalseType, FalseType, TrueType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<TrueType, FalseType, FalseType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<FalseType, TrueType, FalseType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<FalseType, FalseType, FalseType>::Type, FalseType>::value), "Unit test failed");

itkStaticAssert((std::is_same<Or<TrueType, TrueType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<TrueType, FalseType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<FalseType, TrueType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Or<FalseType, FalseType>::Type, FalseType>::value), "Unit test failed");
static_assert((std::is_same<Or<TrueType, TrueType, TrueType>::Type, TrueType>::value), "Unit test failed");
static_assert((std::is_same<Or<TrueType, FalseType, TrueType>::Type, TrueType>::value), "Unit test failed");
static_assert((std::is_same<Or<TrueType, TrueType, FalseType>::Type, TrueType>::value), "Unit test failed");
static_assert((std::is_same<Or<FalseType, FalseType, TrueType>::Type, TrueType>::value), "Unit test failed");
static_assert((std::is_same<Or<TrueType, FalseType, FalseType>::Type, TrueType>::value), "Unit test failed");
static_assert((std::is_same<Or<FalseType, TrueType, FalseType>::Type, TrueType>::value), "Unit test failed");
static_assert((std::is_same<Or<FalseType, FalseType, FalseType>::Type, FalseType>::value), "Unit test failed");

static_assert((std::is_same<Or<TrueType, TrueType>::Type, TrueType>::value), "Unit test failed");
static_assert((std::is_same<Or<TrueType, FalseType>::Type, TrueType>::value), "Unit test failed");
static_assert((std::is_same<Or<FalseType, TrueType>::Type, TrueType>::value), "Unit test failed");
static_assert((std::is_same<Or<FalseType, FalseType>::Type, FalseType>::value), "Unit test failed");

// And between constants
itkStaticAssert((AndC<true, true>::Value == true), "Unit test failed");
itkStaticAssert((AndC<true, false>::Value == false), "Unit test failed");
itkStaticAssert((AndC<false, true>::Value == false), "Unit test failed");
itkStaticAssert((AndC<false, false>::Value == false), "Unit test failed");
static_assert((AndC<true, true>::Value == true), "Unit test failed");
static_assert((AndC<true, false>::Value == false), "Unit test failed");
static_assert((AndC<false, true>::Value == false), "Unit test failed");
static_assert((AndC<false, false>::Value == false), "Unit test failed");

// And between types
itkStaticAssert((std::is_same<And<TrueType, TrueType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<And<TrueType, FalseType>::Type, FalseType>::value), "Unit test failed");
itkStaticAssert((std::is_same<And<FalseType, TrueType>::Type, FalseType>::value), "Unit test failed");
itkStaticAssert((std::is_same<And<FalseType, FalseType>::Type, FalseType>::value), "Unit test failed");
static_assert((std::is_same<And<TrueType, TrueType>::Type, TrueType>::value), "Unit test failed");
static_assert((std::is_same<And<TrueType, FalseType>::Type, FalseType>::value), "Unit test failed");
static_assert((std::is_same<And<FalseType, TrueType>::Type, FalseType>::value), "Unit test failed");
static_assert((std::is_same<And<FalseType, FalseType>::Type, FalseType>::value), "Unit test failed");

// Xor between constants
itkStaticAssert((XorC<true, true>::Value == false), "Unit test failed");
itkStaticAssert((XorC<true, false>::Value == true), "Unit test failed");
itkStaticAssert((XorC<false, true>::Value == true), "Unit test failed");
itkStaticAssert((XorC<false, false>::Value == false), "Unit test failed");
static_assert((XorC<true, true>::Value == false), "Unit test failed");
static_assert((XorC<true, false>::Value == true), "Unit test failed");
static_assert((XorC<false, true>::Value == true), "Unit test failed");
static_assert((XorC<false, false>::Value == false), "Unit test failed");

// Xor between types
itkStaticAssert((std::is_same<Xor<TrueType, TrueType>::Type, FalseType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Xor<TrueType, FalseType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Xor<FalseType, TrueType>::Type, TrueType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Xor<FalseType, FalseType>::Type, FalseType>::value), "Unit test failed");
static_assert((std::is_same<Xor<TrueType, TrueType>::Type, FalseType>::value), "Unit test failed");
static_assert((std::is_same<Xor<TrueType, FalseType>::Type, TrueType>::value), "Unit test failed");
static_assert((std::is_same<Xor<FalseType, TrueType>::Type, TrueType>::value), "Unit test failed");
static_assert((std::is_same<Xor<FalseType, FalseType>::Type, FalseType>::value), "Unit test failed");

// Not between constants
itkStaticAssert((NotC<true>::Value == false), "Unit test failed");
itkStaticAssert((NotC<false>::Value == true), "Unit test failed");
static_assert((NotC<true>::Value == false), "Unit test failed");
static_assert((NotC<false>::Value == true), "Unit test failed");

// Not between types
itkStaticAssert((std::is_same<Not<TrueType>::Type, FalseType>::value), "Unit test failed");
itkStaticAssert((std::is_same<Not<FalseType>::Type, TrueType>::value), "Unit test failed");

#endif
static_assert((std::is_same<Not<TrueType>::Type, FalseType>::value), "Unit test failed");
static_assert((std::is_same<Not<FalseType>::Type, TrueType>::value), "Unit test failed");

return EXIT_SUCCESS;
}

0 comments on commit cd43985

Please sign in to comment.