72 questions
9
votes
1
answer
615
views
std::equal_to<void>{}(A1, B1) does not compile, while A1 == B1 compiles in C++26 for unscoped enums?
I noticed a discrepancy between C++23 and C++26 code when using googlemock:
enum A { A1, A2 };
enum B { B1, B2 };
TEST(...)
{
ASSERT_EQ(A1, B1); // compiles fine in C++23 and C++26
ASSERT_THAT(...
Best practices
3
votes
4
replies
146
views
Will std::is_trivially_copyable_v be deprecated by std::is_trivially_relocatable_v since C++26?
The main use of std::is_trivially_copyable_v[1] is to determine if an object array copy/move can be safely and efficiently replaced by std::memcpy.
However, C++26 introduces std::...
9
votes
1
answer
915
views
Is there any way to iterate data members with STL algorithms using the C++26 reflection?
With C++26 reflection, we can simply iterate all data members of an object:
#include <iostream>
#include <meta>
struct Foo {
int x;
int y;
};
void PrintFoo(const Foo& foo) {
...
Advice
0
votes
7
replies
334
views
Dynamic list of type at compile time
I'm looking for a way to store type "dynamicly" in a using (or concret implementation) that would be modifable and accessible at compile-time.
I would like something like:
struct ...
Advice
5
votes
2
replies
5k
views
Is C++26 getting destructive move semantics?
Can I express a function that consumes an object? Meaning that its destructor is not run on the moved-from object?
Like the proposed library function trivially_locate_at itself?
template <class T&...
3
votes
1
answer
130
views
Why can’t I efficiently move-construct `std::polymorphic<Base>` from `std::polymorphic<Derived>`?
As I understand it, std::polymorphic<T> and std::indirect<T> are const-propagating wrapper types for an owning pointer to a T object, where the target of the pointer is copied with the ...
10
votes
1
answer
244
views
Cannot use std::not_fn with immediate functions
I try to apply std::not_fn wrapper to an immediate consteval function.
But even the simplest C++20 example
#include <functional>
consteval bool f() { return false; }
// ok in GCC and Clang, ...
3
votes
2
answers
225
views
How can I emulate C++26 erroneous behaviour in earlier versions of C++?
C++26 introduces "erroneous behaviour" for uninitialised data, and introduces the [[indeterminate]] attribute for locals to restore the pre-C++26 behaviour as needed. I want to get ...
7
votes
1
answer
175
views
Can contract violations result in std::terminate on noexcept functions?
I have some code in the following style:
struct S {
private:
T* resource;
public:
S(T* r) : resource{r} {
if (r == nullptr) {
throw std::invalid_argument(":("...
4
votes
2
answers
183
views
Why is `iterator_category` deleted in `std::views::concat::iterator` if it's a pure input iterator?
In the C++26-adopted proposal p2542, i.e. std::views::concat, there is a confusing statement:
The member typedef-name iterator_category is defined if and only if all-forward<Const, Views...> is ...
1
vote
0
answers
197
views
Why can a trivially relocatable type not be an implicit lifetime type?
Consider the following code:
#include <type_traits>
struct A trivially_relocatable_if_eligible final {
A() {}
A(A const&) = delete;
A& operator=(A const&) = ...
4
votes
1
answer
166
views
Why no cleanup if a contract precondition fails?
C++26 will introduce function contract specifiers, which are contract assertions associated with a function to express and check that function's pre- and post- conditions.
If enforced, contract ...
1
vote
0
answers
98
views
Compiling C++26 on Windows 11 with g++ 15.1.0 [duplicate]
So I want to compile a c++26 program using g++ version 15.1.0 on Windows 11.
I installed the new version of the GNU compilers replacing version 13 that I had previously because that version couldn't ...
4
votes
0
answers
111
views
std::execution vs std::async [duplicate]
After going to their documentation, I realized std::execution and std::async in C++ represent different approaches to managing and expressing concurrency and parallelism.
std::async is a function ...
0
votes
1
answer
197
views
Do we really need std::start_lifetime_as if a well-defined alternative already exists?
Consider the code example excerpted from cppref:
#include <complex>
#include <iostream>
#include <memory>
int main() {
alignas(std::complex<float>) unsigned char buf[...
50
votes
1
answer
5k
views
What is `template for` in C++26?
I've seen a lot of examples for Reflection in C++26 that use a new kind of loop that I've never seen before like
template for (constexpr auto e : std::meta::enumerators_of(^^E)) {
What is template ...
6
votes
1
answer
348
views
How does `template for` iteration work in C++26? [duplicate]
I'm experimenting with the new C++ compile-time reflection features (as described in P2996R0) and I testing a simple enum_to_string() utility using template for:
template <typename E>
requires ...
3
votes
0
answers
167
views
Why does C++26 still not allow passing a function template as a template parameter?
In C++26, the following code is legal (see p2841r7 and Herb Sutter's article):
template<typename<typename> concept C, template<typename> auto vt, typename T>
requires C<T>
auto ...
4
votes
1
answer
218
views
Can reflection statements be directly used in if-constexpr?
Below example is taken from P2996 verbatim:
#include <experimental/meta>
#include <string>
#include <type_traits>
#include <print>
template<typename E, bool Enumerable = ...
6
votes
1
answer
231
views
Why is std::function_ref(F*) not constexpr, while other ctors are all constexpr?
At the cppref page of std::function_ref, I found an inconsistency issue:
The copy constructor is defined as:
std::function_ref(std::function_ref const&) = default;
while the copy assignment ...
5
votes
1
answer
210
views
Are structured binding packs allowed in expansion statements outside of template?
Recently, expansion statements have been accepted to C++26 draft. Which means, this gives us another way of iterating through members of destructurable types such as "Point" defined below.
...
1
vote
1
answer
218
views
Using C++26 reflection's to inject a struct's name into another struct?
To better understand C++26's reflection, I would like to understand how we can reflect on the name of a struct to inject it in another one (potentially replacing its body, just keeping the name)
For ...
4
votes
1
answer
220
views
Using C++ reflection to automatically generate arithmetic operators?
As the reflection proposal just got accepted into the C++26 draft, I am wondering if the expected facilities could be used to automatically generate several arithmetic operators for a class?
For ...
3
votes
3
answers
261
views
Does trivially copyable imply trivially relocatable?
C++26 will introduce std::is_trivially_relocatable_v, and the proposal author states: Trivially copyable implies trivially relocatable.
However, I think the statement might not always be true, ...
2
votes
1
answer
122
views
Why do we keep a redundant ctor in std::copyable_function?
According to the C++ docs, std::copyable_function has two overloaded ctors as follows:
template<class T, class... CArgs>
explicit copyable_function(std::in_place_type_t<T>,
CArgs&&...
3
votes
1
answer
197
views
Why does std::function_ref allow passing in an expiring functor, rather than disallow it?
At https://en.cppreference.com/w/cpp/utility/functional/function_ref/function_ref.html, there is an overloaded ctor as follows:
template<class F>
function_ref(F&& f) noexcept;
...
6
votes
1
answer
330
views
What does "hardened" and "not hardened" mean for std::vector::back() in C++26?
When trying to access the last item of an empty std::vector using the back() method, it's undefined behaviour as per the current C++ standard.
But, I just now saw on the cppreference documentation for ...
3
votes
1
answer
253
views
Differences between std::function_ref and delegates
What are the differences between the new std::function_ref, that was added to C++26, and a "delegate"? Are they the same?
By "delegate" I mean:
A type that has sizeof(...) == 16.
...
3
votes
0
answers
149
views
Text encoding on Windows in C++
I updated GCC to the recently released version 15.1 (via Msys2, on Windows 10).
On cppreference, I noticed the page regarding the <text_encoding> header, which should be supported by GCC version ...
10
votes
1
answer
3k
views
std::hive container in the upcoming c++ standard
It seems C++26 will introduce a new container called std::hive, but there is no documentation of it yet. Can somebody explain what kind of data collection is this new container?
std::hive
13
votes
0
answers
379
views
Why is this C++ code with fold expanded constraints rejected by Clang trunk?
#include <type_traits>
template <class T>
concept floating_point = std::is_floating_point_v<T>;
template <class T>
concept integral = std::is_integral_v<T>;
template &...
6
votes
2
answers
205
views
Why does Clang 20.1.2 with C++26 fail to find a derived class method when using explicit object parameters as a CRTP replacement?
I'm trying to use C++23's explicit object parameters (as introduced in P0847R7, "Deducing this") to replace the Curiously Recurring Template Pattern (CRTP) for a simple inheritance hierarchy,...
21
votes
2
answers
1k
views
Why does std::views::take_while() do so many function invocations? (even with `cache_latest`)
I decided to use std::views stuff because of their bound-safety and readability. It looks like std::views::take_while invokes too many function calls and recomputes the same thing over and over again. ...
7
votes
0
answers
303
views
What is the purpose/semantics of P2786 is_replaceable?
The C++ working draft now has [EDIT: as of November 2025 it's removed again! But I'll leave this question open until 2026-ish just for historical interest] a definition of replaceable type (...
7
votes
0
answers
318
views
Is there a compelling reason to use "old" RNGs instead of std::philox_engine?
P2075R6 has been accepted into the C++26 standard.
It provides the std::philox_engine class template, and the std::philox4x32 and std::philox4x64 aliases with reasonable constants.
The proposal ...
25
votes
3
answers
1k
views
Why are polymorphic objects not trivially relocatable?
Throughout the battle of P1144 vs P2786 to introduce trivial relocation optimisation for C++, one of the points P1144 has raised against P2786 is that polymorphic objects should not be trivially ...
5
votes
2
answers
149
views
Checking noexceptness when applying function to a pack
I have the following C++26 function which runs some code for each field of a structure:
template <typename S, typename F>
constexpr auto for_each_field(S&& s, F&& f)
{
auto&...
5
votes
1
answer
309
views
Is there really not cross product in std::linalg and if yes why?
I know for sure how to calculate a cross product myself, but usually I tree to use the standard library where possible.
I am aware that std::linalg is still in development so this might already be the ...
17
votes
1
answer
982
views
Is `std::function` deprecated by `std::copyable_function` in C++26?
C++26 provides std::copyable_function [cppref link]. However, the existing std::function is already copyable. So, I have 3 questions:
What are the key advantages of std::copyable_function over std::...
8
votes
2
answers
272
views
Does structured binding pack allow empty pack from zero tuple-sized object?
Structured bindings do not allow empty decomposable types.
auto [] = std::make_tuple(); // error
Ever since P1061R10 has been accepted for C++26, this allows structured bindings to introduce packs (...
30
votes
2
answers
2k
views
Why is std::is_trivial deprecated in C++26?
std::is_pod is deprecated since C++20 and the answer to this question tells us that we should use std::is_standard_layout + std::is_trivial instead.
However, with C++26, now also std::is_trivial is ...
5
votes
1
answer
130
views
What happens with the deduction of a function parameter pack, if it appears in a non-deduced context?
The current draft standard contains this (see the last sentence of this paragraph):
"When a function parameter pack appears in a non-deduced context ([temp.deduct.type]), the type of that pack is ...
5
votes
2
answers
160
views
How can I make a tuple of types that can be accessed by index without pack indexing?
Using C++26's pack indexing, you can create a simple tuple of types like so:
template <typename... Ts>
struct type_tuple {
template <unsigned Index>
using get = Ts...[Index];
};
...
3
votes
1
answer
249
views
Is it possible to implement a constexpr static_vector?
Is it possible to implement a constexpr static_vector?
By static_vector, I mean a vector which has its storage space inside the vector (not heap allocated) and it cannot grow beyond the compile-time ...
2
votes
4
answers
190
views
concatenating any number of std::arrays, using only the bare minimum of ctor calls
I want to implement this function (a function which can concatenate any number of arrays, and it considers the value category as well):
template <typename ELEMENT, std::size_t ...SIZE>
constexpr ...
28
votes
3
answers
5k
views
When should I use a std::inplace_vector instead of a std::vector?
There is a new std::inplace_vector in the C++ standard library that seems to have a fixed capacity defined at compile time. I'm trying to understand a use case for std::inplace_vector instead of std::...
3
votes
1
answer
178
views
What's the deal with domains in execution?
P2300's execution has introduced execution domains such as std::execution::default_domain and the functions transform_env, transform_sender, and apply_sender.
I didn't see how these concepts play with ...
3
votes
1
answer
110
views
Static constexpr within its own class [duplicate]
I'm trying to create a Color class and some constants so I can use them like Color::Red in other parts of my code.
#ifndef COLOR_H
#define COLOR_H
#include <cstdint>
class Color
{
uint8_t ...
1
vote
1
answer
143
views
Compile time check that only one instance of a class is instantiated in the same scope
I have a class from an external library. Only one instance may exist in the same scope. I can assert(instance_counter<=1) that no problem in a wrapper class.
But I want to be sure at compile time. ...
1
vote
2
answers
265
views
Universal references: Why deducing this does not have std::forward?
I watched a video of Scott Meyers about universal references and he told that anytime when you use a universal reference, you must forward it like that:
template<typename T>
auto func(T &&...