On 06/06/2015 11:24 AM, Uwe Klotz wrote:
> +1 Gavin, I also prefer direct-initialization over copy-initialization.
>
> For classes without a copy constructor you need to use
> direct-initialization anyway. And if you bravely declare your single
> parameter constructors as 'explicit' (what you should almost always do,
> even if Qt does not) you also need to use direct-initialization.
>
> http://en.cppreference.com/w/cpp/language/direct_initialization
> "Direct-initialization is more permissive than copy-initialization:
> copy-initialization only considers non-explicit constructors and
> user-defined conversion functions, while direct-initialization considers
> all constructors and implicit conversion sequences. "
>
> But I must confess that I use the assignment style if the type is
> obviously a native type.

This Argument is only valid without move semantics. With move semantics

auto str = QString("foo");

is equivalent to direct initialization. If it wasn't for move semantics 
auto wouldn't make much sense either, since copying some classes can be 
quite expensive (and C++ code should be fast, recommended coding styles 
should produce fast code)

If we are using Qt5 most of the Qt types support move. If we want to use 
auto initialization with or own classes effectively we have to add them.

I personally like the AAA style since it requires me to initialize each 
variable explicitly (this can avoid some nasty bugs). But I admit it can 
be problematic to use this in old codebases. The CSAMPLE in mixxx is an 
example. There is just no nicely readable way to auto initialize it.


>
> Uwe
>
> On 06/06/2015 02:11 AM, Gavin Swanson wrote:
>>
>> are we in violent agreement then? Why not do the optimal thing in the
>> first place for consistency sake?  Rather than rely on the compiler to
>> do it for you. Especially in a case like this where the optimization
>> is no more work nor is it less readable.
>>
>>
>> On Fri, Jun 5, 2015, 7:38 PM Owen Williams <owilli...@mixxx.org
>> <mailto:owilli...@mixxx.org>> wrote:
>>
>>     That's what I said?
>>
>>     "The compiler is free to elide (remove) the temporary+copying
>> whenever
>>     it can, but copy constructor must still be accessible"
>>
>>
>>
>>     On Fri, 2015-06-05 at 23:34 +0000, Gavin Swanson wrote:
>>     > http://stackoverflow.com/a/4470763
>>     >
>>     >
>>     > On Fri, Jun 5, 2015, 7:21 PM Owen Williams <owilli...@mixxx.org
>>     <mailto:owilli...@mixxx.org>>
>>     > wrote:
>>     >         Since CSAMPLE is a simple type, assignment is best --
>> and when
>>     >         it works,
>>     >         assignment is the way to go (hurray for smart compilers
>>     >         eliding copies).
>>     >         With the form sample(0.0), it gives the impression that
>>     >         CSAMPLE is a
>>     >         complex type with a constructor.
>>     >
>>     >         On Fri, 2015-06-05 at 22:16 +0000, Gavin Swanson wrote:
>>     >         > CSAMPLE sample(0.0);
>>     >         >
>>     >         >
>>     >         > On Fri, Jun 5, 2015, 4:45 PM Owen Williams
>>     >         <owilli...@mixxx.org <mailto:owilli...@mixxx.org>>
>>     >         > wrote:
>>     >         >         On Fri, 2015-06-05 at 22:30 +0200, Daniel
>> Schürmann
>>     >         wrote:
>>     >         >
>>     >         >         > CSAMPLE sample = 0.0;
>>     >         >
>>     >         >         This one.  auto should really only be used when
>>     >         assigning from
>>     >         >         a
>>     >         >         function whose return value is obvious.
>>     >         >
>>     >         >
>>     >         >
>>     >         >
>>     >         >
>>     >
>>
>> ------------------------------------------------------------------------------
>>
>>     >         >  _______________________________________________
>>     >         >         Get Mixxx, the #1 Free MP3 DJ Mixing software
>> Today
>>     >         > http://mixxx.org
>>     >         >
>>     >         >
>>     >         >         Mixxx-devel mailing list
>>     >         > Mixxx-devel@lists.sourceforge.net
>>     <mailto:Mixxx-devel@lists.sourceforge.net>
>>     >         >
>>     > https://lists.sourceforge.net/lists/listinfo/mixxx-devel
>>     >
>>     >
>>
>>
>>
>>
>> ------------------------------------------------------------------------------
>>
>>
>>
>> _______________________________________________
>> Get Mixxx, the #1 Free MP3 DJ Mixing software Today
>> http://mixxx.org
>>
>>
>> Mixxx-devel mailing list
>> Mixxx-devel@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/mixxx-devel
>
>
>
>
> ------------------------------------------------------------------------------
>
>
>
> _______________________________________________
> Get Mixxx, the #1 Free MP3 DJ Mixing software Today
> http://mixxx.org
>
>
> Mixxx-devel mailing list
> Mixxx-devel@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/mixxx-devel
>

------------------------------------------------------------------------------
_______________________________________________
Get Mixxx, the #1 Free MP3 DJ Mixing software Today
http://mixxx.org


Mixxx-devel mailing list
Mixxx-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mixxx-devel

Reply via email to