Program Listing for File compile_time_assert.hpp

Return to documentation for file (include/ecl/errors/compile_time_assert.hpp)

/*****************************************************************************
** Ifdefs
*****************************************************************************/

#ifndef ECL_ERRORS_COMPILE_TIME_ASSERT_HPP_
#define ECL_ERRORS_COMPILE_TIME_ASSERT_HPP_

/*****************************************************************************
** Includes
*****************************************************************************/

#include "macros.hpp"

/*****************************************************************************
** Namespaces
*****************************************************************************/

namespace ecl {


/*****************************************************************************
** Classes
*****************************************************************************/
template <bool> struct COMPILE_TIME_FAILURE;

template <> struct COMPILE_TIME_FAILURE<true> {};

template <int x> struct static_assert_test {};

} // namespace ecl
#define ecl_compile_time_assert( logical_expression ) \
   typedef ecl::static_assert_test<sizeof(ecl::COMPILE_TIME_FAILURE< static_cast<bool>(logical_expression) >)> JOIN(compile_time_check,__LINE__) [[gnu::unused]]

// If the (void)ERROR_##message is absent, we get unused variable warnings.
#define ecl_verbose_compile_time_assert( logical_expression, message ) \
    { \
        ecl::COMPILE_TIME_FAILURE<( (logical_expression) != 0)> ERROR_##message; \
        (void)ERROR_##message; \
    }

#endif /* ECL_ERRORS_COMPILE_TIME_ASSERT_HPP_ */