c++20

What is the need of template lambda introduced in C++20 when C++14 already has generic lambda?

送分小仙女□ 提交于 2020-11-30 04:21:10
问题 c++14 introduced generic lambdas that made it possible to write following: auto func = [](auto a, auto b){ return a + b; }; auto Foo = func(2, 5); auto Bar = func("hello", "world"); It is very clear that this generic lambda func works just like a templated function func would work. Why did the C++ committee decide to add template syntax for generic lamda? 回答1: C++14 generic lambdas are a very cool way to generate a functor with an operator () that looks like this: template <class T, class U>

Why isn't this class specialization using a concept accepted?

▼魔方 西西 提交于 2020-11-29 08:58:09
问题 The following code attempts to partially specialize a class using a concept and add a method to the specialization, but it is rejected by clang 11.0.0: #include <concepts> template <typename T> // note: previous template declaration is here struct S {}; template <std::integral T> struct S<T> { void f(); }; template <std::integral T> // error: type constraint differs in template redeclaration void S<T>::f() { } clang gives the error message: <source>:14:16: error: type constraint differs in

How to use the <format> header

家住魔仙堡 提交于 2020-11-29 05:09:32
问题 In a related question (" std::string formatting like sprintf ") I learned about this awesome new C++20 header <format>. However, there seems to be no supporting compiler. Is this correct or is there a way to use it anyway? I'm using g++ 9.3 with the -std=c++2a flag and the library <format> is not recognised. #include <format> // fatal error: format: No such file or directory #include <iostream> int main(){ std::cout << std::format("Hello {}!", "World"); } g++-9 test.cpp -o test -std=c++2a 回答1

How to use the <format> header

孤街醉人 提交于 2020-11-29 05:08:11
问题 In a related question (" std::string formatting like sprintf ") I learned about this awesome new C++20 header <format>. However, there seems to be no supporting compiler. Is this correct or is there a way to use it anyway? I'm using g++ 9.3 with the -std=c++2a flag and the library <format> is not recognised. #include <format> // fatal error: format: No such file or directory #include <iostream> int main(){ std::cout << std::format("Hello {}!", "World"); } g++-9 test.cpp -o test -std=c++2a 回答1