COIN-OR::LEMON - Graph Library

Opened 7 years ago

Last modified 14 months ago

#373 new enhancement

Compile time assertion

Reported by: kpeter Owned by: alpar
Priority: major Milestone: LEMON 1.5 release
Component: core Version: hg main
Keywords: Cc:
Revision id:


Compile time assertion would be useful in some cases (instead of LEMON_ASSERT).

A possible solution is the following:

template <bool> struct STATIC_ASSERT_FAILURE;
template <> struct STATIC_ASSERT_FAILURE<true> {};
template<int x> struct static_assert_test{};

   typedef static_assert_test<\
       sizeof(STATIC_ASSERT_FAILURE< (bool)( x ) >)>\

It could be used like that:


Change History (5)

comment:1 Changed 7 years ago by alpar

It would indeed be useful in some cases. How meaningful/understandable is the error message emitted by the compiler? For example how will it comment the line



comment:2 Changed 7 years ago by kpeter

boost/static_assert.h in the Boost library implements a solution. Maybe we should check it.

comment:3 Changed 5 years ago by alpar

  • Milestone changed from LEMON 1.3 release to LEMON 1.4 release

comment:4 Changed 4 years ago by ggabor

C++11 has a keyword for this:

The latest versions of GCC, Clang, ICC, MSVC all support it. But maybe an ifdef could hide it, if the compiler doesn't support it.

comment:5 Changed 14 months ago by alpar

  • Milestone changed from LEMON 1.4 release to LEMON 1.5 release
Note: See TracTickets for help on using tickets.