lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Default values for default arguments


From: Greg Chicares
Subject: Re: [lmi] Default values for default arguments
Date: Fri, 10 Feb 2017 13:24:20 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Icedove/45.6.0

On 2017-02-04 14:59, Vadim Zeitlin wrote:
> On Sat, 4 Feb 2017 04:51:35 +0000 Greg Chicares <address@hidden> wrote:
> 
> GC> Vadim--Do you see any reason why we should not prefer the uniform
> GC> "{}" syntax to specify default values for default arguments as in
> GC> the following examples? [... e.g. ...]
> GC> -        ,std::string const&              a_default_keyword = ""
> GC> +        ,std::string const&              a_default_keyword = {}
[...]
> [...] just in case it wasn't
> obvious not only to me, this relies on the existence of the ctor from
> std::initializer_list in both std::string and std::vector. IOW, this
> wouldn't work for any class not providing such ctor, so if the question is
> "can we uniformly use {} to specify default values for all classes", then
> the answer is definitely no.

Even worse...

N3337: C++11 [5.17/9]   "The meaning of x={} is x=T()"
N4618: C++17 [5.18/9.1] "The meaning of x={} is x=T{}"

...the answer was definitely yes, and then they changed it.

Thus, the only braced-initialization modernization I would propose is
eliminating the brace-initialized C arrays of POD types in cases like:

-        static int const n = 101;
-        static double const d[n] =
+        static std::vector<double> const v
            {
            //0     1     2     3     4     5     6     7     8     9
            2.50, 2.50, 2.50, 2.50, 2.50, 2.50, 2.50, 2.50, 2.50, 2.50, // 00
[...]
            1.00                                                        // 100
            };
-        static std::vector<double> const v(d, d + n);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]