c++20

Why is ranges::ostream_iterator default-constructible?

独自空忆成欢 提交于 2019-12-22 05:13:29
问题 This question follows a discussion in the comments here. In Eric Niebler's ranges-v3 library (which is sort-of becoming part of the standard for C++20), ranges::ostream_iterator is default-constructible - without an ostream. How come? I thought that "dummy" construction with effective construction later is an anti-pattern in C++, a wart we are gradually getting rid of. std::ostream iterator can only be constructed with a stream (for now - before C++20). And it's not as though we can do

std::is_constant_evaluated behavior

我们两清 提交于 2019-12-22 01:28:13
问题 GCC9 already implements std::is_constant_evaluated . I played a little bit with it, and I realized it is somewhat tricky. Here’s my test: constexpr int Fn1() { if constexpr (std::is_constant_evaluated()) return 0; else return 1; } constexpr int Fn2() { if (std::is_constant_evaluated()) return 0; else return 1; } int main() { constexpr int test1 = Fn1(); // Evaluates to 0 int test2 = Fn1(); // Evaluates to 0 int const test3 = Fn1(); // Evaluates to 0 constexpr int test4 = Fn2(); // Evaluates

the purpose of the -Wlifetime flag?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-21 17:38:39
问题 What is the purpose of the -Wlifetime compile flag in clang ? The information I found on the Internet about it are very vague. Is this any noticeable feature? 回答1: This flag analyzes the local file to see if the code may use pointers to objects that are dead. You can see Herb Sutter cppcon video on YouTube where he explains this very well: https://youtu.be/80BZxujhY38 来源: https://stackoverflow.com/questions/52662135/the-purpose-of-the-wlifetime-flag

Is compiler allowed to call an immediate (consteval) function during runtime?

末鹿安然 提交于 2019-12-21 04:43:30
问题 This might be a stupid question, but I am confused. I had a feeling that an immediate ( consteval ) function has to be executed during compile time and we simply cannot see its body in the binary. This article clearly supports my feeling: This has the implication that the [immediate] function is only seen at compile time. Symbols are not emitted for the function, you cannot take the address of such a function, and tools such as debuggers will not be able to show them. In this matter,

C++2a contract programming and compilers

久未见 提交于 2019-12-21 04:08:18
问题 I'm interested in studying the recently accepted contract programming for C++20 for learning and investigation purpose. As I'm looking around for compiler support, I'm disappointed to not find any. Both gcc and clang are quite clear they do not support this feature within their --std=c++2a mode. Since the approval is pretty recent, I'm not too surprised that current compilers do not support the exact semantic proposed. What is more surprising to me though is that there is absolutely nothing,

Why do we need the spaceship <=> operator in C++?

耗尽温柔 提交于 2019-12-19 05:52:58
问题 Why do we need such an operator in C++ and how is it useful in modern C++ programming? Any real world code examples where this can be applied will help. This question is geared to understand the practical application in real world without reading wordy proposal from Herb Sutter. No offense to the proposal though. 回答1: I'll give you three points of motivation, just off the top of my head: It's the common generalization of all other comparison operator (for totally-ordered domains): > , >= , ==

Why will std::rel_ops::operators be deprecated in C++20?

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-19 05:06:38
问题 According to cppreference.com, std::rel_ops::operator!=,>,<=,>= will be deprecated in C++20. What's the rationale behind? 回答1: In C++20, you get three-way comparison (operator <=> ), which automatically "generates" default comparisons if provided: struct A { // You only need to implement a single operator. std::strong_ordering operator<=>(const A&) const; }; // Compiler generates all 6 relational operators A to1, to2; if (to1 == to2) { /* ... */ } // ok if (to1 <= to2) { /* ... */ } // ok,

Reusing data member storage via placement new during enclosing object's lifetime

佐手、 提交于 2019-12-18 18:09:18
问题 This bounty has ended . Answers to this question are eligible for a +100 reputation bounty. Bounty grace period ends in 15 hours . walnut is looking for an answer from a reputable source . This is a follow-up to my previous question where I seem to have made the problem more involved than I had originally intended. (See discussions in question and answer comments there.) This question is a slight modification of the original question removing the issue of special rules during construction

Reusing data member storage via placement new during enclosing object's lifetime

三世轮回 提交于 2019-12-18 18:09:12
问题 This bounty has ended . Answers to this question are eligible for a +100 reputation bounty. Bounty grace period ends in 15 hours . walnut is looking for an answer from a reputable source . This is a follow-up to my previous question where I seem to have made the problem more involved than I had originally intended. (See discussions in question and answer comments there.) This question is a slight modification of the original question removing the issue of special rules during construction

Can I take the address of a function defined in standard library?

守給你的承諾、 提交于 2019-12-17 18:34:13
问题 Consider the following code: #include <cctype> #include <functional> #include <iostream> int main() { std::invoke(std::boolalpha, std::cout); // #1 using ctype_func = int(*)(int); char c = std::invoke(static_cast<ctype_func>(std::tolower), 'A'); // #2 std::cout << c << "\n"; } Here, the two calls to std::invoke are labeled for future reference. The expected output is: a Is the expected output guaranteed in C++20? (Note: there are two functions called tolower — one in <cctype> and the other in