Quick Q: Why doesn’t std::queue::pop return value?

Quick A: To guarantee exception safety and for performance.

Some time ago on SO:

Why doesn't std::queue::pop return value?

So, whats the difference, pop function could have done the same thing.

It could indeed have done the same thing. The reason it didn't, is because a pop that returned the popped element is unsafe in the presence of exceptions (having to return by value and thus creating a copy).

Consider this scenario (with a naive/made up pop implementation, to ilustrate my point):

template<class T>
class queue {
    T* elements;
    std::size_t top_position;
    // stuff here
    T pop()
    {
        auto x = elements[top_position];
        // TODO: call destructor for elements[top_position] here
        --top_position;  // alter queue state here
        return x;        // calls T(const T&) which may throw
    }

If the copy constructor of T throws on return, you have already altered the state of the queue (top_position in my naive implementation) and the element is removed from the queue (and not returned). For all intents and purposes (no matter how you catch the exception in client code) the element at the top of the queue is lost.

This implementation is also inefficient in the case when you do not need the popped value (i.e. it creates a copy of the element that nobody will use).

This can be implemented safely and efficiently, with two separate operations (void pop and const T& front()).

CppCon 2015 Modern User Interfaces for C++—Milian Wolff

Have you registered for CppCon 2016 in September? Don’t delay – Early Bird registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2015 for you to enjoy. Here is today’s feature:

Modern User Interfaces for C++

by Milian Wolff

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

The C++ language evolved significantly in the recent past, and so did many frameworks and libraries in the big ecosystem surrounding it.

For twenty years now, Qt is being used on a multitude of platforms to create native looking, compelling graphical user interfaces.

It offers C++ libraries and tools for building desktop, mobile and embedded applications. Qt gives engineers APIs for developing using two dimensional controls, integrating 3D using OpenGL, embedding web content, as well as a new declarative domain-specific language called QML, which is extensible using C++. Qt is also much more than a UI toolkit and provides a multitude of helper libraries for various use-cases, such as localization, database access, XML and JSON parsing and much more.

During this talk, I will give an introduction to Qt and present its capabilities in how it can be utilized to write modern UIs using C++, both in 2D as well as 3D. Additionally, I will show how some of its features, like the integrated web engine or QML, can be leveraged to go beyond C++. While at it, I hope to clear up some outdated misconceptions about Qt and its relationship to standard C++ and the STL as well as Boost and other libraries.

Finally, I will present the KDE Frameworks, an open source collection of high quality, cross platform Qt libraries that are being used by the KDE Software Collection. KDE frameworks are to Qt as Boost is to the STL. Recent development makes it simpler than ever to use these libraries in external applications.

CppCon Early Bird registration closes on Friday

cppcon-082.PNGThis is it! Four days left -- CppCon 2016 Early Bird registration closes on Friday.

As a warmup, the optional pre-conference classes run Saturday and Sunday, and then CppCon 2016 Week kicks off on Monday morning with an opening keynote by Bjarne Stroustrup on the latest in the C++ world, followed by more than 100 of the best C++ talks of 2016, lightning talks, panels, exhibitors where you can try live products and find one-on-one helpdesks to get popular C++ compilers' developers to help you with your questions, and more.

And of course, a full week of around-the-clock interaction with fellow attendees from across industries and disciplines, making CppCon the best learning and networking opportunity for C++ developers in a relaxed and inviting festival atmosphere.

To see what others have had to say about CppCon, check out the attendee video, featuring a soundtrack of original music written and performed by the CppCon house band. And check out the video archive of 2014 and 2015 talks on YouTube and on Channel 9.

CppCon is "the" C++ event of the year. Early Bird registration closes on Friday. If you haven't registered yet, register today!

How to Convince Your Boss to Send You to CPPCon (at company expense!)

The CPPcon conference is tremendously educational and interesting. The venue in Bellevue Washington is very, very nice and agreeable.  Attendees get to rub elbows with well known people in the business.  For  A C++ programmer to be standing in the registration queue next to Bjarne Stroustrup, Sean Parent, (or myself -- lol) is actually a physical thrill -- like meeting a rock star. Add in emotional disputes about arcane topics that no one else understands, good music, good beer, free snacks and coffee it's better than a vacation -- which is basically is -- and paid by the company without impacting your wife's vacation time. It might even enhance your career! And's all free because the company is paying for it!

But course you can't you can't get all these benefits unless you can get your company to send you!  So here's my suggestion on how to get you company to pay for it. 

