Topic: Static assert default message
Author: Kaba <none@here.com>
Date: Thu, 17 Jun 2010 11:59:46 CST Raw View
Hi,
I find that I can't write
static_assert(N > 0);
in Visual Studio 2010. This seems to be consistent with the current C++
0X draft: the error message is required:
static_assert(N > 0, "N must be a positive number.");
However, I would like it convenient if static_assert without a message
worked as STATIC_ASSERT below:
#define STATIC_ASSERT(x) static_assert((x), #x)
STATIC_ASSERT(N > 0);
This is because many of the tests are simple and self-explanatory, and
stringizing the condition is a reasonable default error message in these
cases.
What do you think?
--
http://kaba.hilvi.org
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use
mailto:std-c++@netlab.cs.rpi.edu<std-c%2B%2B@netlab.cs.rpi.edu>
]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]
Author: =?ISO-8859-1?Q?Daniel_Kr=FCgler?= <daniel.kruegler@googlemail.com>
Date: Thu, 17 Jun 2010 15:13:19 CST Raw View
On 17 Jun., 19:59, Kaba <n...@here.com> wrote:
> I find that I can't write
>
> static_assert(N > 0);
>
> in Visual Studio 2010. This seems to be consistent with the current C++
> 0X draft: the error message is required:
>
> static_assert(N > 0, "N must be a positive number.");
>
> However, I would like it convenient if static_assert without a message
> worked as STATIC_ASSERT below:
>
> #define STATIC_ASSERT(x) static_assert((x), #x)
>
> STATIC_ASSERT(N > 0);
>
> This is because many of the tests are simple and self-explanatory, and
> stringizing the condition is a reasonable default error message in these
> cases.
>
> What do you think?
I think that this is a very reasonable default. Boost also uses it,
if possible:
#define BOOST_STATIC_ASSERT( B ) static_assert(B, #B)
Greetings from Bremen,
Daniel Kr gler
--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]