intermediate

Quick Q: Is std::unique_ptr required to know the full definition of T?

Quick A: For certain members only.

Recently on SO:

Is std::unique_ptr<T> required to know the full definition of T?

Most templates in the C++ standard library require that they be instantiated with complete types. However shared_ptr and unique_ptr are partial exceptions. Some, but not all of their members can be instantiated with incomplete types. The motivation for this is to support idioms such as pimpl using smart pointers, and without risking undefined behavior...

Refactoring from single to multi purpose

Working on an old project, it came to my mind that I do this refactoring from one static path to multiple options for the 2nd time this year...

Refactoring from single to multi purpose

by Jens Weller

From the article:

For the second time this year I'm refactoring a program from a single purpose to have two or more modes of operation. Both times the start and end result is similar, just the processing is different. A classic case of using polymorphism.

The first program was a tool to process videos from speakers, find a face and export the subframe around it into a new video. The first mode was a good approach to test it, and gave results for some speakers. The second mode did a complete scan first, and then gave a smoother video for some videos. Still, both modes had to be retained...

Announcing Meeting C++ Trainings!

Meeting C++ Trainings - a site for online trainings launched on Monday:

Announcing the start of Meeting C++ Trainings

by Jens Weller

From the article:

Meeting C++ organizes now its own online trainings, learn C++ from the leading experts!

You can choose trainings from several trainers and participate in the training you need online. Both half day and full day trainings are available. Right now the listed trainings start by mid June and go into July, but soon also Trainings in August and September will be available. My goal is to offer 1-2 Trainings per trainer in one quarter...

Nifty Fold Expression Tricks--Jonathan Müller

Many things can be done!

Nifty Fold Expression Tricks

by Jonathan Müller

From the article:

Suppose you need to have a variadic function and want to add all arguments together. Before C++17, you need two pseudo-recursive functions:

template <typename H, typename ... T>
auto add(H head, T... tail)
{
    return head + add(tail...);
}

template <typename H>
auto add(H head)
{
    return head;
}

However, C++17 added fold expressions, making it a one-liner:

template <typename H, typename ... T>
auto add(H head, T... tail)
{
    return (head + ... + tail);
    // expands to: head + tail[0] + tail[1] + ...
}

If we’re willing to abuse operator evaluation rules and fold expressions, we can do a lot more. This blog posts collects useful tricks...