C++ Logo

std-proposals

Advanced search

Re: [std-proposals] Initial draft for C++: Uniform Initialization for Multiple Variables

From: Sebastian Wittmeier <wittmeier_at_[hidden]>
Date: Sat, 26 Oct 2024 11:13:06 +0200
So better use square brackets   type [var1, var2] = value; type [var1, var2](value); type [var1, var2]{value};   Like a structured binding. But find a way to signify that each variable is initialized with value.   This can be done in the following way:   We introduce std::rep(value), which repeats or replicates values. It returns a std::infinite_tuple, which has infinite size and can return at compile time the type of any of its elements and at runtime the value of any of its elements. Structured bindings are extended to accept std::infinite_tuple. int [x, y, z, w] = std::rep(0);   The std::infinite_tuple with or without structured bindings would have a lot more use cases.   -----Ursprüngliche Nachricht----- Von:Ville Voutilainen via Std-Proposals <std-proposals_at_[hidden]> Gesendet:Fr 25.10.2024 23:42 Betreff:Re: [std-proposals] Initial draft for C++: Uniform Initialization for Multiple Variables An:std-proposals_at_[hidden]; CC:Ville Voutilainen <ville.voutilainen_at_[hidden]>; On Mon, 12 Aug 2024 at 14:45, Amber Bhardwaj via Std-Proposals <std-proposals_at_[hidden]> wrote: > > Hello CppCommunity, > > My name is Amber Bhardwaj. It's been almost a decade since I started using C++. I got an idea that I want to present in front of this cpp community. I am not sure how good this idea is for others! But I feel this feature should be present so kindly review it and suggestions are most welcome. > > 1. Problem Statement > > C++ currently requires separate lines for declaring and initializing multiple variables of the same type. This can become verbose and cumbersome, especially for simple cases where all variables share the same value. > > 2. Proposed Solution > > Introduce a new syntax for uniform initialization of multiple variables within curly braces: >> >> type {var1, var2, ..., varn} = value; type{var1, var2, ..., varn} always means initialization in C++, and is always an expression, never a declaration. The very last thing we want to do is open the door to it possibly also meaning a declaration. -- Std-Proposals mailing list Std-Proposals_at_[hidden] https://lists.isocpp.org/mailman/listinfo.cgi/std-proposals

Received on 2024-10-26 09:13:26