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


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

Re: What is the good of new way of coding?

From "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>
Newsgroups comp.lang.c++
Subject Re: What is the good of new way of coding?
Date 2022-09-17 12:03 -0700
Organization A noiseless patient Spider
Message-ID <tg55ll$7nub$1@dont-email.me> (permalink)
References (4 earlier) <tg4qtf$1ub0$1@gioia.aioe.org> <tg4r45$6q5f$1@dont-email.me> <tg4rnu$aeq$1@gioia.aioe.org> <tg4sug$6vcn$1@dont-email.me> <tg51mc$7cfq$1@dont-email.me>

Show all headers | View raw


On 9/17/2022 10:55 AM, Alf P. Steinbach wrote:
> On 17 Sept 2022 18:34, Bonita Montero wrote:
>> Am 17.09.2022 um 18:13 schrieb Muttley@dastardlyhq.com:
>>> On Sat, 17 Sep 2022 18:03:37 +0200
>>> Bonita Montero <Bonita.Montero@gmail.com> wrote:
>>>> Am 17.09.2022 um 17:59 schrieb Muttley@dastardlyhq.com:
>>>>> On Sat, 17 Sep 2022 17:31:19 +0200
>>>>> Bonita Montero <Bonita.Montero@gmail.com> wrote:
>>>>>> Am 17.09.2022 um 16:50 schrieb Muttley@dastardlyhq.com:
>>>>>>> On Sat, 17 Sep 2022 15:03:25 +0200
>>>>>>> Bonita Montero <Bonita.Montero@gmail.com> wrote:
>>>>>>>> Am 17.09.2022 um 14:46 schrieb wij:
>>>>>>>>> I did not update my C++ understanding (probable since C++11) to 
>>>>>>>>> find out
>>>> I
>>>>>>>>> cannot understand what the codes are about !!!
>>>>>>>>>
>>>>>>>>> --- frorm https://groups.google.com/g/comp.lang.c++/c/2ebc6ifoPr4
>>>>>>>>> #include <iostream>
>>>>>>>>> #include <utility>
>>>>>>>>>
>>>>>>>>> using namespace std;
>>>>>>>>>
>>>>>>>>> int main()
>>>>>>>>> {
>>>>>>>>> auto pow = []<unsigned P>( double b, 
>>>>>>>>> integral_constant<unsigned, P> )
>>>>>>>>> -> double
>>>>>>>>> {
>>>>>>>>> auto unroll = [&]<size_t ... Indices>( index_sequence<Indices 
>>>>>>>>> ...> )
>>>>>>>>> -> double
>>>>>>>>> {
>>>>>>>>> return ((Indices, b) * ...);
>>>>>>>>> };
>>>>>>>>> if constexpr( P )
>>>>>>>>> return unroll( make_index_sequence<P>() );
>>>>>>>>> else
>>>>>>>>> return b;
>>>>>>>>> };
>>>>>>>>> cout << pow( 2.0, integral_constant<unsigned, 10'000>() ) << endl;
>>>>>>>>> }
>>>>>>>>> ------
>>>>>>>>>
>>>>>>>>> Question1: What would the code look like if using C++2006 for 
>>>>>>>>> the above
>>>>>>>> 'program'?
>>>>>>>>
>>>>>>>> It's not possible to write that before C++20.
>>>>>>>
>>>>>>> Really? So it outputs some special assembler reserved for C++20 
>>>>>>> does it?
>>>>>>>
>>>>>>
>>>>>> No, you can't unroll variable.
>>>>>
>>>>> I'm pretty sure the same functionality could be achieved in older 
>>>>> C++ or
>>>>> even C albeit with more lines of code.
>>>>>
>>>>
>>>> Show me.
>>>>
>>>
>>> I don't have a c++ 20 compiler so I can't see what it does and I have 
>>> better
>>> things to do on a saturday than run it in my head.
>>>
>>
>> Without C++20 you would have to unroll the fold expressions
>> N times, in this case 10.000 times. Have fun !
> 
> The Boost preprocessor library comes to mind.

Iirc Boost preprocessor is based on the Chaos preprocessor codebase, 
right? Anyway, check out this loop unrolling in C for a HMAC lib:

https://github.com/ogay/hmac/blob/master/sha2.c

Macros indeed. Search the code for UNROLL_LOOPS :^)

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


Thread

What is the good of new way of coding? wij <wyniijj2@gmail.com> - 2022-09-17 05:46 -0700
  Re: What is the good of new way of coding? Bonita Montero <Bonita.Montero@gmail.com> - 2022-09-17 15:03 +0200
    Re: What is the good of new way of coding? Muttley@dastardlyhq.com - 2022-09-17 14:50 +0000
      Re: What is the good of new way of coding? Bonita Montero <Bonita.Montero@gmail.com> - 2022-09-17 17:31 +0200
        Re: What is the good of new way of coding? Muttley@dastardlyhq.com - 2022-09-17 15:59 +0000
          Re: What is the good of new way of coding? Bonita Montero <Bonita.Montero@gmail.com> - 2022-09-17 18:03 +0200
            Re: What is the good of new way of coding? Muttley@dastardlyhq.com - 2022-09-17 16:13 +0000
              Re: What is the good of new way of coding? Bonita Montero <Bonita.Montero@gmail.com> - 2022-09-17 18:34 +0200
                Re: What is the good of new way of coding? "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-09-17 19:55 +0200
                Re: What is the good of new way of coding? "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-09-17 12:03 -0700
                Re: What is the good of new way of coding? Bonita Montero <Bonita.Montero@gmail.com> - 2022-09-18 16:21 +0200
                Re: What is the good of new way of coding? Muttley@dastardlyhq.com - 2022-09-19 08:30 +0000
                Re: What is the good of new way of coding? Bonita Montero <Bonita.Montero@gmail.com> - 2022-09-19 10:37 +0200
                Re: What is the good of new way of coding? Muttley@dastardlyhq.com - 2022-09-19 08:54 +0000
                Re: What is the good of new way of coding? Bonita Montero <Bonita.Montero@gmail.com> - 2022-09-19 11:13 +0200
  Re: What is the good of new way of coding? Bonita Montero <Bonita.Montero@gmail.com> - 2022-09-17 15:23 +0200
    Re: What is the good of new way of coding? Bonita Montero <Bonita.Montero@gmail.com> - 2022-09-17 15:38 +0200
  Re: What is the good of new way of coding? Andreas Kempe <kempe@lysator.liu.se> - 2022-09-17 14:37 +0000
    Re: What is the good of new way of coding? Bonita Montero <Bonita.Montero@gmail.com> - 2022-09-17 16:40 +0200
      Re: What is the good of new way of coding? Andreas Kempe <kempe@lysator.liu.se> - 2022-09-17 20:52 +0000
        Re: What is the good of new way of coding? Mr Flibble <flibble@reddwarf.jmc.corp> - 2022-09-17 22:18 +0100
          Re: What is the good of new way of coding? Mr Flibble <flibble@reddwarf.jmc.corp> - 2022-09-17 22:21 +0100
            Re: What is the good of new way of coding? Andreas Kempe <kempe@lysator.liu.se> - 2022-09-17 21:31 +0000
  Re: What is the good of new way of coding? Muttley@dastardlyhq.com - 2022-09-17 14:52 +0000
    Re: What is the good of new way of coding? Bonita Montero <Bonita.Montero@gmail.com> - 2022-09-17 17:32 +0200

csiph-web