C++26: A Giant Leap for Compile-Time Standard Library Features

2025-05-01

C++26 is set to revolutionize compile-time programming with a massive boost to constexpr support in the standard library. Several proposals (P2562R1, P1383R2, P3074R7, P3372R2, P3508R0, P3369R0) bring stable sorting algorithms, and functions, improved union rules, nearly all containers and adaptors, and specialized memory algorithms into the constexpr fold. This significantly enhances compile-time capabilities, allowing, for example, compile-time sorting of constexpr containers. While std::hive and std::hash remain excluded due to limitations, C++26 promises a dramatic expansion of compile-time programming possibilities.

Read more
Development standard library

C++26: A Giant Leap for constexpr

2025-04-23

C++26 is set to revolutionize constexpr! Upcoming features include constexpr casts from void*, enabling more flexible compile-time memory manipulation; constexpr placement new, allowing object placement within constant expressions; and constexpr structured bindings, bringing compile-time structured binding. These improvements drastically expand constexpr's reach and empower the standard library with significantly enhanced compile-time capabilities.

Read more

C++20 Ranges Performance: A Surprise Twist

2025-04-19

The author replaced a raw loop with `std::ranges::transform` in a C++ project, expecting a performance boost. Tests revealed a surprising result: an optimized raw loop (using `emplace_back` and `reserve`) proved 20% faster on Clang and 10% faster on GCC. The article compares different approaches, highlighting performance and code readability. The conclusion: prioritize readability unless performance is a critical bottleneck.

Read more
Development

C++26: Removed and Deprecated Features Roundup

2025-03-20

C++26 is removing or deprecating several features. These include the complete removal of the `std::allocator` typedef deprecated in C++20, and the no-argument overload of `std::basic_string::reserve()`; removal of deprecated Unicode conversion utilities and `std::strtok`; removal of aged `strstreams` and `std::shared_ptr` atomic access APIs; and removal of `std::wstring_convert`. Additionally, `std::is_trivial` is deprecated, with suggestions to use the more precise `is_trivially_XXX` alternatives; and `std::memory_order::consume` is deprecated due to unsatisfactory specification and implementation difficulties. These removals and deprecations aim to improve language safety and efficiency, and clean up outdated functionality.

Read more

C++26: Pack Indexing Simplifies Element Extraction

2025-01-24

While C++11 introduced parameter packs, extracting specific elements remained cumbersome. C++26, thanks to proposal P2662R3, introduces pack indexing, allowing direct access to pack elements using the subscript operator, e.g., `T...[0]` for the first element. This leads to cleaner, more readable code and improved compile-time performance. Although negative indexing and slicing aren't yet supported, the feature is already highly usable, significantly improving C++ development.

Read more

C++26: The Unnamed Placeholder `_` Arrives

2025-01-11

C++26 introduces a game-changing feature: the unnamed placeholder `_`. This solves a long-standing annoyance in C++: handling unused variables. Previously, developers needed `[[maybe_unused]]` or `std::ignore` to avoid compiler warnings, especially with structured bindings. The `_` placeholder can be declared multiple times without conflict and implicitly has the `[[maybe_unused]]` attribute, simplifying code and improving readability. This feature is already implemented in GCC 14 and Clang 18.

Read more