COIN-OR::LEMON - Graph Library

Opened 14 years ago

Last modified 8 years ago

#373 new enhancement

Compile time assertion

Reported by: Peter Kovacs Owned by: Alpar Juttner
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 14 years ago by Alpar Juttner

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 14 years ago by Peter Kovacs

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

comment:3 Changed 11 years ago by Alpar Juttner

Milestone: LEMON 1.3 releaseLEMON 1.4 release

comment:4 Changed 10 years ago by Gábor Gévay

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 8 years ago by Alpar Juttner

Milestone: LEMON 1.4 releaseLEMON 1.5 release
Note: See TracTickets for help on using tickets.