c++20 Questions

1

Solved

Should the following program be rejected? Clang seems to accept it. template<typename T> concept c = requires { T::n; }; struct z; constexpr bool b(auto...) { return c<z>; } struct z { ...
Refutation asked 12/10 at 22:32

2

Solved

I was reviewing a code I proposed to initialize a std::array at compile-time for non-default-constructible objects: https://mcmap.net/q/905632/-idiom-for-initializing-an-std-array-using-a-generator...

1

Solved

I understand that std::is_constant_evaluated() was useful to determine compile time evaluation in C++20. But since C++23 we have if consteval. However there is no mention of deprecation for std::is...
Araceli asked 2/10 at 14:3

2

Solved

I'm trying to learn C++ ranges. As far as I can see, the simplest (and the only, short of implementing a custom range view class) way to create a range view object that generates a custom sequence ...
Angers asked 30/9 at 16:44

1

Solved

A requires-expression similarly to a function can introduce local parameters using a parameter list. And lambda expressions defined at block scope may have captures without initializers. Is it allo...
Interlace asked 25/9 at 19:40

2

Solved

GCC accepts this code, Clang and MSVC reject it due to failed static assertion in assert. What does the standard say? https://godbolt.org/z/PKMKzYGsc template<typename T> constexpr int assert...
Effectuate asked 24/9 at 2:53

1

This code compiles on gcc and msvc but not with clang from C++20 on: #include <type_traits> class IBase { protected: IBase() noexcept = default; public: virtual ~IBase() noexcept = defa...
Redfin asked 21/9 at 16:27

1

Solved

A requires-expression can introduce local parameters using a parameter list. If any of these parameters has void type, will the requires expression just yield false or shall it be hard compilation ...
Northeastwards asked 19/9 at 20:32

2

Solved

VS2019 latest c++ compiler. Error is :"a coroutine's promise must declare either 'return_value' or 'return_void'" Example pulled from David Mazièreshttps://www.scs.stanford.edu/~dm/blog/c...
Greenhead asked 28/4, 2021 at 18:59

1

I have installed gcc-10 compiler on my ubuntu 20.04. I needed to test the work of coroutine ts, so I found an example using coroutines and tried to compile it. exemple: #include <coroutine> #...
Alkyd asked 27/11, 2020 at 15:45

2

Solved

Consider this example: std::atomic<int> v = {0}; // thread 1: for(int i = 0; i<999999;i++) v.load(memory_order::seq_cst); // #1 v.exchange(2,memory_order::seq_cst); // #2 //thread 2: ...
Engen asked 5/9 at 9:52

1

Solved

Having this code, GCC and MSVC are both happy with it, when clang complains. Any two lambdas must have different types, which makes me think that clang "caches" the type of the default te...
Linotype asked 6/9 at 19:6

1

I am testing ranges from C++ 20 , and this is my main.cpp: #include <ranges> #include <iostream> int main() { auto const ints = {0,1,2,3,4,5}; auto even = [](int i) { return 0 == i %...
Tenebrous asked 26/5, 2021 at 8:56

3

Solved

I was working on a simple parser using std::ranges. I was trying to parse ints in a string until all were converted or one failed by doing something like: try_parse_ints(str) | take_while(is valid ...
Aney asked 28/8 at 17:57

1

Solved

I have the following bit of code, that uses a runtime determined width: #include <string> #include <vector> #include <fmt/core.h> #include <fmt/format.h> int main() { std...
Epaminondas asked 1/9 at 5:5

3

Solved

Let me describe a scenario, first we have a function which returns us some sort of data which we can't be sure about the validity of, i.e. auto random_predicate() -> bool { int v = uniform_dist...
Exemplar asked 25/2, 2023 at 23:33

2

Solved

Currently best way I can think of is to use static_assert, but I would prefer nicer way. #include <set> #include <forward_list> using namespace std; template<typename C> concep...
Pernick asked 10/1, 2018 at 14:26

2

How does an atomic<shared_ptr<>> work internally ? I'm not asking for the mechanics of the control block alongside with the stored data, which is easy to imagine for me, but for the ato...
Gassy asked 6/8 at 11:35

1

Solved

Consider the following move-only type: struct MoveOnly { MoveOnly() = default; ~MoveOnly() = default; MoveOnly(const MoveOnly&) = delete; MoveOnly& operator=(const MoveOnly&) = del...

3

Solved

In C++20, there are two swap function templates: std::ranges::swap(T&&, U&&) and std::swap(T&, T&). I just wonder: What's the difference between they two?
Markson asked 25/7, 2021 at 7:42

1

Solved

I'm seeing some unexpected behavior when using the std::variant::operator<. In the situation where the type has an implicit bool conversion operator and its less operator is not a member functio...
Scourge asked 26/7 at 10:58

1

Solved

Consider the following two structs whose sizes are 8 and 1 bytes respectively: class eight { int i; char c; eight(const blub&) {} }; class one { char s; one(const blob&) {} }; Whe...
Anthropography asked 22/7 at 15:8

1

Anyone knows what kind of UB is this? The following code deadlocks on jthread destruction when built with MSVC 19.29.30148, sometimes it deadlocks after std::cout and sometimes before. This is some...
Ozell asked 18/9, 2023 at 10:31

1

Solved

Consider this concept, which has a default template parameter. template<class T, class = decltype([]{})> concept IsDefined = sizeof(T) > 0; Since every lambda has a distinct type, one mig...
Weiser asked 19/7 at 16:7

1

Solved

I am new to C++ modules. I am using Visual Studio 2022. Let's say I am creating a DLL, and I don't want my users to see implementation details of my class. How can I achieve this in C++ modules? Mo...
Mil asked 9/7 at 18:9

© 2022 - 2024 — McMap. All rights reserved.