Slashdot Mirror


C++14 Is Set In Stone

jones_supa (887896) writes "Apart from minor editorial tweaks, the ISO C++14 standard can be considered completed. Implementations are already shipping by major suppliers. C++14 is mostly an incremental update over C++11 with some new features like function return type deduction, variable templates, binary literals, generic lambdas, and so on. The official C++14 specification release will arrive later in the year, but for now Wikipedia serves as a good overview of the feature set."

30 of 193 comments (clear)

  1. Stone by buchner.johannes · · Score: 4, Funny

    Wouldn't it more useful for it to be set in silicone?

    --
    NB: The message above might reflect my opinion right now, but not necessarily tomorrow or next year.
    1. Re:Stone by makq · · Score: 3, Informative

      Silistone!

    2. Re:Stone by NotInHere · · Score: 4, Informative

      Actually, its set in {La,}Tex: https://github.com/cplusplus/d...

  2. Still... by fyngyrz · · Score: 3, Interesting

    ...using c. Although I do like to comment thusly, and so prefer a compiler that understands at least basic c++:

    // comment

    I like to stay as close to the metal as I can get. I'd use assembler, but many of my projects are cross platform, so c it is.

    --
    I've fallen off your lawn, and I can't get up.
    1. Re:Still... by makq · · Score: 5, Funny

      Various black hats appreciate your dedication to C.

    2. Re:Still... by tlhIngan · · Score: 4, Informative

      ...using c. Although I do like to comment thusly, and so prefer a compiler that understands at least basic c++: // comment

      I like to stay as close to the metal as I can get. I'd use assembler, but many of my projects are cross platform, so c it is.

      End of Line terminated comments ("//") actually are in the C spec as part of C99. And while it did take GCC a little while for that to be accepted in C mode, most other commercial compilers accepted them just fine. (C++ is not completely compatible with C, mind you, unlike Obj-C which is fully C compatible. This can cause issues if you try to compile C code using a C++ compiler rather than a C/C++ compiler)

      Now, one interesting thing in C++14 is binary literals (using "0b" a la "0x" for hex). That seems handy, though it would be more appropriate to be in C than C++ as C generally needs that sort of specification. Though, annoyingly, they didn't seem to allow use of something like _ to break long literals up into human-readable groups. I mean, a 32-bit string of bits is already hard enough to visually see, allowing the use of something like "_" in the string to help arbitrarily break up and group long constants would be helpful. (Even in hex it would be useful when doing 64-bit values).

      E.g., would you rather try to see which bit is set in a string like "0b001011010011011101011100" or have it broken up like "0b0010_1101_0011_0111_0101_1100" or "0b00101101_00110111_01011100". If it's a bit field, you may even want "0b001011_010011011_01_0_111_0_0" if breaking it into fields has meaning.

      Such a small change to help readability...

    3. Re:Still... by Anonymous Coward · · Score: 5, Informative

      Though, annoyingly, they didn't seem to allow use of something like _ to break long literals up into human-readable groups.

      Yes they did. It's not underscore, it's apostrophe. For example:
              auto a = 0b100'0001; // ASCII 'A'
              auto million = 1'000'000;

      See here:
              http://isocpp.org/wiki/faq/cpp14-language#digit-separators>http://isocpp.org/wiki/faq/cpp14-language#digit-separators

    4. Re:Still... by Imagix · · Score: 5, Informative

      Uh, yes they do. Don't rely on summaries to list all of the features of the language. From N3797: An integer literal is a sequence of digits that has no period or exponent part, with optional separating single quotes that are ignored when determining its value. Example: The number twelve can be written 12, 014, 0XC, or 0b1100. The literals 1048576, 1’048’576, 0X100000, 0x10’0000, and 0’004’000’000 all have the same value. — end example

    5. Re:Still... by fyngyrz · · Score: 4, Interesting

      Have you ever written C code which uses a switch statement based on what type a struct/union is and calling the relevant code for it?

      No. When I use structures as objects (which is often), they almost always contain a pointer to a block of general methods appropriate to that structure, as well as containing any methods unique to the object, all of which are called through the object/structure, so it would be unusual, at least, to be testing the object type in order to choose an object-specific procedure to call. However, I do mark each object type with a specific ID and serial as they are created, along with a tag indicating what procedure created them, as these things facilitate some very useful memory management and diagnostic mechanisms.

      Have you ever used qsort?

      I am aware of qsort. But I have my own multi-method sort library that I use. Most of them locate the comparison mechanisms they are to use through the procedures specified by the objects they are asked to sort. Likewise list management, memory management, certain types of drawing primitives and image processing primitives, image handling mechanisms, associative storage, basically anything I have run into that I thought likely I would need more than once. I am positively locked into the idea that if I write it, I can fix it, and the number of bugs and problems that fall into the "maybe they'll fix the library someday" class are greatly reduced. I'm a little less picky if I have the source code to a capability I didn't actually write and can supply my own version if and as needed. A good example of something like that is SQLite. Actually having the source code and compiling it in reduces my inherent paranoia to a somewhat duller roar.

      --
      I've fallen off your lawn, and I can't get up.
    6. Re:Still... by brantondaveperson · · Score: 4, Funny

      From the "re-inventing C++" department... :)

  3. Support for your position by fyngyrz · · Score: 4, Funny

    Wouldn't it more useful for it to be set in silicone?

    Intend to stay abreast of the spec, do you?

    --
    I've fallen off your lawn, and I can't get up.
    1. Re:Support for your position by Anonymous Coward · · Score: 5, Funny

      You boob. Take your puns and go.

    2. Re:Support for your position by geekoid · · Score: 3, Funny

      Did they make any changes in mammary allocation?

      --
      The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
    3. Re:Support for your position by jones_supa · · Score: 3, Funny

      Goodbye. Now I'm just gonna relax and listen the tits chirping.

  4. Re:Oh god so what? by geekoid · · Score: 4, Insightful

    COBOL is an excellent language for hat it was designed for. I can only assume your hate comes from ignorance.

    It seems to me, your hate would be better directed at poor engineering and software engineering standards then the tools.

    --
    The Kruger Dunning explains most post on /. http://en.wikipedia.org/wiki/Dunning%E2%80%93Kruger_effect
  5. Re:Oh god so what? by Anonymous Coward · · Score: 4, Insightful

    Any individual can choose a usable subset of a complex system. The problem is that each individual chooses a different subset.

    So in the real world, you have to understand nearly all of it in order to be able to maintain other people's code or to work as a team.

    I've been writing C++ since around 1990, when the idea of an STL was being bounced desperately around by Musser and Stepanov. Back then, C++ was a genuinely simple enough language to implement in - nobody pretended that it was anything more than a C compiler preprocessor, which is mostly what it still is, with a little bit of runtime support, but there's just so much of it.

  6. Where are my designated initializers? by Tough+Love · · Score: 3, Insightful

    It's just pathetic that so many years down the road the committee can't get its act together to provide this much loved C99 feature at least for POD. This is a major issue, if not the major issue) with porting C code. The word wanking comes to mind. Here, GCC guys really need to take the lead but it's starting to feel like GCC guys are actually holding back on it. It's not like the coding is a challenge.

    --
    When all you have is a hammer, every problem starts to look like a thumb.
  7. Re:Why do we need Auto? by erapert · · Score: 4, Informative

    Herb Sutter responded to this on his blog (Sutter's Mill): http://herbsutter.com/2013/08/...

  8. Re:Why do we need Auto? by Anonymous Coward · · Score: 3, Interesting

    I used to think that, until I realized:

    auto handler = boost::bind(&Class::write_callback, this, boost::ref(timer), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred);

    /// what is the type of handler?
    boost::asio::async_write(device, buffer, handler);

    Iterators another good one:

    typedef void (*FunctionPtr)();
    std::map<std::string, FunctionPtr> knownCommands;

    /// elsewhere:
    std::string command = "example";

    /// what do you like more?
    std::map<std::string, FunctionPtr>::iterator it = knownCommands.find(command);

    /// or
    auto it = knownCommands.find(command);


    if (it != knownCommands.end()) { /* do something useful */ }

  9. Re:Why do we need Auto? by Anonymous Coward · · Score: 3, Informative

    There are several cases where auto is critical.

    For instance with lambdas, it is no longer even possible to write out the types:

    auto itr = boost::make_filter_iterator([](const Bar &bar) {return bar.foo;},vect.begin(),vect.end());

    The type of itr is boost::filter_iterator, but it cannot be written out because there is no way to enter to the type of the lambda.

    It also eliminates nasty hacks like you see in BGL:

    property_map::const_type pm = get(vertex_index,graph);

    The property_map specialization framework is nasty and complex and conveys no meaning to the caller beyond what 'get' already says. So instead of the nasty property_map we use 'auto' and decltype(get(vertex_index,declval()), which is just as informative to the reader.

    Another good use is to get rid of duplications:

    auto ptr = make_shared(..);

    Is better than the duplicative:

    std::shared_ptr ptr = make_shared(..);

    That isn't even touching how useful it is when working with template meta programming. There are many cases where building up a return type is incredibly complex, and not useful to the reader because the underlying type is obscured by template meta programming anyhow.

    The improvements to auto are mostly fine tuning. Eg return type deduction eliminates the nasty idiom that has developed:

    auto foo() -> decltype(the_return_function(...))
    {
            return the_return_function(...)
    }

    The duplication is very common when using auto for a return.

  10. Re:Why do we need Auto? by kthreadd · · Score: 5, Informative

    Auto does not mean loose typing. It still has a type, you just don't have to write it but it will be there and will be enforced by the compiler.

  11. Re:Oh god so what? by ShanghaiBill · · Score: 5, Interesting

    But here's the catch: you're not supposed to know it all. C++ is like a large store where you go and "shop" just the features you need. You can keep it super simple and write C-style code and just use classes as the only C++ feature, if you want to.

    That is fine if you are a team of one, and you never read code written by others.

  12. Re:Oh god so what? by fnj · · Score: 4, Insightful

    Err, the implication is that you can also write C++ that is not guaranteed to be maintainable by anybody short of a complete master, which even Bjarne says he is not. I think it is fair to estimate that the number of complete C++ masters in the world is in the single to double digits; no more. It may be you can identify another programming language for which that holds true. I don't think I can.

    Other successful computer languages do not have that problem. Any competent C programmer can maintain any C code, and the same for python and Java. Perl is arguable; the problem is not complexity but opaqueness.

  13. Re:Why do we need Auto? by Stele · · Score: 3, Informative

    auto definitely makes writing looping constructs with iterators shorter/easier, without additional typedefs, but by far the nicest use for it is in writing templates, where a specialization or type-dependent mapping my occur in the template using a helper function, and you don't necessarily know what the intermediate type might be. Sure, you could use some complicated typedefs, which may require additional traits classes, but auto handles it nicely.

  14. Re:Oh god so what? by TechyImmigrant · · Score: 3, Insightful

    > Integer overflow has absolutely nothing to do with security.

    Yes it does. I take it you don't write much crypto code?

    --
    I should use this sig to advertise my book ISBN-13 : 978-1501515132.
  15. Re:Why do we need Auto? by Xrikcus · · Score: 4, Informative

    Lambdas are a primary place where auto is there precisely because C++ is a strong, statically typed language as far as possible. The alternative might be polymorphic lambdas, which would require dynamic typing. With auto the type you get, and can propagate through templates, is the type of that specific lambda. With polymorphism the type you'd get is the type of a lambda, from which you'd need to infer which lambda. Auto ensures that with a lambda, though the type is not easily known to the programmer, the type can be statically defined in the code and propagated accordingly.

  16. C++ set in stone by doti · · Score: 3, Funny

    now we just need to throw the stone in the Marina Trench.

    --
    factor 966971: 966971
  17. Re:Oh god so what? by TheRaven64 · · Score: 4, Informative

    Integer overflow has absolutely nothing to do with security

    Integer overflow has been in the top five causes of CVEs for several years running. Buffer overflows, sadly, are still at the top.

    --
    I am TheRaven on Soylent News
  18. Back to the future by T.E.D. · · Score: 5, Funny

    with some new features like function return type deduction,

    Hey, K&R C had function return type deduction back in the 70's .

    ...of course it always guessed "int", but IT HAD IT.

  19. Re:Oh god so what? by lgw · · Score: 3, Informative

    So in the real world, you have to understand nearly all of it in order to be able to maintain other people's code or to work as a team.

    If you don't have coding standards and a firm code review process to enforce them, you have already lost.

    C++ has a lot of cruft to allow you to cleanly solve problems that 99% of coders will never encounter. I'd say that these days, if your not in some dark corner where you need at least 1 bizarre C++ feature, you should probably use a higher level language.

    As an example of what I mean - C++ lets you overload the 'new' operator. Why would you ever want to do that? There no reason to learn how that feature works until and unless you need it. But if you need to do "slab allocation" or otherwise change the memory allocation pattern away from "just malloc", suddenly overloading 'new' is an amazingly useful and clean way to do this. In C you have to replace malloc with some other call (or #define malloc notmalloc) and police it everywhere in your codebase, which gets ugly when you have 20 different objects each allocated from its own slab, and gets horrifically ugly when you discover that you need to do this a couple years into a project. In C++ you just overload 'new' on a class-by-class basis.

    C++ has many features like that - stuff that you'd almost never have any use for, but is wonderful when you find yourself in that dark corner. You just need to guard against that guy who just wants to play with some C++ cruft when it's not needed, just because it looks neat.

    --
    Socialism: a lie told by totalitarians and believed by fools.