News for hackers. Stuff that matters.
Re:C++20 has been approved by dgellow on Sunday September 06, 2020 @06:59AM (#24390499)
Has anyone anything positive to say about C++, and more specifically C++20?

We all know the negative parts, any C++ related thread is always full of people repeating them over and over. What about some celebration time for now? A huge milestone for the language has been reached with C++20, can we share something positive about it for once?

Re:C++20 has been approved by UncleMeat on Sunday September 06, 2020 @08:56AM (#24391007)
> Has anyone anything positive to say about C++

IMO, C++ has the following huge benefits.

1. Ambient performance. If you need a fast program and don't have a tight loop you can optimize, C++ makes ordinary behavior fast.

2. RAII is a very clean and understandable design paradigm.

3. The idiom of using "const" everywhere plus widespread copying of values makes "spooky action at a distance" way less common when doing OOP or imperative programming.

Re:C++20 has been approved by pdpi on Sunday September 06, 2020 @08:39AM (#24390938)
Pointer types in C can mean a bazillion different things, and C++ provides you with zero cost abstractions to unambiguously represent many of the useful ones (references vs owned pointers vs shared pointers vs arrays, off the top of my head), that alone makes it worth the price of admission for me.

RAII is a damned useful idiom too, makes writing safe code that much easier.

Tooling for C++ is pretty damn good in all the usual platforms

Re:C++20 has been approved by virgilp on Sunday September 06, 2020 @10:09AM (#24391399)
They are not zero-cost, but yes, it's good that they were added
Re:C++20 has been approved by vlovich123 on Sunday September 06, 2020 @10:12AM (#24391419)
unique_ptr isn’t 0-cost?
Re:C++20 has been approved by Rusky on Sunday September 06, 2020 @10:27AM (#24391535)
This is probably not what was meant, but interestingly unique_ptr actually isn't zero-cost on some ABIs: https://www.youtube.com/watch?v=rHIkrotSwcc
Re:C++20 has been approved by the_svd_doctor on Sunday September 06, 2020 @10:26AM (#24391529)
Close but not exactly https://youtu.be/rHIkrotSwcc
Re:C++20 has been approved by mhh__ on Sunday September 06, 2020 @12:34PM (#24392518)
https://gcc.godbolt.org/z/TMYso5

If you pass a unique_ptr it has to have redirection through a pointer, so it isn't quite zero cost.

However, since the entire point of using a smart pointer is to control the ownership I'm not that bothered.

Re:C++20 has been approved by shultays on Sunday September 06, 2020 @02:33PM (#24393546)
Zero cost compared to a raw pointer. You are comparing apple and oranges if you compare it to a regular variable.

It has a null check on destructor (and a delete of course), which is good enough for "zero cost" to me

Re:C++20 has been approved by shultays on Sunday September 06, 2020 @03:02PM (#24393775)
Hmm, now i thinked about this one but perhaps it is fair to compare unique_ptr to regular variables as well.

I guess it is more complicated than i thought, but i think it is fair to compare them pointers too. Because most of the time you will probably need to store it as a pointer

Re:C++20 has been approved by tempsolution on Sunday September 06, 2020 @01:14PM (#24392869)
What are you talking about? unique_ptr contains a pointer, that's it. Yes, to represent a pointer you have to contain a point. Passing it on or not makes zero difference and using a website that return unoptimized C++, is not a good place to gather intel. unique_ptr is zero cost, unless you use it across library boundaries without LTO.
Re:C++20 has been approved by vvanders on Sunday September 06, 2020 @10:16AM (#24391456)
shared_ptr certainly isn't, last I looked at it there was some significant performance overhead since it's required to be thread safe.
Re:C++20 has been approved by pdpi on Sunday September 06, 2020 @10:58AM (#24391765)
Whether shared_ptr are thread safe is an... interesting question. If you have to ask it the answer is “no”.

At any rate, the definition of “zero cost” isn’t “it’s the same as a raw pointer”. Rather, it should be read as “its cost is the same as the equivalent functionality rolled by hand”. Shared_ptr implements a ref counting mechanism, which, absent a real GC, is necessary for actual shared ownership.

Re:C++20 has been approved by vvanders on Sunday September 06, 2020 @03:46PM (#24394108)
> To satisfy thread safety requirements, the reference counters are typically incremented using an equivalent of std::atomic::fetch_add with std::memory_order_relaxed (decrementing requires stronger ordering to safely destroy the control block). [1]

That's why shared_ptr has horrible performance, the spec requires that the control block is thread-safe. Perf tanks due to the atomic load/stores. If you roll your own with a standard load/store you'll see significant performance increase which means it's definitely not zero-cost.

This is why Rust explicitly went with Arc/Rc[2] so you don't have to pay that cost(although ambiguous ownership I would argue is a pattern you should try to eliminate anyway).

[1] https://en.cppreference.com/w/cpp/memory/shared_ptr

[2] https://doc.rust-lang.org/std/rc/struct.Rc.html / https://doc.rust-lang.org/std/sync/struct.Arc.html

Re:C++20 has been approved by gpderetta on Wednesday September 09, 2020 @06:35AM (#24419542)
formally the answer to the question of "is shared pointer thread safe" is "no": modifying a shared pointer (for example by assigning to it) while another thread is reading (or writing) is UB (unless all accesses are done via the now deprecated std::atomic_* operations.

It is true that the ref count is kept atomically, which allows accessing two distinct shared pointers that happen to point to the same object from different threads. This is pretty much a requirement to support the baseline distinct object thread safety (aka "as safe as int), but it is not what the unqualified "thread safe" normally refers to.

/pedantic

Anyway, it is true that with shared_ptr sometimes you might end up paying for what you do not use, but doing otherwise would have made any use of shared_ptr in threaded applications extremely unsafe so it was felt that in this case the cost was worth it for a vocabulary type object.

Re:C++20 has been approved by virgilp on Sunday September 06, 2020 @03:53PM (#24394152)
> At any rate, the definition of “zero cost” isn’t “it’s the same as a raw pointer”. Rather, it should be read as “its cost is the same as the equivalent functionality rolled by hand”

What kind of definition is that? Zero cost is exactly that - 0 cost, the same performance as if you were not using the abstraction. The alternative to an abstraction is not "my hand-rolled implementation of said abstraction" - it is not using the abstraction, at all (but using lower-level mechanisms to achieve the same goal). 0-cost is used to tell people "you will still achieve the same performance by using the abstraction - and you gain additional benefits (safety, readability etc)". If I can get better performance with raw pointers, then smart pointers are not zero cost (it's still a good idea to use them instead of raw pointers! Just, let's stop pretending they are zero-cost)

Re:C++20 has been approved by gumby on Sunday September 06, 2020 @10:57AM (#24391753)
Yes but imagine writing thread safe refcounted GC in C. It’s painful and easy to forget some of the handshaking.

Most of the abstractions (E.g. iterations) are zero cost as opposed to additional functionality like shared pointers or resizable vectors.

Re:C++20 has been approved by tempsolution on Sunday September 06, 2020 @01:16PM (#24392883)
Being able to read is helpful. They are "zero cost abstractions". Yes, they are not zero cost, big surprise (I thought they wouldn't produce assembly instructions). A pointer is an indirect reference. But the abstraction around them is zero cost:

i.e. there is no way to end up with faster code that does the same thing, without using the abstraction.

This is the very definition of zero cost abstractions.

Re:C++20 has been approved by AlexSW on Sunday September 06, 2020 @07:14AM (#24390564)
As someone that really likes C++ templates (no other language seems to come close in power for such a compile-time typed system), I'm particularly looking forward to concepts, and I believe (correct me if I'm wrong) that they will make compiler errors for templated code much more straightforward, which will be a nice quality of life improvement even if not using concepts directly.
Re:C++20 has been approved by dgellow on Sunday September 06, 2020 @08:23AM (#24390873)
> I believe (correct me if I'm wrong) that they will make compiler errors for templated code much more straightforward

Oh yes, that would really be awesome if that's the case. Wikipedia has a section regarding "Compiler diagnostics" when Concepts are used, the precision of the error message demonstrated is SO MUCH better than what you get with templates!

https://en.wikipedia.org/wiki/Concepts_(C%2B%2B)#Compiler_di...

Code example:

    std::list<int> l = {2, 1, 3};
    std::sort(l.begin(), l.end());

Example with templates:

    In instantiation of 'void 
    std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = std::_List_iterator<int>; _Compare = __gnu_cxx::__ops::_Iter_less_iter]':
    error: no match for 'operator-' (operand types are 'std::_List_iterator<int>' and 'std::_List_iterator<int>')
    std::__lg(__last - __first) * 2,
    ...
    ... // continues for 50+ lines

Example with concepts:

    error: cannot call function 'void std::sort(_RAIter, _RAIter) [with _RAIter = std::_List_iterator<int>]'
    note:   concept 'RandomAccessIterator()' was not satisfied
Re:C++20 has been approved by greggman3 on Sunday September 06, 2020 @08:21AM (#24390862)
That strikes me as Stockholm Syndrome. No one in their right mind would consider C++ templates a good design for a meta-language. In fact the majority of older template patterns aren't based on good language design but hacks around conditional compiling via arrays of size -1 and crap like that.

A good meta programming language would be one that's as easy to program as a general language. lisp, nim, etc...

Re:C++20 has been approved by _se on Sunday September 06, 2020 @08:44AM (#24390959)
I think this is.. quite wrong. I don't think C++ is an amazing language (it's not in my top 3 personally, but I do work with it daily), but templates are one of the best things about the language IMO.

I have a lot of experience with many different types of metaprogramming (cl macros, Rust macros, template Haskell (and Typeable/Generic), ... even CLR code generation) and C++ templates are better than everything I've used other than Common Lisp once you really understand them. A really common C++ theme I see is people that don't understand things railing against them (I used to be in this camp myself, so I can identify with the sentiment).

Templates allow you to choose at will between nominal/structural subtyping (in a way), perform type-level logic, generate code that can be thread-safe or lock-free at the caller's whim... They are very powerful, much more than most devs realize, and if you understand C++, writing them is not difficult.

The "really understand them" part is, of course, the hard part. You need to understand the core language and the template language to be effective with them. I can see why even some experienced C++ developers shy away from templates.

Re:C++20 has been approved by Dylan16807 on Sunday September 06, 2020 @09:48AM (#24391257)
Even if they're a good general design, half the uses of SFINAE are absolutely insane and from what I understand it's significantly harder than it should be to make a fully generic template across all kinds of edge case and corner case types.

The attitude with templates seems to be that if something is at all possible with hacks then there doesn't need to be any language support added, even if it would be vastly simpler to read and write and probably to compile. I don't think that works out well.

Re:C++20 has been approved by northwindfoo on Sunday September 06, 2020 @10:40AM (#24391642)
I wouldn't call myself a c++ expert but I have used the language for a long time. In my opinion, templates have a lot of awesome uses outside of SFINAE and if you find yourself reaching for SFINAE, that's probably code smell and you can probably simplify the design elsewhere to avoid it.

Generally I find the best use of templates is the most basic: you want to write some code that operates on duck-types. As long as one is able to control themselves and pick the right use cases for maintainability, templates are simple enough. In my experience, this is very doable.

Concepts are also a really cool way to rein in which types are accepted as a template parameter and have a lot of potential to make templates easier to understand and teach. To me, this is the most exciting c++20 feature.

Re:C++20 has been approved by _se on Sunday September 06, 2020 @11:49AM (#24392163)
With C++17, if constexpr removed most of the necessity for crazy SFINAE uses. Before that it was definitely worse. C++20 adds even more to make things more "semantic"; they're constantly adding better language support for templates.
Re:C++20 has been approved by qppo on Sunday September 06, 2020 @11:29AM (#24392010)
No one disputes that meta programming is useful. What is disputed is C++ templates being a "good" way to meta program.

I certainly understand metaprogramming, but navigating very dense C++ templates is one of the most complicated things I've had to do in my life. One or two levels of abstraction and you will lose your ability to hold everything you need to solve a problem in your head, and after a few dozen lines the source code is unreadable.

> You need to understand the core language and the template language to be effective with them.

this is a bug.

Re:C++20 has been approved by _se on Sunday September 06, 2020 @11:54AM (#24392206)
I guess that just hasn't been my experience at all. I don't think a nested C++ template is any more complicated than a CL macro with a corresponding level of nested `.

I also don't really see how requiring understanding of a language to generate that language could be considered a bug - every macro system carries that requirement. C++ just happens to be (much) more complex than most languages (and I do agree that a large amount of that complexity is probably not necessary).

Re:C++20 has been approved by qppo on Sunday September 06, 2020 @01:38PM (#24393072)
I'd argue it's significantly more complex because you don't have access to the C++ AST, templates are ultimately non-hygienic macros, their results are invisible to both developer and user, and potential errors are inscrutable. They're difficult to abstract over, and you will wind up repeating yourself quite often since you can't just write normal C++ code with C++ includes for helper functions and data structures.

I should be more clear about what I meant on the bug. C++ templates force you to understand the entirety of the language at once and hack around its edges because it doesn't support actual meta programming. It's hard for me to come up with a concrete example, but my experience writing some advanced compile-time evaluation with SFINAE patterns left me forgetting how things worked within minutes of typing them. Compare to say Rust, where the generics implementation is much cleaner and macro system better flushed out and easier to read/understand. Or the LISPs where your macro is just more LISP code.

And not for nothing, templates destroy compile times. They take a long time to write and edit and make everyone else using them work slower. All told, templates do not make it easier to write C++ except in trivial cases and first-order abstractions.

Re:C++20 has been approved by nikki93 on Sunday September 06, 2020 @12:11PM (#24392323)
The kind of stuff you are able to do with entt (https://github.com/skypjack/entt#code-example) like `entities.view<Position, Sprite>.each([&](auto &pos, auto &vel) { ... });` is super awesome IMO. And then it compiles down to just directly inlined straight walks over the respective arrays (looking in godbolt.org). It's basically almost optimal for it.

I do agree that you can go insane with templates and have a bad time. You just have to choose well. However if you have a problem with there existing other problematic code in the same language (that may be separate from your code), then C++ is maybe not the best fit. There's a lot of C++ out there.

Re:C++20 has been approved by ssvss on Monday September 07, 2020 @12:04AM (#24396545)
Any recommendation for books/blogs/videos/code to learn about this ?
Re:C++20 has been approved by SloopJon on Sunday September 06, 2020 @10:55AM (#24391742)
I consciously avoided C++ since the late 90s, lest its litany of accidental complexities crowd other more important things out of my brain. I was drawn into it recently by a work assignment, and have been pleasantly surprised by modern C++.

I find it much more pleasant to write, e.g., ODBC client code in C++ than in C, and templates have a lot to do with that. I'm not an expert with Lisp macros or other reportedly superior meta-languages, but I will say that when I write generic code in C# or Java, I really miss the power of C++ templates.

Template syntax is pretty awful, and accomplishing what I want can involve some really strange idioms, like SFINAE. The ergonomics are slowly improving with type deduction, constexpr, and now concepts.

Re:C++20 has been approved by HelloNurse on Sunday September 06, 2020 @08:39AM (#24390940)
Exactly, old hacks and techniques. Thirty years ago, C++ template were limited and clever people struggled with their limitations, but now there are vastly simpler ways to do much more.
Re:C++20 has been approved by gumby on Sunday September 06, 2020 @11:02AM (#24391792)
As Stroustrup said to me years ago, “yes, I wanted a macro system but that word had already been colonized by the preprocessor, and we needed to avoid new keywords as much as possible if people were going to try it out.

Nowadays C++ and a powerful multi-paradigm programming language quite straightforward to use if you forget the word “C” in its name.

If would be a good instructional language if people didn’t fall into the lazy “a horse is a king of animal” OO trope.

Re:C++20 has been approved by einpoklum on Sunday September 06, 2020 @08:37AM (#24390932)
It's true the templates weren't designed as a meta language. C++ has a lot of baggage.

But, at least, you no longer have to iterate over arrays with size-1, (size-1)-1 etc these days. We have variadic template expansion, we have the (ugly, still not decent design, but useful) std::integer_sequence , and better still - we have pretty strong constexpr capabilities.

Re:C++20 has been approved by Expert-007 on Monday September 07, 2020 @01:03AM (#24396731)
Such examples speak more to C++ templates as a mechanism for capturing usage patterns in a convenient form, thus effectively creating a special-purpose, domain-specific language, than they speak to such templates as a meta-language. "Meta" means "information about information", so a meta-language in this case would describe the mechanisms used to capture such patterns, not the patterns themselves.

I do meta every day, meta-meta often, and triple-meta occasionally. The rules language for my Expert System is a true meta-language, because I designed it to (among other things) specify the manipulation of computer languages. So its domain knowledge is about the nature of computer languages and how to automate their assessment / analysis, transformation / re-engineering, translation, and generation.

To give a real-life example, we used our Expert System to automate the translation of complex compiler front- and back-end code from a proprietary system language to C++ for a major computer manufacturer. The translation rules don't really care what the code is doing; they care how the code is doing it. The compiler team created new templates and classes to provide the functionality their system language had that C++ doesn't, and we adjusted our translation rules to ensure that the translated code invokes those templates and classes in a clear, effective, efficient, and readable way.

Re:C++20 has been approved by otabdeveloper4 on Sunday September 06, 2020 @08:46AM (#24390974)
> ... easy to program as a general language. lisp, nim, etc...

C++ templates are just a compile-time lazily-evaluated Lisp.

As always, the criticism of C++ comes down to "programming is hard, let's go shopping".

If you don't want to learn and you just want to do the bare minimum to keep your 8 hour coding job, there's already plenty of languages that nail this niche. C++ obviously is not for you, just move on and don't make a redundant comment.

Re:C++20 has been approved by greggman3 on Sunday September 06, 2020 @11:42PM (#24396451)
What an asinine comment. I guess if you're real programmer you'll program everything in brainfuck. Isn't not hard to fathom that some language designs are easier to express and easier to understand than others and still get the same things done. C++'s meta programming via templates is clearly a hack and was never designed to do what it's being abused to do.
Re:C++20 has been approved by zarkov99 on Sunday September 06, 2020 @09:06AM (#24391052)
Other than lisp, which production ready languages do you think do it better?
Re:C++20 has been approved by rwmj on Sunday September 06, 2020 @09:43AM (#24391226)
I really liked camlp4 (an early fork of which is available as camlp5, but no longer a fundamental part of the OCaml ecosystem). I was able to use camlp4 to implement Erlang-style bitstrings, and they were as efficient as if you had written the most efficient code by hand.

https://people.redhat.com/~rjones/bitstring/html/Bitstring.h...

Re:C++20 has been approved by mhh__ on Sunday September 06, 2020 @12:41PM (#24392592)
> no other language seems to come close in power for such a compile-time typed system

D is far more powerful, especially when you consider that it's had working constraints for (?) something like a decade now.

Simple example, try to express this in C++ without a windows full of syntax-soup (https://d.godbolt.org/z/Toc8ob), the template constraint is one line, and I can pass anything into a template using alias be that templates, a string etc.

Passing strings into a templates is a very common trick for generating code at compile time in the D standard library, although it wouldn't work in C++ due to how slow C++ can be to compile some times.

Re:C++20 has been approved by nikki93 on Sunday September 06, 2020 @11:08PM (#24396307)
> Passing strings into a templates ... wouldn't work in C++ ...

https://www.youtube.com/watch?v=QM3W36COnE4 Here's an example of parsing regular expressions in C++ at compile time. Code here: https://github.com/hanickadot/compile-time-regular-expressio...

Re:C++20 has been approved by pjmlp on Monday September 07, 2020 @03:20AM (#24397326)
Sadly, D the language still needs to get their act together in what the language actually wants to be, and the eco-system suffers from this lack of direction.
Re:C++20 has been approved by HelloNurse on Sunday September 06, 2020 @08:35AM (#24390924)
Straightforward error messages are only an aspect of straightforward template definitions: the problem of restricting templates to suitable type parameters has the first general, explicit and well organized solution.
Re:C++20 has been approved by spacechild1 on Sunday September 06, 2020 @01:24PM (#24392943)
I am mostly writing audio applications where I need maximum performance because the time budget is extremely limited (usually 1.45 ms to compute the whole audio graph). I'm working on Pure Data, which is written in C89, but my own projects are all C++. Things which make C++ much more pleasant than C:

* RAII

* lambdas

* templates

* function overloading

* operator overloading (used judiciously)

* inheritance and interfaces (used judiciously)

* an extensive standard library

* exceptions (depends on the project)

For me, the advantages of C++ over C are obvious and IMO there's no reason to use C except for legacy projects or platforms which don't have a C++ compiler.

Of course, C++ has lots of warts and things to complain about, but OP asked for the positive things :-)

Re:C++20 has been approved by pjmlp on Monday September 07, 2020 @03:18AM (#24397301)
Many of those features were already available in Turbo C++ for MS-DOS back in 1993, hence why I never liked C and only wrote straight C code when required to deliver projects in various contexts written in C.
Re:C++20 has been approved by snarfy on Sunday September 06, 2020 @10:13AM (#24391427)
I did C++ for 10 years before moving on to C# for the next 10. I had an opportunity to work on a modern C++ project for a couple years and took it so that I could learn the new stuff. The team lead was a big C++ fan and used all the latest features with compiler set to c++17 standard.

I could go on about the bad parts, but the good parts

1. lambdas

2. constexpr

3. threads

These additions did make C++ feel a little more modern.

Re:C++20 has been approved by ainar-g on Sunday September 06, 2020 @07:14AM (#24390571)
If you use a tiny subset of C++, then you get a dialect of C with more type safety, namespaces, mostly-not-unsafe subtype polymorphism through class inheritance, and also okay parametric polymorphism through templates. That dialect will compile a bit slower (it's still C++ after all), but produce code which either has the same performance as C or is only slightly behind C.
Re:C++20 has been approved by shash on Sunday September 06, 2020 @10:37AM (#24391614)
Or often, faster than C, if you’re using compile time template expansion instead of runtime void* casts.
Re:C++20 has been approved by creativeCak3 on Sunday September 06, 2020 @12:07PM (#24392281)
Have been using it professionally for a little bit now. -RAII -Smart Pointers -Classes(or not, your choice) -Lambda Expressions -Amazing Standard Library -Lightning fast -A compiler that you can trust -Static types -Templates -Well defined semantics for pointers, references AND values. -Moving semantics.

And this is the "Vanilla" version of the features. In C++17 and C++20, there is all kinds of goodies like concepts and modules that I'm personally excited about.

Hate it all you want, but it's an amazing language.

Re:C++20 has been approved by jzwinck on Sunday September 06, 2020 @07:12AM (#24390552)
Yes! The spaceship operator (three way comparison a la strcmp) is very welcome, and the no_unique_address attribute will be helpful for people who care a lot about optimization. Simplifications like these really help, and don't take a programming language genius to utilize.
Re:C++20 has been approved by atombender on Sunday September 06, 2020 @12:31PM (#24392498)
I love the new modules.

In fact, it's the one major feature I'd love to start using right away that I know would be immediately useful, but the compiler support isn't there yet. According to this [1], Clang has partial support [2], while GCC has no support at all.

[1] https://en.cppreference.com/w/cpp/compiler_support

[2] https://clang.llvm.org/cxx_status.html

Re:C++20 has been approved by shultays on Sunday September 06, 2020 @10:51AM (#24391717)
It is a performant language that is relatively safe when you use safe practices. And quite mature with lots of library support
Re:C++20 has been approved by pjmlp on Sunday September 06, 2020 @11:29AM (#24392008)
Plenty,

Finally we got modules, concepts will put an end to the fame of endless kilometres of error messages and compile time programming almost allows for static reflection.

Re:C++20 has been approved by foxtacles on Sunday September 06, 2020 @07:16AM (#24390579)
Yeah, it's unfortunate! I love C++ personally, I've recently commented something positive in another thread:

https://news.ycombinator.com/item?id=24041406

Re:C++20 has been approved by asdfasgasdgasdg on Sunday September 06, 2020 @09:51AM (#24391281)
Looking forward to having access to coroutines. Also the <=> operator and ranges. Lots of really good stuff in this release.
Re:C++20 has been approved by einpoklum on Sunday September 06, 2020 @07:16AM (#24390578)
Yes, I have many positive things to say about C++.

It certainly has a lot of warts, but over the past decade, it has become easier and more straightforward to write code in various styles which used to be possible-but-a-pain (like functional programming), or not quite possible.

So with C++ you get performance + backwards compatibility + paradigm flexibility for the price of difficult, sometimes ambiguous syntax, some historical baggage you need to ignore, and slower compilation time. It's a decent tradeoff IMHO.

Specifically, regarding C++20:

* std::span is the best thing since sliced bread. How was this not in the library already? Cuh-razee... https://stackoverflow.com/q/45723819/1593077

* I'm happy that ranges support is inside the language. I can now `sort(my_container)` rather than the clunky `sort(my_container.begin(), my_container.end())` for example. And there are a bunch of useful lazily-evaluted range views. I only wish more of the ranges library could have been added. And I hope the compilation of ranges isn't too slow.

* Modules can now start replacing include files. Initially, this will only be a theoretical possibility, but within several years, no longer will your compiler have to deal with 100,000 lines of text or so per translation unit: It will be like in Java and other languages, where it's just your current file that needs to be compiled and the rest is already compiled. Of course the transition will not be smooth (feature macros, conditional compilation - not obvious to me how to replace them when using modules), but this is a good direction. We could see faster compilation times and content suggestions in IDEs.

* Expanded constexpr support means we can do more work once, at compile time, rather than repeating it at run-time (e.g. dynamic memory allocation - so you can have constexpr std::vector).

* Coroutines are something interesting which I am not familiar with (except the very rough general idea of different control flows being switched between. I can at least say it's interesting to look into.

* libfmt string formatting - Yes, yet another way to format strings: printf-style, iostreams, and now the "Python style", I guess you could say? It combines some benefits of both of the previous ones.

* std::source_location - you know how, if you're writing some error-handling function, you usually need to wrap it in a macro which gives you the filename and line number? Well, that's going away now. I know it's just a minor thing, but I hate having those macro'd error handlers.

* You can now tell the compiler to use a generated equality and comparison operators; this saves you boilerplate. Although in the C++ tradition, this capability is defined in a somewhat convoluted way under the hood.

Re:C++20 has been approved by gumby on Sunday September 06, 2020 @11:05AM (#24391808)
Unfortunately ranges are only available in g++ at the moment. But I expect to have most of c++20 available in the next 6 months or so.
Re:C++20 has been approved by nikki93 on Sunday September 06, 2020 @11:40AM (#24392083)
I'd written C++ a bunch around 2006-2011 for gamedev, and jumped back into it recently and am really really loving it. I had a while in between of leaning into C which I think is important to do, to move away from the super OO based approach which I think C++ isn't necessarily about anymore.

Highlights for me:

- Type deduction -- basically using auto for variable declarations.

- Move semantics makes RAII actually usable since you can make heavy / important objects but then move them elsewhere and still have their lifetime be automatically managed. I use this in my game engine to wrap physics bodies etc. so that they are automatically removed from the scene when the component containing them is dropped (I'm using an ECS). A neat thing also is you can delete copy constructors and force certain types to be "move-only."

- Having been in C-land for a bit, I'm appreciating the ready availability of std::vector and std::string again. Also std::array is awesome.

- Lambdas are amazing. I often make simple control structure utilities in my modules that accept lambdas, and they are often inlined. I don't often do lambdas where I 'save them and call them later' -- they are mostly immediately called. This makes it safe to use reference captures.

As for C++20 I am mostly interested in seeing how it goes with modules Also the `requires` keyword will simplify some of my uses of `enable_if`.

A lot of the good stuff is also due to ecosystem and tooling vs. just language. My game works everywhere now: native macOS, Windows and iOS, but especially web due to Wasm! It also has an immediate mode API for rendering UI in Wasm, which I use along with some simple reflection to get an automatic entity inspector: https://m.imgur.com/dyUtL8f The entire gameplay code fits in like 700 lines: https://gist.github.com/nikki93/5893543a5e3d76a7858d54b74a4c... You can see how I don't do any pointer stuff or manual recource / memory management there at all.

Tbh in many cases with precompiled headers it almost feels like it builds about as fast as webpack. And then my "publish" is a simple rsync of static files to the server.

Another tooling / ecosystem thing lately has been godbolt.org which is wonderful for seeing immediately the asm that ur code generates. Which then makes you realize how good optimizing compilers for C++ are these days. I don't think other languages have come so far. And then with godbolt.org you can learn which constructs produce what code.

I'm using entt for the ECS: https://github.com/skypjack/entt you can see how it encourages the use of POD structs and non-OO code for the most part. It feels good to use C++ in that style as a C with the above features. I just basically don't use vtables / RTTI anymore. I do use templates a fair amount.

I do concede that this enthusiasm may have a lot to do with having had experience in C/C++ already for a while. If I was completely new to the language it'd be a lot harder. The backwards compatibility lets me keep all my experience (even if the point isn't to write exactly like how I wrote before, but to understand the motivation for the new features). I've also dug into Go, Rust, Nim, Common Lisp, Haskell, ... but weirdly modern C++ has been the best combination of ergonomics, control, and portability. Especially for Wasm you really just want deterministic resource management. I'd probably still combine it with Lua or JS for scripting eventually.

You do have to invest a lot of energy into learning the language and caring about the details, but I think C++ is very well positioned to reward you for that investment, and you are also rewarded continuously and early.