652 questions
4
votes
1
answer
121
views
Can you observe whether _Atomic expands to an alias template or class template?
[stdatomics.h.syn] specifies the following:
template<class T>
using std-atomic = std::atomic<T>; // exposition only
#define _Atomic(T) std-atomic<T>
libc++ and libstdc++ ...
2
votes
0
answers
44
views
libstdc++.so links error when try to use pybind11/3.0.1 of conan-2 and cpp23 in wsl
In WSL (Ubuntu 24.04), when using Conan to create a package that links pybind11/3.0.1, the resulting executable in the test_package fails to run.
Even if the executable doesn't directly call any ...
9
votes
1
answer
288
views
How can you prevent a destructor call from being reordered above an atomic write by the compiler?
Here is a possibly incorrect program for communicating between a function and a signal handler that might interrupt it. Assume that HandleSignal has been arranged to run as a signal handler. The ...
5
votes
2
answers
234
views
Forwarding multiple sets of variadic arguments
I'm building a container which uses, as its internal representation, a couple of standard containers, each with a different type. I need to code my version of emplace(..) and here's where I got stuck.
...
1
vote
0
answers
63
views
How to make IntelliSense work properly with MSVC standard library and clang-cl compiler?
I'm trying to get clang-cl (the compiler I installed via Visual Studio Installer), MSVC standard library and IntelliSense to work together.
Simple 'Hello world' by C++23 std::println does build and ...
2
votes
1
answer
133
views
C++ Template Function Ambiguity for Wrapper Type Specialization
I have a C++ function template:
#include <string_view>
template<typename T>
T get_gadget(std::string_view str);
I also added explicit specializations for some user-defined types, e.g., ...
0
votes
1
answer
199
views
Typename packing is failed in C++
Here is code:
aml::type_list<int,int,char,std::string> example;
std::tuple_element_t<2,std::tuple<decltype(example)>> a = 'b';
But when i try to run code it says, static assertion ...
5
votes
1
answer
141
views
Use std::regex_search called from module
I came across a strange problem. I made a C++20 module with the following content (file module.cppm):
module;
#include <regex>
#include <string>
export module foo;
export namespace bar {
...
1
vote
0
answers
164
views
Weird interaction between libstdc++ standard library headers and module
I'm using clang 21.1.0 from linuxbrew's LLVM package with libstdc++ from Fedora 42's repos (gcc 15.2.1). The following code compiles:
#include <memory>
#include <string>
auto main() -> ...
1
vote
1
answer
328
views
Clangd: call to consteval function 'fmt::basic_format_string<...>' is not a constant expression, but MSVC compiles it
I'm using spdlog with fmt::format_string to log messages, and I also want to capture the call location using std::source_location. My goal is to have a simple logging function like this:
Logger::Error(...
8
votes
3
answers
338
views
What is the difference between using `std::from_range` vs `std::ranges::to`?
C++23 introduces std::ranges::to, allowing the construction of a container from a range. E.g.,
auto my_set = produce_range() | std::ranges::to<std::set>();
And C++23 also introduces the std::...
2
votes
1
answer
78
views
How to track time in a SetConsoleCtrlHandler
There is an extensive discussion of the risk that a write to shared state in a signal handler could be interrupted midway by another signal handler.
I handle CTRL+C in a function that is set up with ...
0
votes
1
answer
222
views
Can I create an *alias* member function in C++?
I am refactoring a project, and I have to unify a set of derived classes under the same base class.
These are two derived classes:
class D1 : public virtual B {
virtual int F(int i) { ...
0
votes
0
answers
86
views
How can I obtain a copyable value type from a transform_view<enumerate_view<...>>?
tl;dr
Given this code:
#include <functional>
#include <optional>
#include <range/v3/range/conversion.hpp>
#include <range/v3/range/primitives.hpp>
#include <range/v3/view/...
1
vote
1
answer
214
views
How to achieve conditional compile time for optional structure members without #if ... #else ... #endif
I am designing a new embedded c++23 library that will have a few hundreds of optional features.
the global idea is like this:
I would expect that if constexpr(...) would remove code when flag is false....
2
votes
2
answers
133
views
Deduce maximum number of function arguments (fails with concepts)
I am writing a function probeMaxArgs that deduces the maximum number of arguments in a function/callable object. For simplicity I assume, that the object don't have any overloads of operator() (...
5
votes
1
answer
115
views
Must I fully build an unordered_set::key_type object to call the erase() method?
I asked the similar question for find() method of std::unordered_set last day - How can I use a lightweight argument in unordered_set::find() method?. But the recommendations received for find() ...
3
votes
0
answers
123
views
Compiling std::generator with optimization produces null-dereference in GCC
cppreference.com gives an example on how to use the c++23 std::generator.
From https://en.cppreference.com/w/cpp/coroutine/generator.html:
#include <generator>
#include <iostream>
...
3
votes
2
answers
151
views
How to reduce verbosity when splitting `std::string_view` by `std::views::split`?
Consider the following snippet:
// included, for exposition only
SomeData buzz(std::string_view);
constexpr auto foo(std::string_view v) {
using namespace std::string_view_literals;
return v ...
13
votes
1
answer
1k
views
Does C++23 guarantee std::launder can be omitted in placement new scenarios?
#include <iostream>
#include <new>
struct A {
int const n;
void f() {
new (this) A{2};
}
void g() {
std::cout << this->n;
}
void h() {
...
1
vote
0
answers
168
views
What technical obstacles have prevented concurrent containers (e.g. P0652R2) from entering the ISO C++ standard?
Modern CPUs—even entry-level models—now ship with four or more hardware cores, so multithreaded programming is the norm rather than an afterthought.
By contrast, standard C++23 still offers only low-...
5
votes
1
answer
159
views
How to `bind_front()` the `this` pointer in a member function?
I'm writing an async, callback-heavy program, and a common pattern I encounter is, in a member function, having to make a callback pointing to another member function.
What I have so far is this:
void ...
11
votes
2
answers
1k
views
What is "[core] language undefined behavior" as opposed to "undefined behavior"?
Herb Sutter refers to that in Peering Forward - C++’s Next Decade - Herb Sutter - CppCon 2024, and it stresses language several times (e.g. here), so I'd like to understand how to tell it apart from ...
2
votes
0
answers
115
views
MSVC calling deleted destructor when wrapping rvalue in struct (C++23)
I'm experimenting, with wrapping move semantics into a wrapper type:
#include <utility>
#include <type_traits>
// Type that will get moved
struct NonDestructible {
~NonDestructible() =...
1
vote
2
answers
77
views
gcc/clang unresolved user-defined literal template operator""
I'm trying to parse UUID expression using C++23, However compiling under clang 20.1.6 and gcc 15.1.0 find the operator as candidates yet it get ignored. here is my code:
union uuid_t {
unsigned ...