c++20 Questions

2

The GCC C++ compiler (any many other C++ compilers as well) provide nonstandard extentions such as alloca() for stack based allocation variable length arrays, as they are part of the C standard C...
Acrobatic asked 17/5, 2021 at 19:47

1

Solved

template <typename... Ts> struct A { template <typename C> constexpr auto proc() noexcept { return C{ }; } constexpr size_t size() noexcept { return sizeof...(Ts); } }; template &lt...
Frit asked 5/7 at 10:37

2

Solved

The CTRE library is able to parse and validate regular expressions at compile time using syntax like ctre::match<"REGEX">(text_to_search). I know this syntax is only supported...
Ecclesiolatry asked 17/6, 2021 at 18:12

1

Solved

I'm writing a constexpr code and I would like to inspect computed values at compile time. The usual trick is to do something like this: struct ReturnValue { int value1; int value2; }; constexpr...
Rima asked 26/6 at 11:27

2

Solved

Let's say I have a vector of a very simple struct: struct SimpleStruct { int a; int b; int c; }; std::vector<SimpleStruct> vs; I wish to sort this struct by 'a' leaving the positions of 'b' ...
Mormon asked 19/6 at 0:35

3

Solved

Consider the following piece of code: struct B { friend bool operator< (const B&, const B&); friend bool operator==(const B&, const B&); }; struct D : B { friend std::strong_...
Hangman asked 18/6 at 13:37

3

Solved

A handy method to verify if a positive integer n is a power of two (like 1, 2, 4, 8, etc.) is to use the following test for having no more than 1 bit set: bool test = n & (n - 1) == 0; This op...

2

Solved

The following code (godbolt): #include <iostream> #include <vector> #include <ranges> struct S { float x = 150.f; S f() const { return *this; } }; int main() { std::vect...
Behlau asked 16/6 at 22:0

2

Solved

Consider this code: #include <iostream> #include <vector> #include <exception> void foo(std::exception const& e1) { try { std::cout << e1.what() << std::endl; ...

1

Anonymous enums are in common use for defining compile-time-only constants in a compiler-supported fashion (i.e. without resorting to Macros), in C. This is also true for C++ (because even while th...
Remediable asked 13/6 at 12:25

1

I'm fairly new to C++ coroutines. When my app shuts down, I'd like to be able to give any outstanding co-routines a hint that I'd prefer they finished early. One solution/idea I came up with was to...
Pumpernickel asked 2/2, 2021 at 22:17

2

I was confused by the following paragraph about type aliasing from cppreference (source): Whenever an attempt is made to read or modify the stored value of an object of type DynamicType through a g...
Graiae asked 20/5, 2021 at 13:24

2

Solved

In C++ Weekly - Ep 313 - The constexpr Problem That Took Me 5 Years To Fix!, Jason Turner demonstrates several compile-time techniques in order to construct a std::string at compile-time and then p...

3

Solved

Consider the following scenario: struct MyInterface {}; struct Data : MyInterface{}; struct DataWrapper { SomeContainerOf<MyInterface*> getData() {...} private: std::vector<Data...
Streptothricin asked 1/6 at 20:58

8

Solved

The C++20 feature std::source_location is used to capture information about the context in which a function is called. When I try to use it with a variadic template function, I encountered a probl...

1

C++20 std::atomic has wait and notify_* member functions, but no wait_for/wait_until. The Microsoft STL implementation for std::atomic uses WaitOnAddress (when the OS is new enough to has it). And ...
Corinecorinna asked 21/10, 2021 at 10:20

1

The proposal for shared_ptr<T[N]> has this paragraph: https://www.open-std.org/JTC1/SC22/WG21/docs/papers/2014/n3920.html The unfortunate occurence of unique_ptr having lost its support for ...
Unquestioned asked 24/5 at 0:41

2

Solved

I've got the following implementation of the c++ concept move_constructible from cppreference template<typename _Tp> concept move_constructible = constructible_from<_Tp, _Tp> &&amp...
Beneath asked 22/11, 2021 at 4:40

1

Solved

I've reduced my code to the following example, which fails -O3 C++20 compilation on my g++ (x64 12.3) as well as apparently 14.1 when using godbolt: Again according to godbolt, clang works without ...
Testimony asked 22/5 at 10:26

1

For some reason GCC regards variable a as an rvalue within the initialization of variable b (of which the expression is of type int&). And, as a result, rejects the code as it's not able to bin...
Oskar asked 13/5 at 23:58

2

Solved

I'm dealing with the last big 4 of C++ 20, attempting to learn the new main features. Trying some code from the web related to ranges, I've written: std::vector ints{ 6, 5, 2, 8 }; auto even = [](i...
Prejudice asked 28/9, 2020 at 12:54

2

Solved

I want to loop through a vector in a sorted way without modifying the underlying vector. Can std::views and/or std::range be used for this purpose? I've successfully implemented filtering using vie...
Irrepressible asked 4/3, 2022 at 8:41

2

The std::ranges::view concept in C++23 requires a view to be movable, which includes move-assignability. I understand why we want a view to be move-constructible, but why is the assignment necessar...

1

Solved

libc++ std::counting_semaphore uses atomic increment with memory_order_release in release method: void release(ptrdiff_t __update = 1) { if(0 < __a.fetch_add(__update, memory_order_release)) ...
Cascade asked 2/8, 2020 at 11:27

1

I've encountered a really weird problem with clang. When I compile my code with C++20 using gcc-11 everything is fine. The problem appears when I try to compile it with C++20 and clang-14 (using cl...

© 2022 - 2024 — McMap. All rights reserved.