Blog

On forcing all derived classes to implement a specific non-virtual method, part 2 -- Raymond Chen

RaymondChen_5in-150x150.jpg

Building on the previous article, Raymond Chen explores how deleted functions can produce clearer compiler errors when derived classes fail to implement required non-virtual methods. He also examines C++26’s new custom diagnostic messages for deleted functions, their compiler support, and why this technique works in C++/WinRT but not C++/WRL.

On forcing all derived classes to implement a specific non-virtual method, part 2

by Raymond Chen

From the article:

Last time, we observed that one way to force all derived classes to implement a specific non-virtual method is simply not to implement it in the base class and sit back and wait for the compile-time fireworks. I noted that we can do better than this, though.

The problem is that the compiler tells you what is wrong, but the details are often buried in the “supplementary error information”, and it may not be obvious how to dig it out, or maybe you dig it out but you don’t understand how to fix it.

You can steer people to the correct error by implementing the method as deleted.

// C++/WRL

struct OneWayConverter
{
    // Derived classes must implement Convert()
    HRESULT STDMETHODCALLTYPE Convert(IInspectable* value,
        ABI::Windows::UI::Xaml::Interop::TypeName targetType,
        IInspectable* parameter, HSTRING language,
        IInspectable** result) = delete;

    // One-way converters cannot convert back
    HRESULT STDMETHODCALLTYPE ConvertBack(IInspectable* /*value*/,
        ABI::Windows::UI::Xaml::Interop::TypeName /*targetType*/,
        IInspectable* /*parameter*/, HSTRING /*language*/,
        IInspectable** result)
    {
        *result = nullptr;
        return E_NOTIMPL;
    }
};

// C++/WinRT

struct OneWayConverter
{
    // Derived classes must implement Convert()
    winrt::Windows::Foundation::IInspectable
        Convert(
            winrt::Windows::Foundation::IInspectable const& /*value*/,
            winrt::Windows::UI::Xaml::Interop::TypeName const& /*targetType*/,
            winrt::Windows::Foundation::IInspectable const& /*parameter*/,
            winrt::hstring const& /*language*/) = delete;

    // One-way converters cannot convert back
    winrt::Windows::Foundation::IInspectable
        ConvertBack(
            winrt::Windows::Foundation::IInspectable const& /*value*/,
            winrt::Windows::UI::Xaml::Interop::TypeName const& /*targetType*/,
            winrt::Windows::Foundation::IInspectable const& /*parameter*/,
            winrt::hstring const& /*language*/)
    {
        throw winrt::hresult_not_implemented();
    }
};

// Plain C++ analogous scenario

struct OneWayConverter
{
    // Derived classes must implement Convert()
    Color Convert(Widget const&amp /*value*/) = delete;

    // One-way converters cannot convert back
    Widget ConvertBack(Color const& /*color*/)
    {
        throw std::exception("not implemented");
    }
};

This has a few benefits.

 

On forcing all derived classes to implement a specific non-virtual method, part 1 -- Raymond Chen

RaymondChen_5in-150x150.jpgHow can you ensure a derived C++ class implements a required method without relying on comments or runtime assertions? This article explores a simpler approach—leaving the method unimplemented in the base class—and demonstrates how C++/WRL, C++/WinRT, and plain C++ catch missing implementations at compile time.

On forcing all derived classes to implement a specific non-virtual method, part 1

by Raymond Chen

From the article:

You may have a base class that implements only partial functionality and relies on the derived class to do the rest. How do you make sure that the derived class does the rest?

For concreteness, let’s say that we are implementing IValueConverter, which has two methods:

  • Convert() to convert from the source to the destination.
  • ConvertBack() so that two-way conversions can convert from the destination to the source.

Suppose you want to write a base class called OneWayConverter. Its implementation fails the ConvertBack() call, and you want to force the derived class to implement the forward conversion.

// C++/WRL

