c++14

Why std::future is different returned from std::packaged_task and std::async?

早过忘川 提交于 2020-12-05 07:01:30
问题 I got to know the reason that future returned from std::async has some special shared state through which wait on returned future happened in the destructor of future. But when we use std::pakaged_task , its future does not exhibit the same behavior. To complete a packaged task, you have to explicitly call get() on future object from packaged_task . Now my questions are: What could be the internal implementation of future (thinking std::async vs std::packaged_task )? Why the same behavior was

constexpr defaulted default constructors

我怕爱的太早我们不能终老 提交于 2020-12-01 09:51:24
问题 I get compiler error by Clang 3.8 and GCC 5.3 if I want to declare my default -ed default constructors as constexpr . According to this stackoverflow question it just should work fine: struct A { constexpr A() = default; int x; }; however: Error: defaulted definition of default constructor is not constexpr Have you got any clue what is actually going on? 回答1: As it stands, x remains uninitialized, so the object can not be constructed at compile time. You need to initialize x: struct A {

constexpr defaulted default constructors

烈酒焚心 提交于 2020-12-01 09:50:42
问题 I get compiler error by Clang 3.8 and GCC 5.3 if I want to declare my default -ed default constructors as constexpr . According to this stackoverflow question it just should work fine: struct A { constexpr A() = default; int x; }; however: Error: defaulted definition of default constructor is not constexpr Have you got any clue what is actually going on? 回答1: As it stands, x remains uninitialized, so the object can not be constructed at compile time. You need to initialize x: struct A {

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

泄露秘密 提交于 2020-11-30 04:22:42
问题 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>

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>