Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #68148

Re: Static_assert in 2017 C++

From David Brown <david.brown@hesbynett.no>
Newsgroups comp.lang.c++
Subject Re: Static_assert in 2017 C++
Date 2019-09-03 08:21 +0200
Organization A noiseless patient Spider
Message-ID <qkl0pu$flk$1@dont-email.me> (permalink)
References <31f1dc85-3b69-4787-8fa8-e4ee5836c609@googlegroups.com> <68VaF.480308$on8.285950@fx46.iad> <0e36df1d-7918-47fb-abef-7f50dd64b99d@googlegroups.com> <3%fbF.340450$oq9.65742@fx47.iad>

Show all headers | View raw


On 02/09/2019 23:40, Richard Damon wrote:
> On 9/1/19 9:58 PM, woodbrian77@gmail.com wrote:
>> On Sunday, September 1, 2019 at 2:39:57 PM UTC-5, Richard Damon wrote:
>>>
>>> Personally, I would be tempted to leave it as is. Making useful error
>>> messages is generally good. Making the Error comment optional might make
>>> some sense if the Error Condition is fully self documenting, but the
>>> linkage between IEC559 and IEEE754 isn't inherently obvious.
>>
>> Right.
>>
>>> I might
>>> even extend the error message to something more verbose, like
>>>
>>> IEEE754/IEC559 Floating point assumed and needed
>>
>> I don't like having iec559 in there.  If they want
>> they can look at the line for more info.  I agree in
>> principle that that's a better message.  On the other
>> hand, some say this isn't likely to assert very often
>> so the error message may not be that important.
>>
>>>
>>> After all, a static_assert imposes zero run time costs, just minimal
>>> text space in the file and virtually zero processing time during
>>> compilation. Treat it as file documentation for the requirements of the
>>> system, and make it readable.
>>
> 
> The one purpose of IEC559 in the message is that that is what the
> language calls it, so including it in the message might be useful.
> 
> My main thought is why work hard to coming up with a minimal message
> when there is NO run time cost to the fuller message. The string
> shouldn't even be included in the image, as static_assert generates no
> code. Yes, the message may be never seen, but if it IS seen, it would
> seem best to make it clear. The expected output (but I don't think
> required) is printing the message, and maybe the condition that was
> false as part of the error message. My preference would be that the
> message be fairly self explanatory by itself.
> 
> Yes, they can go to the source code to read a comment near by, and maybe
> even that happens somewhat automatically if they are building in an IDE,
> but the less you assume about the environment, the better for the user.
> If the message is clear, the user might realize without needing to dig
> into the code, that they need to invoke the build with a flag to use IEC559.
> 
> It would be nice if in the vicinity of the static_assert was some
> comments explaining WHY you have such a statement in the code, in case
> someone on a machine that doesn't support it tries to use it, so they
> can figure out if they want to try to remove the assumptions in the code
> or if they need to try to find another package.
> 

As a follow-on from that, remember that static assertions are free in 
the code, document requirements, and protect from unwarranted 
assumptions.  So it is fine to duplicate them.  If you have a library 
file with twenty mathematical functions, and three of them rely on IEEE 
formats for some reason, put the static assertion at all three 
functions.  And the message can explain /why/ the assertion is there, 
although that could also be left in comments in the code.

static_assert(std::numeric_limits<float>::is_iec559,
	"IEEE format is needed for exponent hack in log_base2");
