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


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

Re: constexpr was created why?

From Muttley@dastardlyhq.com
Newsgroups comp.lang.c++
Subject Re: constexpr was created why?
Date 2022-07-20 15:12 +0000
Organization Aioe.org NNTP Server
Message-ID <tb9619$10sd$1@gioia.aioe.org> (permalink)
References <7e7658ec-0e5a-43b5-8d81-ed2157f8415dn@googlegroups.com> <tb7kea$1fr6$1@gioia.aioe.org> <tb8e2n$1o26$1@gioia.aioe.org> <tb8ngq$1itlj$1@dont-email.me>

Show all headers | View raw


On Wed, 20 Jul 2022 13:04:57 +0200
David Brown <david.brown@hesbynett.no> wrote:
>On 20/07/2022 10:23, Muttley@dastardlyhq.com wrote:
>> On Wed, 20 Jul 2022 03:06:18 +0200
>> Manfred <noname@add.invalid> wrote:
>>> On 7/20/2022 12:25 AM, gdo...@gmail.com wrote:
>>>> is this one of those things where the committee had nothing better to do?
>>> ok, maybe I haven't got to the point where I see the demand for such, but I
>>> will be open-minded and use it when I see an opportunity.
>>>>
>>>> prevents ..., more intuitive ..., easier to type than ..., more expressive
>>> than ..., solves the problem of ..., well I'm sure I'll see all of that at
>>> some point.
>>>
>>> Short answer: to facilitate compile time evaluation.
>> 
>> IME ever constexpr I've seen could have been evaluated by the developer
>> directly and just been a hard coded const/macro. Constexprs are generally a
>> solution looking for a problem.
>> 
>
>Many things could be calculated by the developer and hardcoded into 
>software.  But we usually don't do that, when the programming language 
>provides a way to handle it.  When you use "sizeof" in a memcpy or 
>allocation function, it is not because the developer is incapable of 
>figuring out the size of the type.  It is because using "sizeof" makes 
>code clearer, easier to change, maintain or re-use, easier to port, and 
>less likely to be wrong.
>
>The same logic applies to other compile-time calculations.  Let the 
>computer do what the computer is good at, leaving the programmer to do 
>what he/she is better at.

sizeof() makes it clear what you are doing. A constexpr is code that someone
will have to understand and/or manually execute to find what the value it 
produces is. I'm not sure adding code to create const values aids code clarity
in any way.

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


Thread

constexpr was created why? "gdo...@gmail.com" <gdotone@gmail.com> - 2022-07-19 15:25 -0700
  Re: constexpr was created why? Mr Flibble <flibble@reddwarf.jmc.corp> - 2022-07-19 23:56 +0100
    Re: constexpr was created why? "gdo...@gmail.com" <gdotone@gmail.com> - 2022-07-19 17:18 -0700
      Re: constexpr was created why? Mr Flibble <flibble@reddwarf.jmc.corp> - 2022-07-20 01:21 +0100
  Re: constexpr was created why? Manfred <noname@add.invalid> - 2022-07-20 03:06 +0200
    Re: constexpr was created why? Bonita Montero <Bonita.Montero@gmail.com> - 2022-07-20 03:24 +0200
    Re: constexpr was created why? Muttley@dastardlyhq.com - 2022-07-20 08:23 +0000
      Re: constexpr was created why? David Brown <david.brown@hesbynett.no> - 2022-07-20 13:04 +0200
        Re: constexpr was created why? Muttley@dastardlyhq.com - 2022-07-20 15:12 +0000
          Re: constexpr was created why? Öö Tiib <ootiib@hot.ee> - 2022-07-20 21:00 -0700
  Re: constexpr was created why? David Brown <david.brown@hesbynett.no> - 2022-07-20 09:27 +0200
  Re: constexpr was created why? Juha Nieminen <nospam@thanks.invalid> - 2022-07-20 09:46 +0000

csiph-web