c++23 Questions

1

This code compiles with MSVC from VS 2022 in C++20 mode. It failes in C++23 mode. (/std:c++latest) #include <memory> struct A; struct B { B(); ~B(); std::unique_ptr<A> ptr{nullptr...
Sverdlovsk asked 22/2 at 11:29

3

Solved

Why code below has no problem with a2 but does not compile for z1? #include <cmath> // std::nextafter #include <limits> // std::numeric_limits int main () { constexpr float a1 {1.f}; ...
Therewithal asked 3/3 at 17:19

1

Solved

I recently noticed a strange issue regarding C++23 Deducing this feature. Suppose we have a struct S with a simple conversion operator: struct S { operator int() { return 42; } }; int i = S{}; S...

0

So, I was trying to use the C++23 std::print and std::println functions, but when I tried to compile the following code using the -std=c++2b flag, it gave a fatal error: 'print' file not found #inc...
Phylum asked 4/1 at 13:30

1

Solved

I have the following code: #include <print> #include <vector> int main() { std::vector<int> v{1, 2, 3}; std::println("{}", v); } Among the numerous errors this produ...
Rage asked 4/1 at 0:44

1

Solved

C++23 allows [[...]] attributes in lambda expressions: auto lambda = [] [[nodiscard]] { return 42; }; But the grammar has place for two lists of attributes, roughly before and after the parameter...
Thurstan asked 22/12, 2023 at 14:6

3

Solved

How can you convert to a custom data structure using std::ranges::to? Basically something like struct my_data { char b; int foo; std::string baz; }; auto text = "v 3 fool|x 56 description|...
Kempe asked 18/12, 2023 at 14:30

2

Solved

(My original question was going to be about "What happened to _BitInt?" but that was based on a misreading of some cppreference pages). The Library Introduction section 16.2 of the C++23 ...
Nader asked 3/11, 2023 at 16:5

4

Solved

According to cppref: std::allocator<T>::allocate_at_least Allocates count * sizeof(T) bytes of uninitialized storage, where count is an unspecified integer value not less than n, by calling ...
Glidewell asked 8/9, 2021 at 7:1

2

Short Version of Question C++23 gives us a new way to write mixin classes (instead of CRTP). Is there any context where CRTP would still be preferred? Summary of the Two Approaches CRTP is a powerf...
Sandstone asked 26/10, 2023 at 23:33

1

Solved

The following code compiles fine: #include <cstddef> struct A { char a; static constexpr int off(void) { return offsetof(A, a); } static constexpr int (*off_p)(void) = off; }; The follow...
Weidman asked 22/10, 2023 at 18:40

1

Solved

I wanted to view a 3x3 grid column by column, so I figured I would use std::views::stride like so: #include <array> #include <iostream> #include <ranges> auto main() -> int { ...
Papyrology asked 11/10, 2023 at 17:2

2

C++23 will likely see the introduction of a stack trace mechanism, via the <stacktrace> header. I know we're going to have an std::stack_trace class, made up of std::stacktrace_entry'ies, and...
Gourley asked 29/12, 2021 at 19:17

1

Solved

I'm trying out the Kokkos reference mdspan implementation to see if it could be used to simplify some bits of code in our codebase. One thing that I would have intuitively assumed to be possible is...
Autosome asked 15/8, 2023 at 12:59

1

Solved

P0593, under the Type punning section, presents this example: float do_bad_things(int n) { alignof(int) alignof(float) char buffer[max(sizeof(int), sizeof(float))]; *(int*)buffer = n; // #1 new...
Firewater asked 7/9, 2023 at 10:43

1

Solved

How do I get the return type of a lambda that has a deducing this signature using std::invoke_result_t. auto lambda = [](this auto& self, int x) -> int { return x; }; auto x = std::invok...

2

Solved

In C++23, the [[assume(expression)]] attribute makes it so that if expression is false, the behavior is undefined. For example: int div(int x, int y) { [[assume(y == 1)]]; return x / y; } This c...
Anonym asked 1/9, 2023 at 15:3

1

Solved

Consider the following code: #include <memory> #include <optional> template <typename T> constexpr T * arg_to_pointer(T & arg) noexcept { return std::addressof(arg); } int ...
Peggypegma asked 24/8, 2023 at 14:36

2

Solved

On CppCon 2022 was announced, that new official HelloWorld in C++ is now: #include <print> int main() { std::print("Hello world\n"); return 0; } Do you know, is std::print avail...
Malefactor asked 24/8, 2023 at 7:49

2

Solved

After P0593R6 ('Implicit creation of objects for low-level object manipulation') was accepted in C++20, C++23 will get std::start_lifetime_as() which 'completes the functionality proposed in [P0593...
Shadshadberry asked 10/6, 2023 at 10:43

1

Solved

The wording in the standard regarding implicit move changed in c++23 see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2022/p2266r3.html relevant part is: a returned move-eligible id-express...
Cosmogony asked 9/7, 2023 at 10:40

2

Solved

Since C++11, we are able to do floating point math at compile time. C++23 and C++26 added constexpr to some functions, but not to all. constexpr floating point math is weird in general, because the...
Upstream asked 4/7, 2023 at 9:13

1

Solved

I have the following code: #include <stacktrace> #include <iostream> void bar() { for (const auto &entry : std::stacktrace::current()) { std::cout << entry << '\n'; ...
Appreciable asked 23/6, 2023 at 9:47

1

Solved

Are you allowed to use static local variables in constexpr functions? For example: #include <string_view> #include <utility> enum class axis { x, y, z }; constexpr std::string_view a...
Sargasso asked 24/6, 2023 at 18:51

2

Solved

I have the following code, which doesn't compile with x86_64 GCC 13: #include <iostream> #include <stdfloat> int main() { std::cout << std::float128_t{1} << '\n'; } This ...
Goodhen asked 18/6, 2023 at 10:44

© 2022 - 2024 — McMap. All rights reserved.