c++20

Why C++20 doesn't use `requires` to restrict the T for atomic<T>?

时光怂恿深爱的人放手 提交于 2020-08-07 18:27:41
问题 A generic std::atomic<T> is required to have a T that is Copy Constructible and Copy Assignable : [atomics.types.generic]/1 The program is ill-formed if any of (1.1) is_­trivially_­copyable_­v<T> , (1.2) is_­copy_­constructible_­v<T> , (1.3) is_­move_­constructible_­v<T> , (1.4) is_­copy_­assignable_­v<T> , or (1.5) is_­move_­assignable_­v<T> is false . Above is not new to C++20. Compilers may use static_assert to issue an error for a non-conforming T. However, C++20 could use formal

What are use cases of separate arrive and wait of C++20 barrier?

|▌冷眼眸甩不掉的悲伤 提交于 2020-08-07 03:34:45
问题 C++20 std::barrier has arrive_and_wait method, which is what pretty much every synchronization barrier implementation has. But it also has separate arrive and wait . I'm wondering what are the use cases. 回答1: OK, so you've got a bunch of threads that have to do some kind of synchronized tasks. These tasks are grouped into phases: the tasks from one phase will use data produced by tasks from a previous phase, and all previous phase work must be done before any next-phase work can start. Any

Will there be a concept for arithmetic types in C++ standard library?

北城以北 提交于 2020-08-06 08:09:46
问题 I've been looking through concepts library on C++ reference and i couldn't find a concept for arithmetic types. I couldn't also find it in p0898. I think such concept would be very helpful. Insted of doing: template <typename T> T some_function(T arg) requires std::integral<T> || std::floating_point<T> { /* functions body */ } I could just do: template <std::arithmetic T> T some_function(T arg) { /* functions body */ } I could obviously define it myself and it wouldn't be hard (ex. template

Will there be a concept for arithmetic types in C++ standard library?

余生长醉 提交于 2020-08-06 08:09:45
问题 I've been looking through concepts library on C++ reference and i couldn't find a concept for arithmetic types. I couldn't also find it in p0898. I think such concept would be very helpful. Insted of doing: template <typename T> T some_function(T arg) requires std::integral<T> || std::floating_point<T> { /* functions body */ } I could just do: template <std::arithmetic T> T some_function(T arg) { /* functions body */ } I could obviously define it myself and it wouldn't be hard (ex. template

How can I use C++20 std::format?

不打扰是莪最后的温柔 提交于 2020-08-02 16:55:13
问题 C++20 introduces std::format . What are the advantages over printf or std::cout . How can I use it and someone give an example of it? 回答1: What are the advantages over printf Type safety. For printf, the programmer must carefully match the format specifier to the type of the argument. If they make a mistake, the behaviour of the program is undefined. This is a very common source of bugs, especially for beginners. To be fair, decent compilers diagnose these mistakes as long as a constant

Why is volatile deprecated in C++20?

倾然丶 夕夏残阳落幕 提交于 2020-07-28 14:18:23
问题 According to cppreference, most uses of the volatile keyword are to be deprecated in C++20. What is the disadvantage of volatile ? And what is the alternative solution when not using volatile ? 回答1: There's a good talk by the c++ committee language evolution chair on why. Brief summary, many of the places that volatile is being removed from didn't have any understandable meaning and just caused confusion. 来源: https://stackoverflow.com/questions/59223814/why-is-volatile-deprecated-in-c20

Why is volatile deprecated in C++20?

六眼飞鱼酱① 提交于 2020-07-28 14:15:57
问题 According to cppreference, most uses of the volatile keyword are to be deprecated in C++20. What is the disadvantage of volatile ? And what is the alternative solution when not using volatile ? 回答1: There's a good talk by the c++ committee language evolution chair on why. Brief summary, many of the places that volatile is being removed from didn't have any understandable meaning and just caused confusion. 来源: https://stackoverflow.com/questions/59223814/why-is-volatile-deprecated-in-c20

Concise bidirectional static 1:1 mapping of values and types

不羁岁月 提交于 2020-07-17 11:18:13
问题 I'm going to start with how I imagine using the code I'd like to create. It doesn't have to be exactly like this but it's a good example of what I mean by "concise" in the title. In my case it's mapping of a type to a related enumeration value. struct bar : foo<bar, foo_type::bar> { /* ... */ }; // \_/ \___________/ // ^ Type ^ Value What this should ideally do is an automatic registration of a bidirectional mapping between the first template parameter of foo , a type, and second, a value,

Concise bidirectional static 1:1 mapping of values and types

╄→尐↘猪︶ㄣ 提交于 2020-07-17 11:16:41
问题 I'm going to start with how I imagine using the code I'd like to create. It doesn't have to be exactly like this but it's a good example of what I mean by "concise" in the title. In my case it's mapping of a type to a related enumeration value. struct bar : foo<bar, foo_type::bar> { /* ... */ }; // \_/ \___________/ // ^ Type ^ Value What this should ideally do is an automatic registration of a bidirectional mapping between the first template parameter of foo , a type, and second, a value,

Can lambdas be used as non-type template parameter?

…衆ロ難τιáo~ 提交于 2020-07-17 11:14:41
问题 Is the following code legal? template <auto Lambda> struct A {}; int main () { auto lmb = [](int i){return i*i;}; A<lmb> a; return 0; } I noticed that g++ compiles it fine, while clang++ returns error: a non-type template parameter cannot have type '(lambda at main.cpp:...)' . 回答1: Can lambdas be used as non-type template parameter? Yes, with implementations that has implemented P0732R2 - Class types in non-type template parameters but clang++ has not implemented it yet. Source: https://en