Skip to main content
Filter by
Sorted by
Tagged with
9 votes
1 answer
615 views

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(...
PiotrNycz's user avatar
  • 25.1k
Best practices
3 votes
4 replies
146 views

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::...
xmllmx's user avatar
  • 44.6k
9 votes
1 answer
915 views

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) { ...
Timothy Liu's user avatar
Advice
0 votes
7 replies
332 views

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 ...
DipStax's user avatar
  • 572
Advice
5 votes
2 replies
5k views

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&...
user2394284's user avatar
  • 6,164
3 votes
1 answer
130 views

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 ...
dumbass's user avatar
  • 27.2k
10 votes
1 answer
244 views

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, ...
Fedor's user avatar
  • 24.7k
3 votes
2 answers
225 views

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 ...
sh1's user avatar
  • 5,010
7 votes
1 answer
175 views

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(":("...
Jan Schultke's user avatar
  • 43.7k
4 votes
2 answers
183 views

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 ...
xmllmx's user avatar
  • 44.6k
1 vote
0 answers
197 views

Consider the following code: #include <type_traits> struct A trivially_relocatable_if_eligible final { A() {} A(A const&) = delete; A& operator=(A const&) = ...
xmllmx's user avatar
  • 44.6k
4 votes
1 answer
166 views

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 ...
Eternal's user avatar
  • 3,114
1 vote
0 answers
98 views

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 ...
Kiwi's user avatar
  • 11
4 votes
0 answers
111 views

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 ...
smalik's user avatar
  • 483
0 votes
1 answer
197 views

Consider the code example excerpted from cppref: #include <complex> #include <iostream> #include <memory> int main() { alignas(std::complex<float>) unsigned char buf[...
xmllmx's user avatar
  • 44.6k
50 votes
1 answer
5k views

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 ...
Barry's user avatar
  • 312k
6 votes
1 answer
348 views

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 ...
Artem Selivanov's user avatar
3 votes
0 answers
167 views

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 ...
xmllmx's user avatar
  • 44.6k
4 votes
1 answer
218 views

Below example is taken from P2996 verbatim: #include <experimental/meta> #include <string> #include <type_traits> #include <print> template<typename E, bool Enumerable = ...
ofo's user avatar
  • 1,504
6 votes
1 answer
230 views

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 ...
xmllmx's user avatar
  • 44.6k
5 votes
1 answer
210 views

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. ...
Desmond Gold's user avatar
  • 2,278
1 vote
1 answer
217 views

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 ...
Vincent's user avatar
  • 61.1k
4 votes
1 answer
220 views

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 ...
Vincent's user avatar
  • 61.1k
3 votes
3 answers
261 views

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, ...
xmllmx's user avatar
  • 44.6k
2 votes
1 answer
122 views

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&&...
xmllmx's user avatar
  • 44.6k
3 votes
1 answer
197 views

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; ...
xmllmx's user avatar
  • 44.6k
6 votes
1 answer
330 views

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 ...
Harry's user avatar
  • 4,144
3 votes
1 answer
253 views

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. ...
levzettelin's user avatar
  • 3,062
3 votes
0 answers
149 views

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 ...
Sergio's user avatar
  • 1,011
10 votes
1 answer
3k views

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
Harry's user avatar
  • 4,144
13 votes
0 answers
379 views

#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 &...
yaito3014's user avatar
  • 131
6 votes
2 answers
205 views

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,...
Aaron Chifwalo Shavesha's user avatar
21 votes
2 answers
1k views

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. ...
Ali's user avatar
  • 319
7 votes
0 answers
303 views

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 (...
Quuxplusone's user avatar
  • 28.7k
7 votes
0 answers
318 views

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 ...
Jan Schultke's user avatar
  • 43.7k
25 votes
3 answers
1k views

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 ...
yosemite's user avatar
  • 251
5 votes
2 answers
149 views

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&...
Jean-Michaël Celerier's user avatar
5 votes
1 answer
309 views

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 ...
Torsten Knodt's user avatar
17 votes
1 answer
982 views

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::...
xmllmx's user avatar
  • 44.6k
8 votes
2 answers
272 views

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 (...
Desmond Gold's user avatar
  • 2,278
30 votes
2 answers
2k views

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 ...
gexicide's user avatar
  • 40.4k
5 votes
1 answer
130 views

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 ...
geza's user avatar
  • 30.5k
5 votes
2 answers
160 views

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]; }; ...
HeliumHydride's user avatar
3 votes
1 answer
249 views

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 ...
geza's user avatar
  • 30.5k
2 votes
4 answers
190 views

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 ...
geza's user avatar
  • 30.5k
28 votes
3 answers
5k views

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::...
The Mad Gamer's user avatar
3 votes
1 answer
178 views

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 ...
Desmond Gold's user avatar
  • 2,278
3 votes
1 answer
110 views

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 ...
Bencri's user avatar
  • 1,293
1 vote
1 answer
143 views

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. ...
Patrick Fromberg's user avatar
1 vote
2 answers
265 views

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 &&...
Chameleon's user avatar
  • 2,239