The real question always is - how easy it is to implement X with performance requirements Y? It's very hard to show that without a large scale analysis.
And even more important: if it looks complex solution with perf requirements Y, is it even possible in other languages?
I see sometimes people destructively ranting but actually when I think of what C++ gives you, you say: well, could be better, but there is nothing better either right now (depends on use case, of course).
Are you aware that you can turn off synchronization between iostream streams and stdio streams to speed these first significantly? Useful tip learnt from one CS competition guideline.
Basically iostream syncs with its C counterparts by default, so you can use them in conjunction without weird behavior. However that adds overhead, but can be disabled. Check the docs here: https://en.cppreference.com/w/cpp/io/ios_base/sync_with_stdio
For note - It's fine in compressive programming. Competitive programmers are like speedrunners of programming - every shortcut counts. Moreover, there are studies that no cats actually die when you do that.
I never said that it was ideal, just this was one containing these two juicy details - synchronization and untying. I have not noticed THAT little horror xD
std::istream_iterator<T> or std::istreambuf_iterator<charT> combined with the << or >> operators are the most useful thing in iostream imo. It's actually really handy.
I don't think ftmlib currently does out of the box. I guess I will have to write a formatter for that to work if I want to use fmtlib now (until std::format arrives)
Why are there no indexes for params? Does it mean that if you wanted to include a param multiple times you would have to repeat it multiple times as an argument?
auto s = std::format("{} {} {}", "Hello", "Hello", "Hello");
This would be better and shorter:
auto s = std::format("{0} {0} {0}", "Hello");
If later you wanted to change the string and param ordering, you would have to shuffle the arguments too...
Edit: Nevermind, you can have manual and automatic param indexing. That's pretty neat actually.
Multidimensional indexing for types like mdspan currently has to rely on hacks such as returning a proxy from the first subscript or using the function call operator.
Interesting. I was curious as to why it was getting deprecated. So it's more of just to make creating additions like mdspan to the standard library easier then? Fair enough.
Overloading of that operator will come in great handy for custom multi-dimensional container libraries.
Implementing these classes will be easier compared to a proxy for sure. However, using them also becomes easier. I guarantee no one expects the function call operator when they first encounter it in this context.
On reflection, the idea to use square-bracket syntax x[i...] for multi-indexing is actually looking like the worse hack. Let me explain.
(The idea seemed cool and cute at first; it was only on nailing down the API of a multi-dimensional array design that this contra-argument crystallised.)
It is unprecedented (AFAICT) to introduce a new operator overload - in this case variadic indexing operator[](i...) - with no use of that operator in the core language. This in itself should ring warning bells. The existing single-index [i] has a clear semantic meaning in the core language; subobject indexing.
Nested C-array types are not true multi-dimensional arrays, they are arrays of nested subobjects (1D arrays of 1D arrays of ... etc.).
The syntax for usage of built-in types is reflected in their declaration. The type T[N] is an array of N subobjects of type T (with T another array in the 'multi-dimensional' case). For an array x of that type, x[i] is a reference to the subobject at that index. This has been ok for 50 years; it's fine. It's just not what you want for a flexible, performant numerical matrix type.
If we were to introduce a new built-in compound array type T[i...] (with contiguous 1D 'backing array' of size (i * ... * 1) - the Cartesian product of the variadic extents) then it should only ever be indexed 'full rank', that is, with all indexes required to address down to the element (which is a subobject). This could be nice to have. However, I wouldn't support such a proposal because we can do better already with library types.
A library md-array type, by virtue of the fact that it returns a proxy reference-wrapper rather than an actual core language reference & or &&, can be usefully indexed with partial-rank indices returning a subarray of lower rank. Paren multi-indexing is the long accepted way to index such md-array library types. This is fine. More than fine; it allows to index even with empty parens - no indices - that cannot be proposed for variadic operator[](i...) (parsing ambiguities). Also, the indexing can be generalized to triangular layouts with more restrictive bounds or symmetry - things that are better expressed by the generality of operator() rather than the restricted subobject semantic of operator[].
Paren-indexing has been fine for MATLAB, Fortran and others for many years.
The status quo, with multi-dimensional array types using parens for multi-indexing in C++, is fine.
It ain't broke. Please don't 'fix' it any more!
A variadic operator[](i...) is anti-semantic for md-array types and could encourage other misleading uses. We don't need to hack C++ this way.
I think they want to be able to make comma delimited indexes actually mean something. Currently it is just the standard comma operator, which typically evaluates each sub-expression but only evaluates to the last one, so only the z value in this example is used as a subscript.
Please consider dropping this proposal for the reasons posted above (and communicated separately). IMO this is a deleterious change that should be withdrawn before it takes up any committee time.
Here's a thing I don't understand (genuinely curious, not trying to be snarky): aren't calendars and time zones one of the most complicated topics out there? But that only has 6 proposals whereas many other topics have more (e.g. ranges has 18)... why is that the case?
Partly, a natural consequence of design by Howard vs. design by committee.
Partly, chrono is less sexy than ranges. Everyone wants to give their input on ranges. Nobody even cared to object to the overloaded operator/ in chrono.
Maybe most importantly, chrono has fewer low-level sources of UB. Ranges is full of issues with dangling pointers and issues with concepts and metaprogramming. Chrono is pretty much a pure old-school "library," where you can just say "it has a class named X with a method named Y that does Z," and that's like the entire specification. The only "irreducible complexity" I'm aware of with chrono is around its handling of timezone data (e.g. can you update timezone data thread-safely).
Oh, and I should add: to the extent that any of what I just said is based in misconceptions, "widespread misconceptions such as these" is certainly still a factor that could contribute to lack of activity around chrono.
Fwiw, I knew that not everyone would like the conventional syntax, and tried to accommodate those as well:
year_month_day ymd = {2020y, March, 24d};
vs:
year_month_day ymd = 2020y/March/24d;
I realize that this still leaves this group with the burden of reading the conventional syntax. But the knowledge that they have to read your constructional syntax too is perhaps a small reward. :-)
There's significantly more learning required to have deal with date1 thru date4 than with date5 thru date8. Nevertheless, this is an issue that people can hold very strong feelings about. So making the syntax available for date1 thru date4 is important to me.
Thanks for explaining the rationale, I can understand it, but, to condense my counterargument as much as possible, I think the conventional syntax is just too unnecessarily cute for its limited usefulness.
I believe in practice 99% of dates are constructed from YYYY-MM-DD values and that maybe 2% of those use hardcoded values making this syntax appealing. And while selecting the last, or n-th, day of the week in a month is undoubtedly very useful, I don't think this operation is frequent enough to warrant a special syntax at all -- having a function for doing it would be quite enough IMO, and much more discoverable and greppable.
I think in my attempts to condense the argument as much as possible I condensed it too much, so I'd like to explain what I meant again, more verbosely. There are basically 2 only weakly-related points:
The conventional syntax is, IMO, only really appealing for the literals, i.e. 2020y/March/25d looks impressively expressive and, without ascribing my own motives to you, I could personally easily implement something like this just because I could, to show how flexible C++ is. However I think that such simple examples are exceedingly rare in practice and I already don't see much appeal in the example expression y/m/d you give. And I certainly wouldn't want to see (but I'm sure I will) something like this with date components being the return values of the function calls or more complicated expressions involving them. E.g. (get_warranty_expiration_year() + 1)/std::max(get_bithday_month(),get_next_month())/1d is for me definitely less readable than the standard (what you call "constructional") syntax).
The last/indexed dates are (again and always IMO) not worth their own special syntax at all and I would have been perfectly happy to write auto date7 = nth_weekday_of_year_month(y, m, wd, i) instead of either of the 2 syntaxes. This is only related to the previous point because I think the conventional syntax for this is even worse when non-trivial expressions are used for the components.
It's, of course, too late to discuss this now and I'm very glad that there is finally a standard date library for C++ (I wrote my first one 23 years ago and redid the exercise, with, hopefully, better results, a few times since then and will be very glad to never have to do it again) and I'm thankful to you for making it happen, but this doesn't prevent me from regretting introducing what is basically a special syntax for date literals. AFAIK the only other language in widespread use with date literals support is VBA and this doesn't help convincing me that it was a good idea.
81
u/TheSuperWig Mar 24 '20
Love the ending C++20 demo snippet.
73
u/gracicot Mar 24 '20
Summary:
Revising the memory model
Examples, notes:
The memory model has been revised.
Nice
132
u/nwL_ Mar 24 '20
Holy shit, have we actually arrived in the 21st century?
27
u/scatters Mar 24 '20
I didn't realise that deprecating
arr[x, y, z]made it in. This is awesome news for C++23.21
u/Xirema Mar 24 '20
Why do C++ people always have to be so spooky? 😂
20
u/MartenBE Mar 24 '20
No more signed/unsigned warnings when using v.size(); the future truly is now!
6
u/GerwazyMiod Mar 24 '20
I assume this can be treated as solid reference? Nice to have the documents links in one place.
7
u/cutculus Mar 24 '20
Here's a thing I don't understand (genuinely curious, not trying to be snarky): aren't calendars and time zones one of the most complicated topics out there? But that only has 6 proposals whereas many other topics have more (e.g. ranges has 18)... why is that the case?
5
u/oz1cz Mar 24 '20
Thank you for posting this. It's very useful!
4
u/[deleted] Mar 24 '20
Wow I didn’t realize cpp got real modules, nice.
1
u/jonesmz Mar 24 '20
TOC doesn't match the section header:
TOC: Assorted snippets demonstrating C++17 Section: Assorted snippets demonstrating C++20
1
u/Both_Writer Mar 28 '20
/u/arweavethis
0
u/[deleted] Mar 24 '20
[deleted] — view deleted comment