struct WidgetColorConverter :
    Microsoft::WRL::RuntimeClass<
        Microsoft::WRL::RuntimeClassFlags<Microsoft::WRL::WinRt>,
        ABI::Windows::UI::Xaml::Data::IValueConverter>,
    OneWayConverter
{
    // Require the derived class to implement Convert somehow
    HRESULT STDMETHODCALLTYPE Convert(IInspectable* value,
        ABI::Windows::UI::Xaml::Interop::TypeName targetType,
        IInspectable* parameter, HSTRING language,
        IInspectable** result)
    {
        ⟦ ... ⟧
    }
};

// C++/WinRT

struct WidgetColorConverter :
    winrt::implements<WidgetColorConverter>, OneWayConverter
{
    // Require the derived class to implement Convert somehow
    winrt::Windows::Foundation::IInspectable
        Convert(
            winrt::Windows::Foundation::IInspectable const& value,
            winrt::Windows::UI::Xaml::Interop::TypeName const& targetType,
            winrt::Windows::Foundation::IInspectable const& parameter,
            winrt::hstring const& language)
    {
        ⟦ ... ⟧
    }
}

// Plain C++ analogous scenario
struct WidgetColorConverter : OneWayConverter
{
    // Require the derived class to implement Convert somehow
    Color Convert(Widget const&amp value)
    {
        ⟦ ... ⟧
    }
};

Welcome Hudson River Trading as a Gold Sponsor of the Standard C++ Foundation

04_HRT_Stacked_Combo_-_Positive_with_®_-_Q2_2024.pngThe Standard C++ Foundation is pleased to welcome Hudson River Trading (HRT) as our newest Gold Sponsor!

HRT is a global quantitative trading firm that combines advanced mathematics, technology, and high-performance software - including C++ - to develop sophisticated automated trading systems.

The Foundation works to support the development, adoption, and ongoing evolution of the C++ programming language. Our sponsors play an important role in making this work possible and strengthening the global C++ community.

We appreciate HRT's commitment to the future of C++ and are grateful for their support.

Thank you, Hudson River Trading, for joining us!

See the organizations supporting the Standard C++ Foundation at https://isocpp.org/about and learn more about Hudson River Trading.

C++26: std::inplace_vector -- Sandor Dargo

SANDOR_DARGO_ROUND.JPGC++26 introduces std::inplace_vector, a new container that combines the flexibility of std::vector with fixed-capacity, inline storage that requires no dynamic allocation. This article explores its API, overflow-handling options, performance considerations, and how it compares with existing standard library containers.

C++26: std::inplace_vector

by Sandor Dargo

From the article:

C++26 is generous with new containers — we’re getting both std::hive and std::inplace_vector. In this post, we’ll look at the latter.

Until C++26, the standard library had no vector-like container with compile-time fixed capacity whose element storage is guaranteed to live inside the container object itself. std::vector obtains storage through its allocator — typically the heap. std::array has a fixed size. If you need a dynamically-resizable array that never allocates — because you’re on bare metal, because allocation latency is unacceptable, or because you need the data to live inside the object for serialization — there was no standard answer.

C++26 adds std::inplace_vector<T, N> in the new <inplace_vector> header, originally introduced by P0843R14 and subsequently refined by later C++26 papers (P3981R2, P4022R0, P3074R7). It’s essentially boost::static_vector standardized: a vector-like container with a compile-time fixed capacity N, where all elements are stored inline within the object itself.

Meeting C++ 2026 is next week!

You still can join next weeks Meeting C++ conference by getting a ticket for online or onsite!

Meeting C++ 2026 is next week

by Jens Weller

From the page:

This years Meeting C++ is a hybrid event in Berlin and online on 26th - 28th November 2026.

The conference will be again hybrid - just like last year, attendees will join us on location in Berlin, but the conference will be also featuring online and onsite only content.

 

simdjson 5.0 with full C++26 reflection support -- Daniel Lemire

simdjson5-cover-825x510.jpgStatic reflection is no longer guarded and is an officially supported feature. When your compiler has reflection enabled (e.g., g++ -std=c++26 -freflection with GCC 16), simdjson detects it by itself and the reflection-based functions become available.