double log_base2(double x)
{
	...
}

Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Static_assert in 2017 C++ woodbrian77@gmail.com - 2019-08-31 15:55 -0700
  Re: Static_assert in 2017 C++ Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-09-01 11:43 +0100
    Re: Static_assert in 2017 C++ rick.c.hodgin@gmail.com - 2019-09-01 04:16 -0700
      Re: Static_assert in 2017 C++ Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-09-01 13:15 +0100
    Re: Static_assert in 2017 C++ Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-01 14:56 +0200
      Re: Static_assert in 2017 C++ Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> - 2019-09-01 14:20 +0100
        Re: Static_assert in 2017 C++ Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-01 15:35 +0200
          Re: Static_assert in 2017 C++ Ian Collins <ian-news@hotmail.com> - 2019-09-02 07:30 +1200
            Re: Static_assert in 2017 C++ Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-02 07:16 +0200
              Re: Static_assert in 2017 C++ David Brown <david.brown@hesbynett.no> - 2019-09-02 13:13 +0200
                Re: Static_assert in 2017 C++ Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-02 15:55 +0200
                Re: Static_assert in 2017 C++ David Brown <david.brown@hesbynett.no> - 2019-09-02 22:02 +0200
  Re: Static_assert in 2017 C++ Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-01 12:48 +0200
    Re: Static_assert in 2017 C++ Robert Wessel <robertwessel2@yahoo.com> - 2019-09-01 09:21 -0500
      Re: Static_assert in 2017 C++ woodbrian77@gmail.com - 2019-09-01 09:53 -0700
        Re: Static_assert in 2017 C++ Robert Wessel <robertwessel2@yahoo.com> - 2019-09-01 22:29 -0500
          Re: Static_assert in 2017 C++ Robert Wessel <robertwessel2@yahoo.com> - 2019-09-01 22:34 -0500
            Re: Static_assert in 2017 C++ woodbrian77@gmail.com - 2019-09-02 07:32 -0700
      Re: Static_assert in 2017 C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-01 20:35 -0700
        Re: Static_assert in 2017 C++ Robert Wessel <robertwessel2@yahoo.com> - 2019-09-01 22:50 -0500
          Re: Static_assert in 2017 C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-01 21:12 -0700
            Re: Static_assert in 2017 C++ Robert Wessel <robertwessel2@yahoo.com> - 2019-09-02 00:09 -0500
              Re: Static_assert in 2017 C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-01 22:39 -0700
              Re: Static_assert in 2017 C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-04 22:49 -0700
          Re: Static_assert in 2017 C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-01 21:13 -0700
            Re: Static_assert in 2017 C++ Robert Wessel <robertwessel2@yahoo.com> - 2019-09-02 00:20 -0500
              Re: Static_assert in 2017 C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-01 22:41 -0700
        Re: Static_assert in 2017 C++ Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-02 07:14 +0200
          Re: Static_assert in 2017 C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-01 22:46 -0700
            Re: Static_assert in 2017 C++ Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-02 07:55 +0200
              Re: Static_assert in 2017 C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-01 22:58 -0700
                Re: Static_assert in 2017 C++ Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-02 08:20 +0200
                Re: Static_assert in 2017 C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-01 23:24 -0700
                Re: Static_assert in 2017 C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-01 23:25 -0700
                Re: Static_assert in 2017 C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-01 23:26 -0700
                Re: Static_assert in 2017 C++ Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-02 08:33 +0200
                Re: Static_assert in 2017 C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-02 00:18 -0700
                Re: Static_assert in 2017 C++ Bonita Montero <Bonita.Montero@gmail.com> - 2019-09-02 09:23 +0200
                Re: Static_assert in 2017 C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-02 00:26 -0700
              Re: Static_assert in 2017 C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-01 22:58 -0700
                Re: Static_assert in 2017 C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-01 22:59 -0700
                Re: Static_assert in 2017 C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2019-09-04 23:04 -0700
  Re: Static_assert in 2017 C++ Richard Damon <Richard@Damon-Family.org> - 2019-09-01 15:39 -0400
    Re: Static_assert in 2017 C++ woodbrian77@gmail.com - 2019-09-01 18:58 -0700
      Re: Static_assert in 2017 C++ Richard Damon <Richard@Damon-Family.org> - 2019-09-02 17:40 -0400
        Re: Static_assert in 2017 C++ James Kuyper <jameskuyper@alumni.caltech.edu> - 2019-09-02 22:53 -0400
        Re: Static_assert in 2017 C++ David Brown <david.brown@hesbynett.no> - 2019-09-03 08:21 +0200
    Re: Static_assert in 2017 C++ Jorgen Grahn <grahn+nntp@snipabacken.se> - 2019-09-02 14:43 +0000
  Re: Static_assert in 2017 C++ Keith Thompson <kst-u@mib.org> - 2019-09-01 20:48 -0700
  Re: Static_assert in 2017 C++ David Brown <david.brown@hesbynett.no> - 2019-09-03 08:25 +0200
    Re: Static_assert in 2017 C++ Keith Thompson <kst-u@mib.org> - 2019-09-03 00:35 -0700
      Re: Static_assert in 2017 C++ David Brown <david.brown@hesbynett.no> - 2019-09-03 10:31 +0200

csiph-web