From: Marcin.Barczynski on
On Mar 31, 1:43 am, Jerzie.Klench...(a)gmail.com wrote:
> Hello all,
>
> I have the following piece of code:
>
> template<int i, int j, int k>
> void foo()
> {
> // rule: i >= j
> // static_assert(i >= j)
> // static_assert((i - j) >= 2 * k)
>
> }
>
> int main()
> {
> foo<1,2,3>();
> return 0;
>
> }
>
> I was wondering how one would go about creating an
> assert that runs at compile time which would give
> an error message based on the assertion?
>
> I've seen static asserts for types but haven't seen
> any for value templates - any ideas?

The easiest way is to declare a template and define only a
specialization:

template <bool> struct static_assert;
template<> struct static_assert<true> { };

Marcin.

--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]