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."
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.
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.
Intend to stay abreast of the spec, do you?
I've fallen off your lawn, and I can't get up.
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
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.
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.
Herb Sutter responded to this on his blog (Sutter's Mill): http://herbsutter.com/2013/08/...
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);
boost::asio::async_write(device, buffer, handler);
Iterators another good one:
typedef void (*FunctionPtr)();
std::map<std::string, FunctionPtr> knownCommands;
std::string command = "example";
std::map<std::string, FunctionPtr>::iterator it = knownCommands.find(command);
/// or
auto it = knownCommands.find(command);
if (it != knownCommands.end()) {
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.
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.
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.
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.
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.
> 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.
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.
now we just need to throw the stone in the Marina Trench.
factor 966971: 966971
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
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.
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.