  • Don't spend too much time on the above explanation of what the conference is really like.
  • Promise to post each evening a report on the sessions you've attended and your review of them.  At least some of the sessions you've attended will be relevant to issues currently confronting your team.  Such an internal posting will permit your team members to ask more questions while you've still got access to the other conference attendees and speakers.  This could spark new ideas on making better/faster progress on your products. 
  • Pitch conference as a place to send people to get new ideas useful in solving the companies or boss's problems. Of course this presumes that a) your company actually has problems and b) that people realise this.
  • You'll be able to "scout" content that is particularly relevant to you current challenges. Since all the content is later available on video, other team members and the company will benefit from it with out having to wade through hours other stuff.  So your team mates will be able to watch video on company time! This will somewhat ameliorate the resent they'll have about you going the conference while they stay at the office lashed to the hamster wheel.

Hope this works for you and hope to see a record turnout.

CppCast Episode 61: Oulu Trip Report with Herb Sutter

Episode 61 of CppCast the only podcast for C++ developers by C++ developers. In this episode Rob and Jason are joined by Herb Sutter, chair of the ISO C++ standards committee, to discuss the latest progress on C++17 made at the Oulu ISO Standards meeting.

CppCast Episode 61: Oulu Trip Report with Herb Sutter

by Rob Irving and Jason Turner

About the interviewee:

Herb Sutter is a leading authority on software development. He is the best selling author of several books including Exceptional C++ and C++ Coding Standards, as well as hundreds of technical papers and articles, including the essay “The Free Lunch Is Over” which coined the term “concurrency revolution” and its recent sequel “Welcome to the Jungle” on the end of Moore’s Law and the turn to mainstream heterogeneous supercomputing from the cloud to ‘smartphones.’

Herb has served for a decade as chair of the ISO C++ standards committee, and is a software architect at Microsoft where he has led the language extensions design of C++/CLI, C++/CX, C++ AMP, and other technologies.

CppCon 2015 Executors for C++ - A Long Story ...—Detlef Vollmann

Have you registered for CppCon 2016 in September? Don’t delay – Early Bird registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2015 for you to enjoy. Here is today’s feature:

Executors for C++ - A Long Story ...

by Detlef Vollmann

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

Executors will be a base building block in C++ for asynchronous, concurrent and parallel work. The job of an executor is simple: run the tasks that are posted. So the first proposals for executors in C++ had a very simple interface. However, being a building block, the executor should provide an interface that's useful for all kind of higher level abstractions and needs to work together with different types of concurrency, like co-operative multi-tasking or GPU like hardware. This presentation will look at the evolution of the executor proposals for C++ and what they'll provide for normal application programmers.

NDC Oslo 2016 Videos are online

The recordings from the this years NDC Oslo are online.

NDC 2016 Oslo

These are the videos with C++ content:

Andrei Alexandrescu: Fastware

Andrei Alexandrescu: Generic Locking in C++

Anthony Williams: The Continuing Future of the C++ Concurrency

Anthony Williams: Safety: off - How not to shoot yourself into the foot with C++ atomics

Dan Saks: Measuring Instead of Speculating in C and C++

Dan Saks: Using the C++ STL Without Dynamic Memory

Detlef Vollmann: New Executors for C++

Detlef Vollmann: Parallelism vs. Concurrency in C++

Hubert Matthews: The C++ Type System is your Friend

Mark Isaacson: Developing Correct C++ @ Scale

Mark Isaacson: Exploring C++17 and beyond

Sasha Goldshtein: Introduction to C++ Template Metaprogramming

Sasha Goldshtein: The C++ and CLR Memory Models

 

 

CppCon 2015 Doxygen to DoxyPress: A Journey from C++98 to C++11—Barbara Geller & Ansel Sermersheim

Have you registered for CppCon 2016 in September? Don’t delay – Early Bird registration is open now.

While we wait for this year’s event, we’re featuring videos of some of the 100+ talks from CppCon 2015 for you to enjoy. Here is today’s feature:

Doxygen to DoxyPress: A Journey from C++98 to C++11

by Barbara Geller & Ansel Sermersheim

(watch on YouTube) (watch on Channel 9)

Summary of the talk:

This presentation will discuss the benefits of using a documentation generator for creating internal code documentation or end user documentation. DoxyPress can be used to document your source code, generate API documentation, show class hierarchies, collaboration diagrams, and much more. DoxyPress supports several output formats including html, chm, latex, and man pages.

As part of our talk we will cover the process of redesigning source code originally designed for C++98 and how to migrate it to C++11. We will talk about the advantages and drawbacks of moving to C++11 and show how the code changed in DoxyPress.

We will show a small demonstration of DoxyPressApp, which is a a GUI program used to set up your project file which is then used by DoxyPress to generate documentation.

DoxyPress is a fork of the Doxygen documentation tool. A very basic understanding of C++ will be helpful. No prior knowledge of DoxyPress or Doxygen is required.