Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Message with static_assert

33 views
Skip to first unread message

Matt Calabrese

unread,
Nov 29, 2010, 2:20:09 PM11/29/10
to
Is there a reason why the string-literal parameter to static_assert is
not optional? I find myself frequently using the macro
BOOST_STATIC_ASSERT instead since underneath the hood it just uses
static_assert when available, repeating the stringized condition as
the static_assert message. This seems to be appropriate default
behavior. I understand that it is an advantage to be able to provide a
clear message, however, very often the condition itself is clear
enough and it is tedious to have to create an explicit message for
each assertion.

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

Joe Gottman

unread,
Nov 30, 2010, 5:30:14 AM11/30/10
to
On 11/29/2010 2:20 PM, Matt Calabrese wrote:
> Is there a reason why the string-literal parameter to static_assert is
> not optional? I find myself frequently using the macro
> BOOST_STATIC_ASSERT instead since underneath the hood it just uses
> static_assert when available, repeating the stringized condition as
> the static_assert message. This seems to be appropriate default
> behavior. I understand that it is an advantage to be able to provide a
> clear message, however, very often the condition itself is clear
> enough and it is tedious to have to create an explicit message for
> each assertion.
>

You could always use a preprocessor macro:

#define DEFAULT_STATIC_ASSERT(condition) static_assert(condition, #condition)

Joe Gottman

Matt Calabrese

unread,
Nov 30, 2010, 10:03:55 PM11/30/10
to
On Nov 30, 5:30 am, Joe Gottman <josephgott...@comcast.net> wrote:
> You could always use a preprocessor macro:
>
> #define DEFAULT_STATIC_ASSERT(condition) static_assert(condition, #condition)

Yes, as I said, that is what I'm already doing with
BOOST_STATIC_ASSERT. I just think it's rather silly that we have to
use a macro to simulate what likely should be the default behavior to
begin with.

0 new messages