Sunday, April 21, 2013

make_unique in C++14


make_unique

One of the smallest additions is actually great in its impact. It’s make_unique:
  1. auto u = make_unique<some_type>( constructor, parameters, here );
The reason make_unique has important impact is that now we can teach C++ developers to mostly never use explicit new again. In C++11 we already could teach to never use raw pointers and explicit delete again, except in rare cases that are hidden inside a class in order to do something like implement a low-level data structure. However, we could not teach to never write new because although make_shared was provided to create a shared_ptrnewwas still needed to create a unique_ptr. Now, instead of “new”, write make_unique or make_shared.
With draft C++14, we can say simply: Don’t use raw pointers, new and delete, except rarely when implementing low-level data structures. Allocate with make_unique or make_shared, use weak_ptr where appropriate to break cycles, and don’t worry about dangling pointers in C++ again.


From http://isocpp.org/blog/2013/04/trip-report-iso-c-spring-2013-meeting

Sunday, April 14, 2013

Difference between NUL and NULL in C

From "Expert C programming - Deep C secrets" book:

The one "l" NUL ends an ASCII string,
Two two "l" NULL points to no thing.

If you check your include files, you will see definition of null as

#define NULL ((void*)0)

while NUL is first symbol in ASCII table (with value of 0).

Scrolling QScrollArea causes other widgets flickering

Today I've experienced a problem with QScrollArea which was placed besides another widget, like this:

 ________________    ______________
|                |  |              |
|                |  |              |
|                |  |              |
|                |  |              |
|   QWidget      |  |  QScrollArea |
|                |  |              |
|                |  |              |
|                |  |              |
 ----------------    --------------

Now, when my QScrollArea was scrolled into left, that caused part of QWidget that was overlapping with QScrollArea content to flicker.

To avoid this behavior, before scrolling (I am scrolling QScrollArea with buttons, but I guess connecting to the sliderPressed() and sliderRelased() of horizontalScrollBar and verticalScrollBar() should do the trick), you need to hide QScrollArea: