Skip to main content
Filter by
Sorted by
Tagged with
2 votes
1 answer
295 views

I think the following code is ubiquitous: struct A { ... }; char buf[1024]; auto ptr = new (buf) A(...); However, new (buf) A(...); is UB. https://en.cppreference.com/w/cpp/language/lifetime.html ...
xmllmx's user avatar
  • 44.6k
11 votes
1 answer
564 views

Here's the test code: #include <concepts> template<typename T> concept Printable = requires(T obj) { { obj.print() } -> std::same_as<void>; }; template<Printable T> ...
Annyo's user avatar
  • 1,607
1 vote
0 answers
73 views

I'm trying to replace virtual base classes with concepts in a few places in my codebase where dynamic polymorphism isn't actually being used. However I still want it to be nominally typed. In ...
rdong8's user avatar
  • 97
3 votes
1 answer
152 views

At the cppref page on the concept std::default_initializable, I saw the following code: template<class T> concept default_initializable = std::constructible_from<T> && ...
xmllmx's user avatar
  • 44.6k
1 vote
0 answers
138 views

I'm encountering linker errors when using std::vformat inside an exported function from a C++20 module in a DLL. The minimal project setup to reproduce this issue is as follows: MainSolution DLL ...
Aki's user avatar
  • 23
1 vote
1 answer
113 views

#include <array> template<std::size_t tc_n> requires (tc_n > 0) struct StringLiteral final { std::array<char, tc_n> value{}; consteval StringLiteral(char const (&sl)[...
xmllmx's user avatar
  • 44.6k
1 vote
1 answer
80 views

In my CMake project I use "coro" library. But when compile the project I got following errors: /root/uwu/include/picohttp/server.hpp:58:58: error: ‘io_scheduler’ is not a member of ‘coro’ ...
Fuji's user avatar
  • 117
1 vote
1 answer
128 views

Here's a relatively short example: #include <cassert> #include <algorithm> #include <compare> #include <iostream> #include <optional> #include <vector> struct Foo {...
Enlico's user avatar
  • 30.2k
6 votes
1 answer
281 views

I've got a simple code example that attempts to use a format_as() overload to format a custom type (an enum); it outputs a std::string found in a map. From the link above, the compiler is configured ...
Chris Robison's user avatar
0 votes
2 answers
185 views

From cppreference: template< class I > concept contiguous_iterator = std::random_access_iterator<I> && std::derived_from</*ITER_CONCEPT*/<I>, std::...
rdong8's user avatar
  • 97
3 votes
1 answer
131 views

I'm building a client-server project using standalone Asio (C++20) and OpenSSL. My client uses asio::ssl::stream<asio::ip::tcp::socket> for TLS connections. After my client is done communicating ...
user avatar
4 votes
1 answer
190 views

I am defining a Point class where the "size" of a point is defined by its distance from the origin. I.e., a point p1 is "larger" than a point p2 if the sum of the squares of the ...
antonio's user avatar
  • 483
0 votes
3 answers
129 views

In order to use C++20's format capabilities with custom types, we have to provide template specializations of std::formatter for every type we want to format. The nice thing about this approach is ...
Raven's user avatar
  • 3,658
4 votes
4 answers
276 views

I have a template function with several type parameters and depending on those types, the function "calls" an static_assert(false). I want to know when my code fails to compile for specific ...
Lluís Alemany-Puig's user avatar
4 votes
1 answer
159 views

In the following program, the copy constructor of struct S is declared with the constraint that the class is not copy constructible: #include <concepts> template <typename T> struct S { ...
Fedor's user avatar
  • 24.7k
3 votes
1 answer
189 views

I am trying to implement a C++ Translate function for localization. // Language package, containing key-value pairs of translation, e.g., // g_LanguagePack["HELLO@1"] = "Hello, {}!"...
Silver's user avatar
  • 78
8 votes
2 answers
1k views

I'm writing a compile-time parser PoC (compiling a literal string to std::tuple) based on C++20 (or 23 if necessary). Currently gcc, clang, and MSVC all crash for this code, and MSVC gives useful ...
Sprite's user avatar
  • 4,147
5 votes
2 answers
287 views

I have the following code - template <typename T, typename F> struct unique {}; template <auto F> struct ltype { using type = decltype(F); }; using p = unique<int, ltype<[](){}&...
Ajay Brahmakshatriya's user avatar
0 votes
0 answers
174 views

I am trying to implement Double Dabble algorithm to convert a BigInt implemented in std::vector<uint32_t> to decimal string and back. I have already implemented a working version, using 16 bit ...
Ξένη Γήινος's user avatar
2 votes
3 answers
244 views

I have a Foo class that includes an array and a static constexpr variable. As a general convention, I want to write public and private variables respectively. But, compiler error occurs 's_array_size' ...
unique's user avatar
  • 130
6 votes
1 answer
102 views

I have a UTC offset that is not known until run-time, and is not necessarily an integral number of hours. The IANA time zone database isn't a good match for this. What is the simplest user-written ...
Howard Hinnant's user avatar
30 votes
1 answer
1k views

There are lots of Stack Overflow Q&A's solving this problem in other languages, but not so much in C++. How do I find the Nth weekday of the month using <chrono>? For example, what is the ...
Howard Hinnant's user avatar
5 votes
1 answer
175 views

Let me start with a C++ code that simplifies my issues I faced in the actual code base. I compiled it with --std=c++20 and --std=c++17. The first for-loop below was okay; the second for-loop, which ...
Stephen's user avatar
  • 735
24 votes
6 answers
5k views

Looking in cppreference, it seems to imply a std::binary_semaphore may be more efficient than a std::mutex. Is there any reason not to use a std::binary_semaphore initialized to 1 instead of a std::...
Baruch's user avatar
  • 22k
3 votes
3 answers
114 views

template<typename T, typename U> void add_property_immutable(T property_name, U property_value) { auto get_v8_data_type = []<typename X>(X&& property_name_or_value) -> int { ...
Jeff Greer's user avatar