c++20

Are stackless C++20 coroutines a problem?

匆匆过客 提交于 2020-04-07 11:13:45
问题 Based on the following it looks like coroutines in C++20 will be stackless. https://en.cppreference.com/w/cpp/language/coroutines I'm concerned for many reasons: On embedded systems heap allocation is often not acceptable. When in low level code, nesting of co_await would be useful (I don't believe stackless co-routines allow this). With a stackless coroutine, only the top-level routine may be suspended. Any routine called by that top-level routine may not itself suspend. This prohibits

Are stackless C++20 coroutines a problem?

淺唱寂寞╮ 提交于 2020-04-07 11:11:06
问题 Based on the following it looks like coroutines in C++20 will be stackless. https://en.cppreference.com/w/cpp/language/coroutines I'm concerned for many reasons: On embedded systems heap allocation is often not acceptable. When in low level code, nesting of co_await would be useful (I don't believe stackless co-routines allow this). With a stackless coroutine, only the top-level routine may be suspended. Any routine called by that top-level routine may not itself suspend. This prohibits

Something like `declval` for concepts

只谈情不闲聊 提交于 2020-04-06 08:08:28
问题 When you are working with templates and with decltype you often need an instance of a certain type even though you do not have any the moment. In this case, std::declval<T>() is incredibly useful. This creates an imaginary instance of the type T . Is there a something similar for concepts? i.e. a function which would create and imaginary type for a concept. Let me give you an example(a bit contrived but should serve the purpose): Let's define a concept Incrementable template <typename T>

Something like `declval` for concepts

若如初见. 提交于 2020-04-06 08:08:12
问题 When you are working with templates and with decltype you often need an instance of a certain type even though you do not have any the moment. In this case, std::declval<T>() is incredibly useful. This creates an imaginary instance of the type T . Is there a something similar for concepts? i.e. a function which would create and imaginary type for a concept. Let me give you an example(a bit contrived but should serve the purpose): Let's define a concept Incrementable template <typename T>

How do I “expand” a compile-time std::array into a parameter pack?

好久不见. 提交于 2020-03-22 08:09:39
问题 I'd like to use partial template specialization in order to 'break down' an array (which is created at compile time) into a parameter pack composed of its values (to interface with other structures I define in my code). The following (my first attempt) is not compiling #include <array> template <typename T, auto k> struct K; template <typename T, std::size_t... A> struct K<T, std::array<std::size_t, sizeof...(A)>{A...}> {}; because the template argument std::array<long unsigned int, sizeof...

How do I “expand” a compile-time std::array into a parameter pack?

只愿长相守 提交于 2020-03-22 08:08:44
问题 I'd like to use partial template specialization in order to 'break down' an array (which is created at compile time) into a parameter pack composed of its values (to interface with other structures I define in my code). The following (my first attempt) is not compiling #include <array> template <typename T, auto k> struct K; template <typename T, std::size_t... A> struct K<T, std::array<std::size_t, sizeof...(A)>{A...}> {}; because the template argument std::array<long unsigned int, sizeof...

Wildcard for C++ concepts saying “accepting anything for this template argument”

痞子三分冷 提交于 2020-03-20 07:39:38
问题 Is there a way to allow a concept with template arguments , to be ok with any template parameter provided? I.e. some kind of wildcard magic for template argument placeholder? A usage example: template<class Me, TestAgainst> concept derived_from_or_same_as = std::same_as<Me, TestAgainst> || std::derived_from<decltype(p.first), First>; Above is needed because unfortunately primitive types behave differently than class types for is_base_of and derived_from . Now we can define a Pair concept that

Wildcard for C++ concepts saying “accepting anything for this template argument”

拟墨画扇 提交于 2020-03-20 07:37:55
问题 Is there a way to allow a concept with template arguments , to be ok with any template parameter provided? I.e. some kind of wildcard magic for template argument placeholder? A usage example: template<class Me, TestAgainst> concept derived_from_or_same_as = std::same_as<Me, TestAgainst> || std::derived_from<decltype(p.first), First>; Above is needed because unfortunately primitive types behave differently than class types for is_base_of and derived_from . Now we can define a Pair concept that

Wildcard for C++ concepts saying “accepting anything for this template argument”

别说谁变了你拦得住时间么 提交于 2020-03-20 07:37:37
问题 Is there a way to allow a concept with template arguments , to be ok with any template parameter provided? I.e. some kind of wildcard magic for template argument placeholder? A usage example: template<class Me, TestAgainst> concept derived_from_or_same_as = std::same_as<Me, TestAgainst> || std::derived_from<decltype(p.first), First>; Above is needed because unfortunately primitive types behave differently than class types for is_base_of and derived_from . Now we can define a Pair concept that

Lambda lifetime explanation for C++20 coroutines

折月煮酒 提交于 2020-03-20 06:16:30
问题 Folly has a useable library for C++20 style coroutines. In the Readme it claims: IMPORTANT: You need to be very careful about the lifetimes of temporary lambda objects. Invoking a lambda coroutine returns a folly::coro::Task that captures a reference to the lambda and so if the returned Task is not immediately co_awaited then the task will be left with a dangling reference when the temporary lambda goes out of scope. I tried to make a MCVE for the example they provided, and was confused about