Articles & Books

Stop with the CTAD FUD!--Colby Pike

It's not cool.

Stop with the CTAD FUD!

by Colby Pike

From the article:

Among the catalog of features introduced by C++17, you’ll find a feature known as Class Template Argument Deduction, often shortened to “CTAD”. It was one of the largest language changes in C++17, and with it comes a new syntax and a new set of rules to understand.

It’s still very early in the game for CTAD, but we’re already seeing many strong opinions about it without seeing its widespread effect on codebases. In particular, we’re seeing a lot of Fear, Uncertainty, and Doubt about CTAD...

Deducing your intentions--Andrzej Krzemieński

Were you aware?

Deducing your intentions

by Andrzej Krzemieński

From the article:

The language feature in C++17 known as class template argument deduction was intended to supersede factory functions like make_pair, make_tuple, make_optional, as described in p0091r2. This goal has not been fully achieved and we may still need to stick to make_ functions. In this post we will briefly describe what class template argument deduction is, and why it works differently than what people often expect...

Standard Ranges--Eric Niebler

Coming soon.

Standard Ranges

by Eric Niebler

From the article:

As you may have heard by now, Ranges got merged and will be part of C++20. This is huge news and represents probably the biggest shift the Standard Library has seen since it was first standardized way back in 1998.

This has been a long time coming. Personally, I’ve been working toward this since at least November 2013, when I opined, “In my opinion, it’s time for a range library for the modern world,” in a blog post on input ranges. Since then, I’ve been busy building that modern range library and nailing down its specification with the help of some very talented people.

Future blog posts will discuss how we got here and the gritty details of how the old stuff and the new stuff play together (we’re C++ programmers, we love gritty details), but this post is strictly about the what...

span: the best span--Barry Revzin

An answer.

span: the best span

by Barry Revzin

From the article:

This post is a response to RangeOf: A better span, which has many problems worth addressing in detail. While most of this post will deal with specifically std::span<T> (which is indeed the best span), the last section will also discuss a recent addition to the standard library: std::ranges::subrange<T*>...

SG20 Education and Recommended Videos for Teaching C++ -- Christopher Di Bella

In today’s blog, we look at both the newly minted Study Group for education in the C++ Standard Committee. We also look at a small number of conference videos that I recommend teachers consider while they’re waiting for this Study Group to produce usable materials.

SG20 Education and Recommended Videos for Teaching C++

by Christopher Di Bella

From the article:

As articulated in P1231, the goal of SG20 is not to provide normative curricula for teaching C++, but rather to provide teaching and curriculum guidelines.

...

Below are a list of conference videos that I’ve compiled for teachers to watch (and will update if recommendations come in). There’s well over a day’s worth of videos below, but these aren’t a random assortment of my favourite conference videos. Rather, they are sessions that communicate values about:

  • teaching people how to write programs using C++, or
  • writing C++ programs using approaches the community agrees produce better code.

An Extraterrestrial Guide to C++ Formatting--Victor Zverovich

The future of now.

An Extraterrestrial Guide to C++ Formatting

by Victor Zverovich

From the article:

Consider the following use case: you are developing the Enteropia[2]-first Sepulka[3]-as-a-Service (SaaS) platform and have a server code written in C++ that checks the value of sepulka’s squishiness received over the wire and, if the value is invalid, logs it and returns an error to the client. Squishiness is passed as a single byte and you want to format it as a 2-digit hexadecimal integer, because that is, of course, the Ardrite[1] National Standards Institute (ANSI) standard representation of squishiness. Let’s implement the logging part using different formatting facilities provided by C++...

Quick Q: Is it useful to pass std::weak_ptr to functions?

Quick A: yes

Recently on SO:

Is it useful to pass std::weak_ptr to functions?

Consider this toy example.

struct PointerObserver
{
    std::weak_ptr<int> held_pointer;

    void observe( std::weak_ptr<int> p )
    {
        held_pointer = std::move(p);
    }

    void report() const
    {
        if ( auto sp = held_pointer.lock() )
        {
            std::cout << "Pointer points to " << *sp << "\n";
        }
        else
        {
            std::cout << "Pointer has expired.\n";
        }
    }
};

In this example, a function observe holds state.

Its weak_ptr parameter communicates that this smart pointer is not owning, but reserves the ability to own at a later time, safely detecting if the pointer has expired.