simdjson 5.0 with full C++26 reflection support

by Daniel Lemire

From the article:

The simdjson library is a C++ library to parse and generate JSON. It is used in Node.js, ClickHouse, Meta Velox, StarRocks, Apache Doris, the Ladybird browser and many other systems. We released version 4.0 a year ago, in September 2025. Its headline feature was C++26 static reflection: you could turn a C++ structure into JSON, and back, without writing any glue code.

Today we are releasing version 5.0.

We added annotations for the data structures for automated (C++26) serialization and deserialization: rename, rename_all, alias, skip, default_value, flatten, deny_unknown_fields, transparent, and so forth.

struct [[= simdjson::rename_all<simdjson::case_style::camel_case>]] User {
std::string first_name;
int64_t user_id;
[[= simdjson::rename<"KEY">]] int api_key;
};
// {"firstName":"Ann","userId":7,"KEY":8}

 

C++26: std::constant_wrapper -- Sandor Dargo

SANDOR_DARGO_ROUND.JPGC++26 introduces std::constant_wrapper and its shorthand std::cw, offering a more convenient way to preserve compile-time values across function boundaries. From simplifying template arguments to supporting compile-time arithmetic and function calls, this new utility makes constant expressions easier to work with and compose.

C++26: std::constant_wrapper

by Sandor Dargo

From the article:

There’s a fundamental gap in C++ that trips up everyone who reaches for it: you can’t pass a constexpr value through a function boundary and have it remain constexpr on the other side. The value is known at compile time, the function is constexpr, but the parameter inside the function body is not a constant expression. This forces workarounds - template parameters, tag types, std::integral_constant - all of which are verbose and limited.

C++26 adds std::constant_wrapper (P2781R9 by Hana Dusíková, Matthias Kretz, Zach Laine; refined by P3978R3 by Kretz, Kamiński) and its shorthand std::cw<V> to close this gap. It wraps any structural type — not just integers — in a type that carries the value as a non-type template parameter, preserving its compile-time nature across function calls.

Microsoft CppCon 2026 Trip Report -- Michael Price

mstripreport-cpp26.pngCppCon 2026 is a wrap! Microsoft returned to Aurora, Colorado, for a week of talks, technical discussions, and conversations with developers from across the C++ community.

Microsoft CppCon 2026 Trip Report

by Michael Price

From the article:

At our booth, we met people building games, financial systems, developer tools, embedded software, scientific tools, and other applications. Some were working with the latest language features, and others were maintaining and modernizing systems that have been in production for decades. Many talked to us about debugging, performance, build systems, or modern C++, and a growing number were experimenting with ways AI can help them accomplish their goals in the most effective way possible.

Attendees who completed our annual Microsoft C++ survey were entered for our daily LEGO raffle. This year’s prizes included some great LEGO sets; a retro gaming console, a retro camera, a mini orchid, and a model of the Milky Way galaxy.

 

Trip report: CppCon 2026 -- Sandor Dargo

cppcon-2026-muc-airport-alex-and-me.jpg

Last year I wrote that a dream came true by attending and speaking at CppCon. And here I was again! Someone is living the dream, apparently.

Trip report: CppCon 2026

by Sandor Dargo

From the article:

Last year I wrote that a dream came true by attending and speaking at CppCon. And here I was again! Someone is living the dream, apparently.

21 LinkedIn posts shared, 24 sessions attended, 3 talks given.

Those are just numbers, though. The human connections are what make a conference special, and CppCon being the largest C++ conference, there is no shortage. If you just want to wind down with a hot cup of coffee, good luck — someone you’ve been meaning to talk to will inevitably pop up next to you.

I didn’t even have to reach the venue to start catching up with old friends. I planned to work during my layover at the Munich airport, but as I approached a table I bumped into a fellow presenter, Alex Dathskovsky. We ended up taking the same flight to Denver — so much for my productivity plans.