Follow Slashdot stories on Twitter

 



Forgot your password?
typodupeerror
×
Programming

C++20 Is Feature Complete (hackaday.com) 231

Long-time Slashdot reader mejustme shared this report from Hackaday: If you have an opinion about C++, chances are you either love it for its extensiveness and versatility, or you hate it for its bloated complexity and would rather stick to alternative languages on both sides of the spectrum. Either way, here's your chance to form a new opinion about the language. The C++ standard committee has recently gathered to work on finalizing the language standard's newest revision, C++20, deciding on all the new features that will come to C++'s next major release.

After C++17, this will be the sixth revision of the C++ standard, and the language has come a long way from its "being a superset of C" times. Frankly, when it comes to loving or hating the language, I haven't fully made up my own mind about it yet. My biggest issue with it is that "programming in C++" can just mean so many different things nowadays, from a trivial "C with classes" style to writing code that will make Perl look like prose. C++ has become such a feature-rich and downright overwhelming language over all these years, and with all the additions coming with C++20, things won't get easier. Although, they also won't get harder. Well, at least not necessarily. I guess? Well, it's complex, but that's simply the nature of the language...

From better type checking and compiler errors messages to Python-like string handling and plans to replace the #include system, there's a lot at play here!

The article mentions coroutines, the spaceship operator for three-way comparisons, and "a bunch of additions to lambda expressions," as well as a new keyword constinit and removing limitations on the usage of constexpr.

And in addition, "ranges are the new iterators" and concepts "have graduated from being an experimental feature to a full-fledged part of the language standard, allowing the addition of semantic constraints to templates, and ultimately making generic programming a hint more specific."
This discussion has been archived. No new comments can be posted.

C++20 Is Feature Complete

