c++20

Does C++20 mandate source code being stored in files?

断了今生、忘了曾经 提交于 2020-06-09 08:09:27
问题 A slightly strange question, however, if I remember correctly, C++ source code doesn't require a file system to store its files. Having a compiler that scans handwritten papers via a camera would be a conforming implementation. Although practically not making that much sense. However C++20 now adds source location with file_name. Does this now imply that source code should always be stored in a file? 回答1: No, source code doesn't have to come from a file (nor go to a file). You can compile

Does C++20 mandate source code being stored in files?

扶醉桌前 提交于 2020-06-09 08:08:51
问题 A slightly strange question, however, if I remember correctly, C++ source code doesn't require a file system to store its files. Having a compiler that scans handwritten papers via a camera would be a conforming implementation. Although practically not making that much sense. However C++20 now adds source location with file_name. Does this now imply that source code should always be stored in a file? 回答1: No, source code doesn't have to come from a file (nor go to a file). You can compile

Does C++20 mandate source code being stored in files?

喜你入骨 提交于 2020-06-09 08:08:39
问题 A slightly strange question, however, if I remember correctly, C++ source code doesn't require a file system to store its files. Having a compiler that scans handwritten papers via a camera would be a conforming implementation. Although practically not making that much sense. However C++20 now adds source location with file_name. Does this now imply that source code should always be stored in a file? 回答1: No, source code doesn't have to come from a file (nor go to a file). You can compile

Why don't I need to specify “typename” before a dependent type in C++20?

人走茶凉 提交于 2020-06-09 07:52:31
问题 This bit of code compiled in C++20 (using gcc 10.1) without using the typename keyword before the dependent type std::vector<T>::iterator . Why does it compile? #include <vector> template<typename T> std::vector<T>::iterator // Why does this not require "typename" before it? f() { return {}; } int main() { auto fptr = &f<int>; } code playground 回答1: One of the new features in C++20 is Down with typename. In C++17, you had to provide the typename keyword in nearly all † dependent contexts to

Familiar template syntax for generic lambdas

生来就可爱ヽ(ⅴ<●) 提交于 2020-06-08 18:59:11
问题 For c++20 it is proposed to add the following syntax for generic lambdas p0428r2.pdf auto f = []<typename T>( T t ) {}; But the current implementation in gcc 8 did not accept the following instantiation: f<std::string>(""); Is that a implementation bug in gcc or a missing language feature? I know we talk about a proposal and not a approved specification. Complete example ( with comparison to template function syntax ): template <typename T> void n( T t ) { std::cout << t << std::endl; } auto

Module dependencies when using template function specializations

血红的双手。 提交于 2020-05-28 09:23:32
问题 Please check out the following code snippet (pseudo code, didn't compile it): A.h template <typename T> void SubTest(T t) = delete; template <> void SubTest(int i) { cout << i; } template <typename T> class MyClass { public: void Test(T t) { SubTest(t); } } B.h class X{}; template <> void SubTest(X x) { cout << x; } As you can see I want a class template method to call a function template. That function is specialized in various ways. Some of the specializations are located in A.h, some in

Aggregate initialization, set member pointer to same struct member

风流意气都作罢 提交于 2020-05-26 14:38:27
问题 Is it possible to use aggregate initialization to make a pointer aptr point to a which is a member of the same struct ? struct S { int a; int* aptr; }; int main() { S s = { .a = 3, .aptr = &a //point aptr to a }; return 0; } The question is for both C and C++ . 回答1: A working initialization would be: struct S { int a; int* aptr; }; int main() { struct S s = {.a = 3, .aptr = &s.a}; printf("%d", *s.aptr); } Working samples: C11 GNU C++2a GNU Regarding the correctness of the initialization: For

What are the mechanics of coroutines in C++20?

本秂侑毒 提交于 2020-05-24 08:46:25
问题 I was trying to read the documentation (cppreference and the standard documentation on the feature itself) on the sequence of operations that get called when a coroutine function is called, suspended, resumed and terminated. The documentation goes into depth outlining the various extension points that allow library developers to customize the behavior of their coroutine using library components. At a high-level, this language feature seems to be extremely well thought out. Unfortunately, I'm

Dependencies when using C++20 conceptual template function specialization

独自空忆成欢 提交于 2020-05-14 05:53:27
问题 I was doing some tests with the following C++20 code (built with current GCC10): template <typename ToT, typename FromT> ToT myfunction(const FromT& pFrom) = delete; template <typename ToT, typename FromT> struct myclass { inline ToT myclassmethod(const FromT& pFrom) { return myfunction<ToT, FromT>(pFrom); } }; /* C++20 concepts code */ template <std::same_as<std::string> ToT, std::integral FromT> inline ToT myfunction(const FromT& pFrom) { return std::to_string(pFrom); } template <std::same

Dependencies when using C++20 conceptual template function specialization

十年热恋 提交于 2020-05-14 05:52:07
问题 I was doing some tests with the following C++20 code (built with current GCC10): template <typename ToT, typename FromT> ToT myfunction(const FromT& pFrom) = delete; template <typename ToT, typename FromT> struct myclass { inline ToT myclassmethod(const FromT& pFrom) { return myfunction<ToT, FromT>(pFrom); } }; /* C++20 concepts code */ template <std::same_as<std::string> ToT, std::integral FromT> inline ToT myfunction(const FromT& pFrom) { return std::to_string(pFrom); } template <std::same