1

Topic: list vs aggregate initialization

2

Re: list vs aggregate initialization

Hello, rg45, you wrote: R> Greetings to all. There is a desire to talk about aggregate and list  and, how them . In general now, when in constexpr-functions it is possible not to restrict practically itself it is possible to paint bluntly in a forehead any logic of initialization. For example: template <typename T, size_t N> struct Array {private: T data [N]; public: constexpr Array (std:: initializer_list <T> init): data {} {if (init.size ()> N) {throw "overflow";} using std:: begin; using std:: end; auto dst = begin (data); for (auto src = begin (init); src! = end (init); ++ src, ++ dst) {*dst = *src;}} auto begin () const {return std:: begin (data);} auto end () const {return std:: end (data);}}; Quite works. And if to mark result as constexpr all these cycles and checks  will be are fulfilled at a compilation stage: https://ideone.com/J3t69X

3

Re: list vs aggregate initialization

Hello, watchmaker, you wrote: W> Quite works. W> and if to mark result as constexpr all these cycles and checks  will be are fulfilled at a compilation stage: https://ideone.com/J3t69X I forgot accent to put down, generally, the dream was all it to do in the initialization list. And I even have a working variant, but it is awful! The initialization list after all is completely not mandatory consists of constants, there can quite be and  the data. And objects Array if to look with a sight in application area, will not be constexpr, in the majority.

4

Re: list vs aggregate initialization

Hello, watchmaker, you wrote: W> In general now when in constexpr-functions it is possible not to restrict practically itself it is possible to paint bluntly in a forehead any logic of initialization. W> for example: W> W> constexpr Array (std:: initializer_list <T> init) W> By the way, can you will comment, why  initializer_list to accept on value? Something changes it in essence?

5

Re: list vs aggregate initialization

https://stackoverflow.com/questions/178 … d-by-value it is as far as I understand similar string_view

6

Re: list vs aggregate initialization

Hello, reversecode, you wrote: R> https://stackoverflow.com/questions/178 … d-by-value R> it is as far as I understand similar string_view Well arguments are clear, basically. At the same time, nobody speaks: "do not transfer under the link, and that happens something terrible" Me here this moment interested most of all.

7

Re: list vs aggregate initialization

How it does not happen? Happens, the code will be) more slowly) superfluous operators of copying will be added and then heroes on forums will shout that With ++ brakes

8

Re: list vs aggregate initialization

Hello, reversecode, you wrote: R> as it does not happen? Happens, the code will be) more slowly) superfluous operators of copying will be added R> and then heroes on forums will shout that With ++ I brake  today, absolutely casually, glanced in , it appears, the question of uselessness of pluses is solved for a long time already the Author: IT Date: 26.02 17:51. Mankind the Author: IT Date: 26.02 19:28.

9

Re: list vs aggregate initialization

Hello, watchmaker, you wrote: W> In general now when in constexpr-functions it is possible not to restrict practically itself it is possible to paint bluntly in a forehead any logic of initialization. W> and if to mark result as constexpr all these cycles and checks  will be are fulfilled at a compilation stage: https://ideone.com/J3t69X I while consider only the scenario, when all these objects NOT constexpr. Reached here such perversion: https://ideone.com/3vSCbr template <typename T, size_t N> struct Array {public: Array () = default; Array (std:: initializer_list <T> init): Array (init, std:: make_index_sequence <N> ()) {} auto begin () const {return std:: begin (data);} auto end () const {return std:: end (data);} private: template <size_t... I> Array (std:: initializer_list <T> init, std:: index_sequence I.>, T def_value = T ()): data {get <I> (init, def_value)...} {} template <size_t I> static const T& get (const std::initializer_list<T>& init, const T& def_value) {return I <init.size ()? init.begin () [I]: def_value;} private: std:: array <T, N> data;//T data [N];}; I Look at it and I think, whether it is necessary to break spears? And can, the idea what comes to mind to somebody.

10

Re: list vs aggregate initialization

If are afraid Array <Array <Array <Array <int, 3>, 3>, 3>, 3>  that probably costs

11

Re: list vs aggregate initialization

Hello, reversecode, you wrote: R> if are afraid Array <Array <Array <Array <int, 3>, 3>, 3>, 3>  that probably costs the nastiest here is a handling of the incoincident sizes. If not it would be quite .