c++20

Can lambdas be used as non-type template parameter?

荒凉一梦 提交于 2020-07-17 11:14:19
问题 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

What is the difference between chrono::month and chrono::months

做~自己de王妃 提交于 2020-07-17 03:24:12
问题 What is the difference between the C++20 chrono types/values month{7} and months{7} ? Isn't it confusing to have two such similar names? 回答1: Yes, it can be confusing to have both month and months when first encountering this library. However there are consistent naming conventions in this library to help reduce that confusion. And the benefit is having a clear separation of distinct semantics while retaining short intuitive names. months All "predefined" chrono::duration types are plural:

What is the difference between chrono::month and chrono::months

落爺英雄遲暮 提交于 2020-07-17 03:24:12
问题 What is the difference between the C++20 chrono types/values month{7} and months{7} ? Isn't it confusing to have two such similar names? 回答1: Yes, it can be confusing to have both month and months when first encountering this library. However there are consistent naming conventions in this library to help reduce that confusion. And the benefit is having a clear separation of distinct semantics while retaining short intuitive names. months All "predefined" chrono::duration types are plural:

Will std::string end up being our compile-time string after all?

∥☆過路亽.° 提交于 2020-07-15 04:14:29
问题 Many developers and library authors have been struggling with compile-time strings for quite a few years now - as the standard (library) string, std::string , requires dynamic memory allocation, and isn't constexpr. So we have a bunch of questions and blog posts about how to get compile-time strings right: Conveniently Declaring Compile-Time Strings in C++ Concatenate compile-time strings in a template at compile time? C++ Compile-Time string manipulation (off-site) Compile-time strings with

Will std::string end up being our compile-time string after all?

丶灬走出姿态 提交于 2020-07-15 04:14:29
问题 Many developers and library authors have been struggling with compile-time strings for quite a few years now - as the standard (library) string, std::string , requires dynamic memory allocation, and isn't constexpr. So we have a bunch of questions and blog posts about how to get compile-time strings right: Conveniently Declaring Compile-Time Strings in C++ Concatenate compile-time strings in a template at compile time? C++ Compile-Time string manipulation (off-site) Compile-time strings with

Will std::string end up being our compile-time string after all?

老子叫甜甜 提交于 2020-07-15 04:14:24
问题 Many developers and library authors have been struggling with compile-time strings for quite a few years now - as the standard (library) string, std::string , requires dynamic memory allocation, and isn't constexpr. So we have a bunch of questions and blog posts about how to get compile-time strings right: Conveniently Declaring Compile-Time Strings in C++ Concatenate compile-time strings in a template at compile time? C++ Compile-Time string manipulation (off-site) Compile-time strings with

What is `constinit` in C++20?

我只是一个虾纸丫 提交于 2020-07-13 09:22:04
问题 constinit is a new keyword and specifier in C++20 which was proposed in P1143. The following example is provided in the standard: const char * g() { return "dynamic initialization"; } constexpr const char * f(bool p) { return p ? "constant initializer" : g(); } constinit const char * c = f(true); // OK constinit const char * d = f(false); // ill-formed A few questions come to mind: What does constinit mean? Why was it introduced? In which cases should we use it? Does it make a variable

C++20 in g++10: generator not defined

会有一股神秘感。 提交于 2020-07-09 12:05:37
问题 This MCVE works fine in Visual Studio. #include <experimental/generator> #include <iostream> std::experimental::generator<int> f() { for (int i = 0; i < 10; ++i) co_yield i; } int main () { for (int i : f()) std::cout << i << ' '; return 0; } but in g++10, which is listed as having full support or C++20's coroutines, it does not. (Taking out experimental doesn't help.) I am compiling thus: g++ -g -std=c++2a -fcoroutines -c main.cpp . It complains that there is no include file generator, and

C++20 in g++10: generator not defined

狂风中的少年 提交于 2020-07-09 12:04:22
问题 This MCVE works fine in Visual Studio. #include <experimental/generator> #include <iostream> std::experimental::generator<int> f() { for (int i = 0; i < 10; ++i) co_yield i; } int main () { for (int i : f()) std::cout << i << ' '; return 0; } but in g++10, which is listed as having full support or C++20's coroutines, it does not. (Taking out experimental doesn't help.) I am compiling thus: g++ -g -std=c++2a -fcoroutines -c main.cpp . It complains that there is no include file generator, and

Is there a wrapper for floating point numbers in C++20 that would enable me to default the spaceship operator?

筅森魡賤 提交于 2020-07-08 14:01:31
问题 I was watching "Using C++20 three way comparison - Jonathan Müller - Meeting C++ 2019" talk and it mentioned problems with classes that contain floating point members. Problem comes from the fact that IEEE 754 comparisons involving NaN(s) are weird and do not provide total ordering. Talk gives a way to work around this problems, for example using strong_order or manually ignoring NaN values when implementing <=> (assuming that values are never NaN). My questions is if there are some library