c++20

a non-type template parameter cannot have type [closed]

做~自己de王妃 提交于 2021-01-28 11:50:54
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 8 months ago . Improve this question For anyone stumbling upon this question in the future, the original question was: "How to get the simplest example (Point) from this article to compile with GCC or CLANG ?" Edit 1 shows the smallest possible code that fails with CLANG but compiles with GCC (both with -std=c+

Do temporaries passed to a function that returns awaitable remains valid after suspension point with co_await

帅比萌擦擦* 提交于 2021-01-28 02:24:25
问题 I'm adding support for coroutines ts in an async socket class based on windows io completion ports . Without coroutines the io may be done like this : sock.async_write(io::buffer(somebuff), [](auto&& ... args){ /* in handler */ }); or sock.async_write(std::vector<io::const_buffer>{ ... }, [](auto&& ... args){ /* in handler */ }) where each one will returns void and will notify the result through the handler and doesn't need to cache the parameters because the operation will have been

Why can't a range be sorted in range-v3?

筅森魡賤 提交于 2021-01-27 21:00:53
问题 Using the Range-v3 (release 0.10.0) library I was trying to construct a range from a std::vector, transform it into another range and finally sort that range. I expected the sort step to produce another range that I could consume later. But the best I could come up with was this: std::vector<std::string> const input { "2", "3", "1" }; using namespace ranges; std::vector<int> output = input | views::transform([](std::string s) { return std::stoi(s); }) | to<std::vector>() | actions::sort

C++20 Concepts: out-of-line-definition fails with MSVC but not in GCC or clang

好久不见. 提交于 2021-01-27 19:54:51
问题 Consider this little code snippet namespace nsp { template<typename T> concept Addable= requires(const T& a,const T& b) { {a + b} -> std::convertible_to<T>; }; template<Addable T> struct C { C(); }; } template<nsp::Addable T> nsp::C<T>::C() {}; As shown here GCC (10.2) and clang (11.0) accept the code while MSVC (x86 19.28) rejects it with the error message: error C3855: 'nsp::C<T>': template parameter 'T' is incompatible with the declaration. Is this a MSVC bug or are GCC and clang wrong

Does a class template's requires clause have to be repeated outside member definitions?

只谈情不闲聊 提交于 2021-01-27 06:59:29
问题 When the member of a class template that uses the requires clause is defined outside the class, gcc does not complain if requires is not specified, whereas clang does. Consider the code snippet below: #include <concepts> template<typename Container> requires std::integral<typename Container::value_type> class Foo { public: void func(); }; template<typename Container> void Foo<Container>::func() {} The compilation using gcc does not complain. While clang reports the following error: ❯ clang++

Does a class template's requires clause have to be repeated outside member definitions?

你离开我真会死。 提交于 2021-01-27 06:57:26
问题 When the member of a class template that uses the requires clause is defined outside the class, gcc does not complain if requires is not specified, whereas clang does. Consider the code snippet below: #include <concepts> template<typename Container> requires std::integral<typename Container::value_type> class Foo { public: void func(); }; template<typename Container> void Foo<Container>::func() {} The compilation using gcc does not complain. While clang reports the following error: ❯ clang++

SFINAE inside concept template argument

我的梦境 提交于 2021-01-27 06:29:08
问题 Does SFINAE work inside a concept argument? (maybe it's not called SFINAE here). Example: template <class F> requires std::invocable<F, int> && // <-- is this needed? (!std::same_as<std::invoke_result_t<F, int>, void>) auto foo(F f, int a) -> int Is the above std::invocable<F, int> required? If we omit it like so: template <class F> requires (!std::same_as<std::invoke_result_t<F, int>, void>) auto foo(F f, int a) -> int Is this version well-formed even if std::invoke_result_t<F, int> is not

is constexpr algorithm really useful, when iterator (input parameters) are not constexpr generally?

ε祈祈猫儿з 提交于 2021-01-27 04:15:28
问题 proposed in c++ 20, some algorithms are constexpr. For example: template< class InputIt, class UnaryPredicate > bool all_of( InputIt first, InputIt last, UnaryPredicate p ); (since C++11) (until C++20) template< class InputIt, class UnaryPredicate > constexpr bool all_of( InputIt first, InputIt last, UnaryPredicate p ); (since C++20) While we know iterator are not constexpr generally. I think this is useful only in case of constexpr container. Can someone clarify if I am missing something and

C++20 behaviour breaking existing code with equality operator?

孤街浪徒 提交于 2021-01-20 14:13:48
问题 I ran into this while debugging this question. I trimmed it down all the way to just using Boost Operators: Compiler Explorer C++17 C++20 #include <boost/operators.hpp> struct F : boost::totally_ordered1<F, boost::totally_ordered2<F, int>> { /*implicit*/ F(int t_) : t(t_) {} bool operator==(F const& o) const { return t == o.t; } bool operator< (F const& o) const { return t < o.t; } private: int t; }; int main() { #pragma GCC diagnostic ignored "-Wunused" F { 42 } == F{ 42 }; // OKAY 42 == F

Boost bimap fails to compile with gcc 10, c++20. Looking for temporary fix

无人久伴 提交于 2021-01-19 05:46:29
问题 With gcc 10.1 and boost 1.73.0, the following code #include <boost/bimap.hpp> int main() { boost::bimap<int, int> lookup; } fails to compile with flags -O2 --std=c++20 , but will succeed with flags -O2 -std=c++17 (verified with compiler explorer). This is possibly related to the following issue: https://github.com/boostorg/bimap/pull/15 (deprecated std::allocator<void> ) Is there some workaround I can use for now to get this code to successfully compile with --std=c++20 ? 回答1: The reason