New C++ Features Voted In By C++17 Standards Committee (reddit.com) 286
New submitter lefticus writes: The upcoming C++17 standard has reached Committee Draft stage, having been voted on in the standards committee meeting in Oulu, Finland this Saturday. This makes C++17 now feature complete, with many new interesting features such as if initializers and structured bindings having been voted in at this meeting.
An [audio] interview with the C++ committee chair, Herb Sutter, about the status of C++17 has also been posted.
An [audio] interview with the C++ committee chair, Herb Sutter, about the status of C++17 has also been posted.
Sweet (Score:5, Insightful)
C++ needed more features. Some C++ books aren't even 1000 pages long.
Re:Sweet (Score:5, Funny)
C++ needed more features. Some C++ books aren't even 1000 pages long.
I agree! And more use of the "const" keyword.
I want to write something like
const int const foo(const*(const) int const a) const: const {}
and
for (const i = 0;const i(const)++; i and finally:
const return const 1 (const const const)
Re: (Score:3)
Sane languages have their stuff const by default, and you write mut if you want something changeable.
Re: (Score:3, Informative)
Re: (Score:2)
I disagree with you. Rust has many friends in the haskell community. And haskell has survived for a long time, despite not becoming very popular.
Re:Sweet (Score:4, Insightful)
Haskell's unofficial motto is "avoid success at all costs", which is how it has remained pure and hipster. Haskell will always be the language of the future, in the sense that unless you work for a European bank you won't be using it yourself, but the new features in your favourite language will probably come from Haskell.
Avoiding success is a lesson that Rust has not learned.This is why Rust will become obsolete and Haskell will not.
Re: (Score:2)
So you say that isn't a good choice? Do you prefer having to put const everywhere?
Re: (Score:2)
So you say that isn't a good choice? Do you prefer having to put const everywhere?
You don't have to put const "everywhere". Most const values are defined in header files, where you write them once and rarely look at them again. For the code that you spend 90% of your time writing and maintaining, most variables are non-const.
Re: (Score:2)
Are you so sure: https://stackoverflow.com/ques... [stackoverflow.com]
Why foolishly chosen names? (Score:2)
Rust [rust-lang.org]: Happens with iron as iron becomes useless red dust.
Gimp [gimp.org]: (1) a derogatory term for someone that is disabled or has a medical problem that results in physical impairment. [urbandictionary.com]
LaTeX [latex-project.org]: Use two different alphabets to write a name! Inspired by the Greek word ÏÎÏ [stackexchange.com]. Sorry, Slashdot can't display those characters.
No. (Score:4, Funny)
I started programming in C++ in '89. Templates were still new, but most of the language was stable. C++ code I wrote in '89 is still readable and compilable today. I know people who started with C++ in 1981, when it was still Bjarne's skunkworks project. The first public release was '83, making C++ 33 years old -- closer to 40 years old than 25.
Re: (Score:2)
For pretty insane values of "sane". Actually nobody sane does it that way. Breaking convention has no place in solid engineering, and only communities that misidentify "different" as "better" will ever accept such a moronic design.
Re:Sweet (Score:4, Funny)
C++ needed more features. Some C++ books aren't even 1000 pages long.
I agree! And more use of the "const" keyword. I want to write something like const int const foo(const*(const) int const a) const: const {} and for (const i = 0;const i(const)++; i and finally: const return const 1 (const const const)
Replace const with spam and you would have yourself a Monty Python skit.
Re: (Score:2)
The problem is that some C++ still rely on runtime. The ideal C++ program only relies on compile-time templating.
Re: (Score:2)
trump int trump foo(trump*(trump) int trump a) trump: trump {}
and
for (trump i = 0;trump i(trump)++; i and finally:
trump return trump 1 (trump trump trump)
FTFY
Re: (Score:2)
Oh do keep up. This is Slashdot. It's..
APP int APP foo(APP*(APP) int APP a) APP: APP {}
and
for (APP i = 0;APP i(APP)++; i and finally:
APP return APP 1 (APP APP APP)
Apps!
Re: (Score:2)
And how about that @#!$#@$ ** exponentiation operator already !!
Oops! Wrong room.
[leaves]
Re:Sweet (Score:5, Informative)
Just because you are unable to cope with C++'s richness of features does not mean it is a bad thing.
After all, C++ is the one language that
Re: (Score:3)
has a responsibly acting committee doing a good job overlooking the long-term language evolution. So much unlike many other programming languages, were inexperienced people have introduced the same mistakes over and over again, because nobody was there to question them.
To be pedantic here, I'd prefer if they were overseeing it.
Re:Sweet (Score:5, Funny)
Re: (Score:2)
Re: (Score:2)
TECO command strings.
Re: Sweet (Score:2)
Re: (Score:3, Insightful)
This made me laugh. Having written programs in most of the languages living people have heard of, Perl is the one language I can write something in and 15 minutes later can't figure out what it does! I always called Perl the perfect write only language.
Having said that... I could write a Perl program in 5 lines that I would spend HOURS trying to figure out how to do in just about anything else. ... but if it's obscure I better add a comment to say what it is supposed to do. Because given problem 'x' I
Re: Sweet (Score:3)
Re: (Score:2)
Where are the hyphens in Strassenbahnhaltestelle and Polenüberfallenmittelstoff?
I think the real giveaways are a comma after a verb of sensing/knowing - like "Check, that the file is open" - and of course the verb at the end putting.
Re: (Score:2)
WTF is std::vector[bool]?
Don't you mean std::vector<bool>? Or am I missing something? Are booleans really being used as index these days?
Re: (Score:2)
It's what happens when you don't know how to write "std::vector<bool>".
Re: (Score:2)
The beauty of C++ is that std::vector[bool] can be almost anything. See below:
#include
#include #define bool 2 #define vector vector test int main() { std::vector[bool]; test[0][0] = 1; test[1][0] = 2; printf("%d %d\n", test[0][0], test[1][0]); return(1); }
Re: (Score:2)
The beauty of C++ is that std::vector[bool] can be almost anything. See below:
#include <stdio.h>
// Insert almost anything here, use trailing \ if necessary
#include <vector>
#define bool 2
#define vector vector test
int main() {
std::vector[bool];
test[0][0] = 1;
test[1][0] = 2;
printf("%d %d\n", test[0][0], test[1][0]);
return(1);
}
I wish I didn't know enough of C++ to write the above ...
Re: (Score:2)
Try 3 at that demo program:
#include <stdio.h>
// Insert almost anything here, use trailing \ if necessary
#include <vector>
#define bool 2
#define vector vector<int> test
int main() {
std::vector[bool];
test[0][0] = 1;
test[1][0] = 2;
printf("%d %d\n", test[0][0], test[1][0]);
return(1);
}
Re: Sweet (Score:2)
Re: (Score:3)
The idea that Java and C programmers should be able to read th
Re: (Score:2)
I haven't bought a door stopper (technical book) in over ten years. Mostly because up-to-date information can be found on the internet. If I buy a technical book these days, it's a used copy of an older book that is out of print, unavailable as an ebook, or cheaper than the current edition.
I recently picked up "Writing Compilers and Interpreters: An Applied Approach" by Ronald Mak (1991 edition), which uses an ancient dialect of C and Pascal as the target language. I know a smattering of C and nothing about
Re:Sweet (Score:5, Interesting)
You need to divide C++ into two sections: Stuff that's useful for applications, and stuff that's mostly relevant to library writers. A lot of the really hairy stuff is mostly for the library writers. Moreover, a lot of the complexity of C++ (and corresponding slowness of its compilers) comes from compatibility with C and with older versions of itself. If you strip away all that, the core language that most people deal with isn't quite as daunting.
That being said, nobody is claiming that C++ isn't a difficult language to master. Scott Myers has made a career of pointing people away from it's darkest corners, after all.
But really, C++ programming took a quantum leap forward with C++11, and C++14 just filed away some of the rough edges. It's hard to explain to non-C++ programmers what a transformation it was. I'm not expecting nearly as much with C++ 17, but I look forward to seeing if any of the proposed features will be useful in my day-to-day work.
Re:Sweet (Score:4, Interesting)
The C++ committee (rightly so, I think) tends to prefer library-based solutions whenever possible, because there's less chance of disruptive changes when you add new libraries. Only when a library solution won't work do they turn to new language features. You'll also notice they really don't like adding new keywords at this point.
A lot of people seemingly don't understand how important this backwards compatibility is (presumably because they're always rewriting stuff using the latest new-and-shiny tech), but there are many places that have code that's decades old. It's a terrible idea to go and tinker with robust, well-tested code just because it's not the latest new-and-shiny. The careful attention to backwards-compatibility causes a lot of issues (like slow compile time / language complexity, etc), but it's also one of C++'s greatest strengths. People know that an investment in C++ code will be working just fine for decades to come. I mean, they're just now depreciating trigraphs, for pete's sake. Apparently IBM still has code that uses those and opposed their removal in the last standards round, but they're a tiny minority and couldn't sway the committee this time. No one else even knows what the hell they are.
Look how much of a rift the Python 2 to 3 change caused. Even if it's good for the language, incompatible changes that occur too quickly can cause real problems for a programming community. Even after 8 years, a significant percentage of Python programmers are still using 2.x instead of 3, mostly because of dependencies holding them back.
Nothing would kill new C++ features faster than incompatibility with legacy code. And in fact, one of the nice things about C++ is that it typically allows programmers to start adding those new features piecemeal as they get more familiar with them and as they get compiler support.
Re: (Score:2)
Well, actual data say otherwise. [i-programmer.info] If you've got some data that points to contrary trends, I'd be happy to take a look. The good news is that it's trending in the correct direction, albeit slowly.
If that's what you think, then your knowledge is about 7 years out of date.
You're telling me that only a year or so after Python 3 was released, most people were using it? Funny, that's not how I seem to recall things. Yes, there are tools like 2to3 (and even 3to2), but automated tools aren't magic, and can't fix everything.
Nearly all new Python development is done using Python 3, and this has been the case for many years now.
Well, yeah, no kidding. You don't have to worry about legacy c
Re: (Score:2)
Yeah, C++11 was a major improvement; much of the extra "complexity" actually ended up making a lot of things much simpler. The new "auto", the new lambdas, and the new "smart" for loops, between them, allow writing simple, straightforward code to do things which would have required a tangled, opaque, and fragile mess of barely-readable code in older versions of C++.
Rvalue-references and std::move are a little trickier to understand, but fortunately, they can provide benefits even if you don't use them direc
Re: (Score:2)
C++ needed more features.
C++ needs more features to fix all the problems with the previous round of features.
c++ is now the world's most complex language (Score:4, Insightful)
I look back fondly at "c with objects". At least I could decipher the error messages.
Re: (Score:2)
cfront, baby. That's all that was ever needed, right there.
Re: (Score:2)
I look back fondly at "c with objects". At least I could decipher the error messages.
Well, C++ is fully backwards compatible.
But, please use STL. That WeirdCollection class is annoying to figure out.
Re: c++ is now the world's most complex language (Score:5, Insightful)
Re: c++ is now the world's most complex language (Score:4, Informative)
Re: (Score:3)
Swift is used as app programming language for apple's flagship products.
Re: (Score:2, Insightful)
Comparing unusable trash to unusable trash? How is that going to help? Or are you grading language quality on "hipness"?
Sigh (Score:5, Funny)
Still no functional gonkulators. Still no encabulation templates. Still no dichroic monads or parameterized gussets. When will the C++ committee ever get around to adding modern language features that users actually want?
They also forgot (Score:5, Funny)
Open closures, interior decorators, and conditional consts. In protest I'm gong back to c++--
Re: (Score:2)
Re: (Score:2)
And the do_what_I_want() function is still sorely missing! Despite being so well defined.
Re: (Score:2)
Hand in your engineer card right now. For those who don't get the reference... [youtube.com]
If initializer (Score:5, Insightful)
I appreciate the idea behind if initializer. This is actually a somewhat common pattern.
if (MyClass *p = getMyClassOrNull() {
p->doYourThing();
}
But I fear using initializer statements easily gets too long for a line, and couldn't it already be done with the comma operator?
Re: (Score:2)
Re: (Score:2)
No because you can't put a declaration inside the if statement right now. You could use the comma operator to give an already declared variable a value before the boolean expression, but the variable would have scope outside of the if statement.
Yes, you can. The example I showed above works right now, and always have. The problem is that it declarations evaluate to their values, so you can only do it if the value is something that has a useful boolean conversion (like not-null of pointers). The standard would expand the same to more types of expressions. But I can't see why this wouldn't already work:
if (MyClass *p = getMyClass, p && p->ofTheRightType())
p->doTheRightThing()
Re:If initializer (Score:4, Interesting)
No because you can't put a declaration inside the if statement right now. You could use the comma operator to give an already declared variable a value before the boolean expression, but the variable would have scope outside of the if statement.
Yes, you can. The example I showed above works right now, and always have. The problem is that it declarations evaluate to their values, so you can only do it if the value is something that has a useful boolean conversion (like not-null of pointers). The standard would expand the same to more types of expressions. But I can't see why this wouldn't already work:
if (MyClass *p = getMyClass, p && p->ofTheRightType())
p->doTheRightThing()
Wait, I think I figured it out. The comma operator doesn't work after declarations. In a declaration a comma signifies a declaration of another variable of the same type.
Re: (Score:2)
Re: (Score:3)
I really hate it because it now makes ( ) a scope boundary. Previously, you could just assume looking for { } as a scope boundary. This is important because it makes it harder to debug while half asleep.
It is not the parenthesis that is the scope boundary, it is the keyword. This is no different from 'for' statements where 'int i' is often declared. And note my example above already works right now, though it something that is either encouraged, or heavily frowned upon in coding styles. It looks weird and unnatural unless you are used to it.
Missing features (Score:4, Interesting)
Re: (Score:2)
Unfortunately the most important features weren't added. Concepts, modules, reflection and concurrency ... those would actually fixed almost all the things, where c++ is lacking now. Hope those will get into the next standard at least.
Well someone other than gcc has to implement a working version of concepts. As long as only gcc supports them they will keep getting postponed.
Re:Missing features (Score:4, Informative)
I'm still waiting for it to have a poorly specified implementation of *all* of common Lisp.
Re: (Score:2)
I'm still waiting for it to have a poorly specified implementation of *all* of common Lisp.
A poorly specified one? That is literally JavaScript.
Re: (Score:3)
A poorly specified one? That is literally JavaScript.
No, it isn't! JavaScript is a very well-specified implementation of all of Scheme, conveniently wrapped in a syntax which makes it as difficult as possible to actually use that Scheme implementation.
Re: (Score:2)
Re: (Score:2)
I recall somebody with knowledge of both saying that C++ definitely lacks full macros, even though templates come close.
Re: (Score:2)
You want them to rush in incomplete features?! (Score:4, Insightful)
What are you trying to say? That they should rush in features that haven't been thought through? That they should put half-arsed or broken features in place just to say that they have? That they should then support these broken features for decades, since that's how long C++ projects tend to live?
Look, if you want a language with buzzword features thrown in left and right, with changes to these features happening just about every release, then maybe a programming language like Rust is what you're looking for. C++, on the other hand, is a language meant for professionals to use when developing complex systems that won't just be used next week, but will be used 15 or 20 years from now, assuming they aren't still being used long after that. Those standardizing C++ have a huge responsibility on their shoulders. They can't goof around with C++. If a change is made to the language, it has to be thought out thoroughly and it has to be the right thing to do.
Re: (Score:2)
If I hadn't commented already, I would mod the parent post up.
This really is the point, which seems to be far beyond the comprehension of JavaScript greenhorns and the like: I wrote C++ library code > 20 years ago which is still actively maintained as part of complex, commercial server software.
Sure, some minor adjustments had to be made of the decades, as we want our source code to be compatible with at least the penultimate C++ ISO standard. But other than this, the software still runs fine on differen
Re: (Score:2)
I wrote C++ library code > 20 years ago which is still actively maintained as part of complex, commercial server software.
This feature is drastically undervalued.
Re: (Score:2)
That they should rush in features that haven't been thought through? That they should put half-arsed or broken features in place just to say that they have?
You mean like export? Or auto_ptr?
Re: (Score:2)
It's a feature of C++ that's in the C++ standard.
Although it is officially deprecated, so it might not be in C++17.
Re: (Score:2)
Re: (Score:2)
Nevermind managed execution to avoid buffer overruns and other "memtrashing" failures that have been a huge security clusterfuck over the last few decades...
I believe you have mixed up C++ with some other language. C++ does not have any such buffer overrun issues (unless you treat it as "C with classes", of course).
Re: (Score:2)
But it is guarenteed at runtime because otherwise the linker would have failed. Reflection would be expanding on the existing run-time type information (rtti) of C++. Though I personally don't particularly like the rtti system, it certainly is there and could do with a few features to make it more useful. I would prefer more compile time information.
Yet... (Score:3)
There's still no std::string split() method.
Re: (Score:2)
There's still no std::string split() method.
It's in boost. http://www.boost.org/doc/libs/... [boost.org]
Re: (Score:2)
Do you have any actual benchmarks that supports what you imply?
Regex matching isn't exactly super lightweight and while the memory allocation needed to create new objects might be rough I find it very hard to believe that it would come close to the efficiency of tokenizing.
I think the bigger problem is that memory allocation means having to define ownership. Methods that doesn't risk leaking are preferred. By yes malloc is very expensive, it has a tendency to cause cache-misses, where iterating over something locally doesn't.
Re: (Score:2)
Only common sense.
First, regexp matching is super lightweight when the regexp is trivial, like a fixed string with only terminal symbols.
Second, it's not like split() could somehow skip the tokenization. It does all the same, plus allocating storage and copying data into it.
Re: (Score:2)
Reading comprehension. You fail it.
Not impressed. (Score:3)
I'm not that impressed with the "if statement with initializer" addition and especially not impressed with one of their examples that use it to make things more compact. I don't like declaring the same variable twice and think more traditional coding would actually be cleaner.
status_code foo() {
int n = get_value();
if (status_code c = bar(n); c != status_code::SUCCESS) { return c; }
if (status_code c = do_more_stuff(); c != status_code::SUCCESS) { return c; }
return status_code::SUCCESS;
}
Seems like a pretty pointless addition.
Freedom, horrible freedom! (Score:2)
C++ aficionados, your vexing problem has been solved! That is to say, your complex language has added a new "if" structure with more side-effects to enhance the impenetrability and opportunity for obscurantism that we all value so much.
Re: (Score:2)
C++ aficionados, your vexing problem has been solved! That is to say, your complex language has added a new "if" structure with more side-effects to enhance the impenetrability and opportunity for obscurantism that we all value so much.
Not a big deal. A simple code analysis tool should easily identify the problem.
But in the real world ... (Score:2)
Still a bad language (Score:2)
And ironically, one of its most severe shortcomings is that it is far too complicated. Seems they are hard at work on making things worse.
Personally, I have moved back to C for anything that needs efficiency and use Python for anything that does not. The two also combine well.
Re: (Score:2)
Obligatory video (Score:4)
All you need to know about C++17 is here: https://www.youtube.com/watch?... [youtube.com]
Did they finally fix calling a virtual function .. (Score:2)
Did they finally fix calling a virtual function of a containing class during the constructor or destructor (or other initialization) of a member object of a derived class that provides a new overriding for the virtual function?
It should be strongly defined to get the base class version of the virtual function until the first line of the derived class constructor is executing until the last line of the derived class destructor has executed.
I have been asking for this since the first round of standardization.
Re: (Score:2)
It should be strongly defined to get the base class version of the virtual function until the first line of the derived class constructor is executing
then the derived class version
until the last line of the derived class destructor has executed
(except when further overridden by additional layers of derived classes, of course).
Rats! (Score:2)
Goshdiggettydarn! I haven't got round to learning C++11 yet.
Is 4 errors per line typical for Rust programmer (Score:3)
use rust = Use Rust.
Its simpler safer and its better = It's simpler, safer, and better.
You wrote two lines. With 8 errors. Is four errors per line about average for Rust programmers?
Re: (Score:2)
Well, Rust has a lot of handrails and safeguards, so I guess it leads to lazy writing...
Re: (Score:2, Insightful)
Lol. +1 funny (Score:2)
+1 funny
Re:c++ needs to know its place (Score:4, Informative)
Re: (Score:2)
on the what?
Re: (Score:2)
Unmanaged code is inherently unsafe. C++ may be necessary in places but it doesn't belong in a line of business application
You can write managed code with C++.
Examples, Microsoft's C++ CLI and Clang LLVM.
Re: (Score:2)
And what language is the managed code runtime/manager written?
I know! It's managed code all the way down!!!
Re: (Score:2)
C++ is still my favorite language, but I gave up on many features long ago. Even on templates ! Why ? Because just one stupid mistake can produce hundreds of compile errors. And also, I don't want my code to become Perl like : a write only language.
Template errors are fine but compilers need to do a better job at displaying the error.
Most of modern C++ has been trying to be more like Java/C# like, not Perl like. Sometimes it makes things worse because there is hidden complexity behind the simple things.
Re: (Score:2)
Most of modern C++ has been trying to be more like Java/C# like, not Perl like.
In one important respect, modern C++ is trying very hard to be less Java/C#-like. Simula's broken object model is still the answer to most problems in Java and C#, where C++ has come up with better answers. The use of the keyword "virtual" in the C++ standard library is far more rare than most people think. It doesn't appear in the STL at all (apart from things which derive from std::exception).
Re: (Score:2)
I considered saying words to that effect, but then I realised that I honestly don't know how often virtual appears in the parts of the library that nobody uses (e.g. std::locale). I could have grepped it to find out, but that seems like a lot of effort for an offhand Slashdot comment.
Re: (Score:2)