On Monday, 2015-02-09, 16:52:39, PCMan wrote:
> On Mon, Feb 9, 2015 at 7:03 AM, Kevin Krammer <kram...@kde.org> wrote:
> > On Monday, 2015-02-09, 04:07:04, PCMan wrote:
> > > ​OK, a list of main features I plan to use.
> > > 1. auto
> > > 2. nullptr
> > > 3. new range based for() loop for iterating over containers
> > 
> > One thing to keep looking out for with this is to be very careful when
> > applying it on Qt containers (can trigger detach(), i.e. deep copy).
> > 
> Thank you for the info.
> 
> I did not expect that!
> Previously I planed to use Qt containers with ranged for loop. :-(
> Sounds like a bad idea, then.

You can use foreach() for Qt containers and ranged-for for STL containers.
They are potentially bad for the other use case, since they were designed with 
their respective containers in mind.

foreach() makes a copy of the container, which is no problem for a Qt 
container since it is reference counted, but it leads to an actual copy on an 
STL container.

ranged-for calls being/end of a container, which are only const if the 
container itself is const.
On a non-const Qt container, the invocation of non-const methods leads to 
detach(). If the container has a reference count > 1, this will lead to an 
actual copy.

The easiest way is to use the respective convenience "for", but ranged-for can 
be used for Qt containers if they are either ensured a reference count of 1 or 
the expression passed to the ranged-for is a const type.

> > > 5. smart pointers
> > 
> > Could also be using Qt's smart pointer in most cases.
> 
> True, but if the standard library provides the same facilities, it's good
> to use it.
> For code not related to UI, using only the standard library can make it
> reusable in non-Qt projects.
> That's the point of this proposal.

Ah, I see.
I was thinking about code involving Qt :-)

> > 6. move semantics/r value reference
> > 
> > > 7. override keyword (optional)
> > 
> > Can always use Q_DECL_OVERRIDE but override is of course shorter.
> 
> True, but C++ code full of macros really looks alien.
> If we don't plan to support legacy systems that have a broken c++ compiler,
> it's safe to use real C++ keyword here.

Oh, I agree, just pointing out an option.

Cheers,
Kevin
-- 
Kevin Krammer, KDE developer, xdg-utils developer
KDE user support, developer mentoring

Attachment: signature.asc
Description: This is a digitally signed message part.

------------------------------------------------------------------------------
Dive into the World of Parallel Programming. The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Lxde-list mailing list
Lxde-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/lxde-list

Reply via email to