Comments Filter:
  • Who needs C++ when there is elexir or techno psycobitch [youtu.be] that will even be cooler than rust with the she hipsters

    • Erlang doesn't have three separate print libraries. It's no good.
      • Heh, nice. So, about std::format()... I'm actually really looking forward to this addition. The fmt library, which this is based on, is really great to use.

        A lot of people give C++ crap for this (yes, sort of funny to have three string format libraries), but honestly, it's just the result of a pragmatic realization that stream operators was just not great for string formatting. Nearly everyone I know vastly prefers simple, concise printf style formatting, but printf is really pretty awful as well - passi

        • Yeah, I agree, I was mainly joking. I'm not sure this library will be so much better, though. I worry that in a few more years they'll want to add a log4j clone.
          • Yep, I could tell the ribbing was good-natured. Keep in mind this is strictly a string formatting library, not a logging library, so it's really more a replacement for sprintf() than for printf(). It's always hard to be certain, but having used the fmt library for a while in my own projects, I'm pretty sure this will be a very useful and well-received addition to the std lib.

            • I should have said, "I'm not sure that this print library is good enough that they won't add another one in ten years"
  • Comment removed based on user account deletion
    • I've never been able to understand people who prefer C over C++. Those who want speed from their language without using a profiler will be sorely disappointed.
      • If your first and only thought is speed, you'll never understand preferring C. I use some OOP when needed, like accessing archive files in a consistent way. Or the std templates like vector. But otherwise there's not much point. I don't do game engines where the complexity has to be managed and boundaries drawn for separation of concerns.

        If I did need that, I'd use C# because the standard library is huge and we'll tested, it can be as fast as C, and productivity is so much better than C++ in general. C++ is

    • by jma05 ( 897351 )

      It depends on your job.

      > I'll take care of freeing my own memory, thank you.

      Famous last words.

      C is unsuitable for a vast majority of modern programming tasks. It is serviceable only in situations where we can afford to have a lot of eyes to inspect it for errors since it is the most error prone statically typed language ever.

      It sounds like you only learned C and did not spend much time in other paradigms.

      C++ and Rust don't produce bloated code at all.

      If you are new to programming and don't need a lot of

      • Re:Simplicity (Score:5, Informative)

        by Uecker ( 1842596 ) on Sunday August 04, 2019 @03:28AM (#59037140)

        It depends on your job.

        > I'll take care of freeing my own memory, thank you.

        Famous last words.

        Yes, manual memory management is a pain and error prone. On the other hand, I am not fully convinced by most automatic approaches used in other languages. If you use C, you would usually rely on additional tools to check for errors (sanitizers, valgrind, etc.). This works really well in practice.

        C is unsuitable for a vast majority of modern programming tasks. It is serviceable only in situations where we can afford to have a lot of eyes to inspect it for errors since it is the most error prone statically typed language ever.

        If I look at all the programs I use often, most of them are written C (linux, xcfe, bash, terminal, vim, x11, postgresql, git, gimp evolution,evince, etc.).The three big exceptions are: the web browser, gcc, and openoffice. gcc is essentially still a C code base compiled with a C++ compiler (I occasionally contribute patches to gcc). The programs I use that are written C tend to be extremely reliable and light-weight, while those that are written in C++ feel less performant und are less reliable. For example, inkscape is another C++ program I sometimes use, but i tends to be slow and sometimes crashes. Openoffice is also not too performant. With Chromium which is written n C++ I am quite happy though. So I would say C works extremely well for all kinds of programming tasks and the result tends to be good. But of course, this is my biased view, maybe I don't know what "modern programming tasks" are.

        It sounds like you only learned C and did not spend much time in other paradigms.

        C++ and Rust don't produce bloated code at all.

        If you are new to programming and don't need a lot of fancy features, you can still just use a small subset of C++ or Rust features.

        You can certainly stick to a subset of C++ that does not produce bloated code. But I would say that many programmers don't.

        • by jma05 ( 897351 )

          "modern" programming tasks, perhaps I should call them business tasks - the kind of jobs you find on a typical job board - creating web sites, creating enterprise/in-house software, data analysis etc.

          A good chunk of core software that I use was written in C too. But I have run into exactly zero programmers at work who used C as their main language since a couple of decades. I would use C to write small bits of code to create a library for use in a higher level language but I have never run into a scenario w

  • Might as well throw the kitchen sink in, and an autocorrector. Oh well back to c. If I wanted this much of a mess, there's already Java. At the rate they are going, one day c++ compilers will do email and web browsing as part of their core functionality.
  • by pjt33 ( 739471 ) on Saturday August 03, 2019 @02:41PM (#59035126)

    How about removing some features for once? Not that C++ is the only language with feature creep. Stuff that Java marked as deprecated back in version 2 is still in version 9. In fact, it seems to be incredibly rare that any language design committee dares to prioritise having a clean spec over backwards compatibility.

    • In fact, it seems to be incredibly rare that any language design committee dares to prioritise having a clean spec over backwards compatibility.

      Oh, you should try Node.js. Backwards incompatibility is what it does. It will make you happy.

    • Go on, choose a feature and I'll tell you why it can't be removed.

      Thing is if you want a different, incompatible language there are plenty to choose from, depending on your domain. If however you want to be able to (a) take advantage of some of the anguage developents of the last 40 years but (b) not rewrite well tested, working code from 15 years ago, then not removing features is not a bad choice.

      In fact, it seems to be incredibly rare that any language design committee dares to prioritise having a clean

    • Re:Only added? (Score:5, Informative)

      by Justus ( 18814 ) on Saturday August 03, 2019 @05:19PM (#59035832)

      C++ has deprecated and removed features in each of the three most recent language revisions:

      There are additional features deprecated/removed in C++20 (including e.g. the partial deprecation of volatile [open-std.org] as mentioned in the linked article) but I couldn't find a convenient list of them.

      It is true that it is harder to remove features than add them, and people are usually more interested in what's new than what's been removed, so it does not get much attention. However, this doesn't mean it doesn't happen.

    • by Jeremi ( 14640 )

      it seems to be incredibly rare that any language design committee dares to prioritise having a clean spec over backwards compatibility.

      Python did that, breaking compatibility in Python 3. The result is that now there are two Python languages (Python2 and Python3), each with half the user base of the original, and for the forseeable future you have to support both of them.

  • They have not thrown in the kitchen sink yet. Maybe next revision.
  • by Viol8 ( 599362 ) on Saturday August 03, 2019 @02:55PM (#59035184) Homepage

    .... I've got to say, I'm really tired of having to play catch up with the latest features just to keep some idiot interviewer happy down the line when I look for a new job when its almost certain most of their code is still C++98 with a bit of 2011 thrown in or to have to grok some code written by someone who wants o try out everything in the C++ guide appendix A-Z.

    C++98 was a mess - 2011 was the language C++ should have been to start with. 2014, well ok, a few nice bits but generally meh frankly, and as for 2017, honestly who cared?

    The language really is the proverbial kitchen sink now and IMO its probably time to call it a day. I'm really not interested in some new obscure bit of syntax that might save me 1 line of code and as for co-routines, honestly , who gives a shit - they're just glorified gosubs and will probably be a threading nightmare.

    • by dyfet ( 154716 )

      Yes, C++11 is finally a great baseline. In go, there are go routines, which is a dead simple model for threading. C++20 coroutines, though, are yea, meh, but I think if you look at the spec, resumable, etc, it sounds to me like a first stab at/foundation for eventually introducing python style "generators", and yes, that would be even more kitchen-sinkism.

    • .... I've got to say, I'm really tired of having to play catch up with the latest features just to keep some idiot interviewer happy down the line when I look for a new job when its almost certain most of their code is still C++98 with a bit of 2011 thrown in or to have to grok some code written by someone who wants o try out everything in the C++ guide appendix A-Z. ...

      C++ is a problem because it makes dysfunctional companies more obviously dysfunctional? Sounds like a feature not a bug to me. If the inter

      • by Viol8 ( 599362 )

        "Everything in programming is glorified something else"

        True, but there's a law of diminishing returns. Loops were a much clearer form of if-goto. co routines OTOH are not easy to read or follow and if you want generators there are much simpler and just as efficient ways to achieve it with inlined functions.

        • co routines OTOH are not easy to read or follow and if you want generators there are much simpler and just as efficient ways to achieve it with inlined functions.

          What you can do with lambdas returning {lambdas returning lambdas}, you can replace with co-routines which make the logically linear flow control appear as linear flow control (with arbitrary pauses at the yield points). I figure at this point we both understand that as the mechanism and are both talking about the same thing.

          I certainly agree you

          • by Viol8 ( 599362 )

            "What you can do with lambdas returning {lambdas returning lambdas}, you can replace with co-routines"

            I can't think of a single use case where lamdas returning lambdas is a sane thing to do. It just sounds like show off sphagetti code.

            Co routines serve no practical purpose , they're an academic toy and as ugly as C code that uses setjmp and longjmp. If you want to keep state in a seperate code path but don't want to overhead of a stack push and pop and don't like globals then just use static inlined functio

  • a long way from its "being a superset of C" times

    Hey, I remember those times: "If you like your C programs, you can keep your C programs".

    Too bad, much of C code will no longer compile with a C++ compiler and the fans will gleefully tell you, how C++ has "overgrown" that stage, when it had to gain the programmers' trust and midnshare by claiming to be a superset of C...

    • You don't really have to be a fan to say that. That feature was very important in the early years but it simply isn't now. Even now converting a massive old C codebase to C++ is doable (see GCC).

    • by Jeremi ( 14640 )

      Too bad, much of C code will no longer compile with a C++ compiler

      I've never seen any evidence of that, has anyone?

      The only problems I've ever had compiling C inside a C++ compiler was when the C programmer used C++-reserved-keywords (like "new" or "delete") as variable names, and that was easily resolved with a simple search-and-replace (e.g. :s/new/newVar/g).

      Am I missing something?

      • You're not missing anything, as I don't think there's much to that claim. Most large C++ project I know of make use of quite a few C libraries. It's true that C++ is no longer a strict superset of C, but it's been that way for quite a while. Most authors of C libraries take care to ensure their libraries compile with both C and C++. And since C and C++ programmers mostly use the same compilers, it's not hard to make a library compatible with both languages.

      • by mi ( 197448 )

        I've never seen any evidence of that, has anyone?

        Yes, I have. Indeed, it is far from begin a secret. Wikipedia, for example, even say this (emphasis mine):

        Others have argued that since C and C++ are two different languages, compatibility between them is useful but not vital; according to this camp, efforts to reduce incompatibility should not hinder attempts to improve each language in isolation.

        Had it been Microsoft — and had it been Slashdot of at least 10 years ago — someone would've brought

      • by mark-t ( 151149 )
        It gets a lot harder when you are looking at legacy (pre-ansi) C code. It will still compile fine with even a modern C compiler (perhaps at most issuing a few warnings about function prototypes or converting pointer types), but will immediately fail if you try and compile it with C++.
      • I've never seen any evidence of that, has anyone?

        Well, there's the void pointer conversion without a cast (the biggest), VLAs, designated initialisers and a few others. VLAs are the hardest to work around, but not that hard.

  • ... to make it into the c++20 standard. It makes certain types of classes that mimic the semantics of a reference to some user-supplied class (such as through a template parameter) drastically more straightforward.

    Without it, one is forced to relegate the semantics of their object to be similar to that of a smart pointer, which does not necessarily accurately reflect the intended functionality of the user-defined class.

  • Did the comments have to pass a CoC?
  • by dremon ( 735466 ) on Sunday August 04, 2019 @08:38AM (#59037648)
    // no warnings issued by the compiler yet there are 4 major issues in this code.
    // One is quite obvious, 3 others are not unless you have years of C++ experience.
    // you must be completely out of your fucking mind to use C++ for any new projects.
    // compile with "g++ -c -pedantic -Wall -Wextra test.cpp"

    // P.S. I don't give a shit whether this is "part of the language standard". If the standard permits it then it's just garbage.

    #include <iostream>
    class Base {
    public:
        Base() { std::cout << "Base()\n";  }
        ~Base() { std::cout << "~Base()\n"; }
       int m_counter;
    };
    class Derived: public Base {
    public:
        Derived() { std::cout << "Derived()\n"; }
        ~Derived() { std::cout << "~Derived()\n"; }
    };
    int main() {
        Base* b = new Derived[10];
        std::cout << b[10].m_counter << '\n';
        delete b;
        return 0;
    }

    // spoiler:
    // 1. non-virtual destructor in base class. Derived destructor is never called.
    // 2. use of uninitialized field m_counter.
    // 3. array access outside of boundaries.
    // 4. delete operator without []. Runtime errors are guaranteed.
    • You're the one out of your mind, undefined behavior exists with all languages in common use. C++ is fine solution for many problems and majors works used by hundreds of millions of people do just fine with it.

"Conversion, fastidious Goddess, loves blood better than brick, and feasts most subtly on the human will." -- Virginia Woolf, "Mrs. Dalloway"

Working...