+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.
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