10 ms·
Looking at C++14
- deleted 13y ago[deleted]
- mindstab 13y agoI was really excited about learning/using some of the new stuff coming in c++11 and so on until a new job introduced me to Go lang. Now it seems like all of that stuff and more, elegantly built in instead of bolted on. To be fair I think it has a big bent towards server apps and not all general purpose stuff so it only to me seems better for a subset of all c++ work. on the other hand, Mozilla's Rust also looks interesting. Does anyone else feel like c++ is finally starting to be replaced in different segments by more target newer more elegant languages?
- agwa 13y agoI don't think Go is attracting many programmers away from C++ (in fact Rob Pike has expressed surprise at this) because it lacks some of the important good qualities of C++: strong typing (which Go lacks because of its lack of templates/generics) and RAII-style resource management. Instead Go is attracting programmers away from interpreted languages like Python since it has many of the nice qualities of interpreted languages while being very fast. Rust may be a different story (still too soon to tell) because it shares many of the fundamental philosophies of modern C++ without having a "bolted-on" feel. Still, it will be very hard to ever displace C++, because so much code is currently written in C++ and C++ has proven to be a very good language for code that needs to last decades.
- wyager 13y ago>Go lacks because of its lack of templates/generics This is one of my big frustrations with Go. I see lots of ugly `interface` based patterns. I wish more languages would adopt Haskell's typing system (at least partially). It is truly beautiful.
- adamnemecek 13y ago> Still, it will be very hard to ever displace C++, because so much code is currently written in C++ and C++ has proven to be a very good language for code that needs to last decades. I'm pretty sure that Rust devs are aware of that which is why they made Rust compatible with C/C++.
- bjz_ 13y agoThe big issue is that C++ FFIs are notoriously hard to implement. Often C wrappers are the only way to go (Rust has an excellent C FFI). As far as I know, I think D is one of the best out there regarding C++ compatibility, but it is still lacking.
- LnxPrgr3 13y agoThis—also, C++11 is an amazing improvement over C++03, and C++14 looks like another step in the right direction. For a small example, a friend talked me into implementing a few Scala collection operations in C++11. Here's the result: https://gist.github.com/LnxPrgr3/6547131 https://gist.github.com/LnxPrgr3/6547131 Usage looks like this: const collection<vector<string>> names = {"Daniel", "Chris", "Joseph"}; return names.reduce_left<string>([](const string &total, const string &value) { return total + ", " + value; }) == "Daniel, Chris, Joseph"; // ... const collection<vector<string>> strs = {"1", "2", "3", "4", "5"}; auto rv = strs.map<collection<vector<int>>>([](const string &x) { return atoi(x.c_str()); }); return rv.size() == 5 && rv[0] == 1 && rv[1] == 2 && rv[2] == 3 && rv[3] == 4 && rv[4] == 5; This is from a collection of tests, which looks like this: struct test { const char *name; function<bool ()> fn; }; const vector<test> tests = { {"Foldleft", []{ /* .... */}}, {"reduceLeft on empty throws", []{ /* ... */ }}, // ... }; for(auto &test: tests) { cout << test.name << ": " << flush << (test.fn() ? "PASS" : "FAIL") << endl; } I would've never considered something like this useful in C++03—callers would have to create named functor classes just to do some trivial one-line operation, this vector of tests would've had to have been a series of push_back calls, and iterating over it would've been quite a bit uglier. This isn't at all an exhaustive list, but these are the biggest things that come to mind when I think of what C++11 gains over C++03.
- zanny 13y agoIf anything, C++11/14 take the steam out of the languages that were gaining ground against really painful C++03 coding. In benchmarks Go keeps performing somewhere between Java and C++, but it isn't at the baremetal performance of C / C++ yet. Don't know if it can get there with its abstractions. Rust is closer, but it concedes a lot of glyphic syntax (such as requiring :: for scope like in C++ rather than, say, one colon) but I don't see it hitting prime time until Mozilla is ready for Servo to enter Firefox. It needs a big project behind it to show its capable.
- banachtarski 13y agoWait, I'm confused. I would think that the opposite would be true. You don't even have generics in Go. Rust is probably more what you're after.
- sheetjs 13y agoWhat is the current state of C++11 support in major compilers (e.g. G++, clang, MSVC)
- en4bz 13y agoFull in g++ 4.8 and Clang 3.3 with the exception of <regex>. MSVC is still behind.
- agwa 13y agoIt's excellent in GCC and clang. GCC 4.8.1 was feature complete. GCC C++11 status: http://gcc.gnu.org/projects/cxx0x.html http://gcc.gnu.org/projects/cxx0x.html Clang: http://clang.llvm.org/cxx_status.html http://clang.llvm.org/cxx_status.html MSVC is not as good. I don't have any links handy, but anecdotally it still fails to compile some of my code that compiles fine in GCC.
- jarjoura 13y agoMicrosoft should join the LLVM group and just port any MSVC extension not supported in clang over already. :-)
- jzwinck 13y agoGCC 4.8 (and even earlier) has <regex> but it doesn't actually work. I guess it will work in 4.9, but haven't gotten to try it. This glaring omission somehow didn't make the list you linked, which is otherwise exceedingly comprehensive.
- agwa 13y agoGood point, I guess that table only shows language features. Here's the library features table: http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#status.iso.200x http://gcc.gnu.org/onlinedocs/libstdc++/manual/status.html#s... Not feature complete if you take that into account, I'm afraid.
- elnate 13y agohttp://cpprocks.com/c11-compiler-support-shootout-visual-studio-gcc-clang-intel/ http://cpprocks.com/c11-compiler-support-shootout-visual-stu... A little out dated but a good starting point. I'm using gcc 4.6.1 and am loving the C++11 features, only thing I've noticed it missing is implicit capture of this in lambdas.
- diydsp 13y ago>C++14 brings core language support for binary literals, which means you now can integrate binary literals as such in your code: >char c = 0b01011010 I can't believe this took TWENTY YEARS (or at least that's how long I personally have been waiting). Hurray! (I'm going to hobble my walker over to the desktop and start codin' binary.)
- kps 13y agoBoost has a macro that's usable in plain C as well, since it uses only the preprocessor. #include <boost/utility/binary.hpp> char c = BOOST_BINARY(01011010);
- stingraycharles 13y agoYeah but that is a but similar as BOOST_FOREACH before c++11 -- it just isn't making things any prettier. I think most people nowadays are conditioned to parse the enum-as-bitmasks 0x01, 0x02, 0x04, 0x08 etc, so i would be reluctant to use boost's version in that case. The new operator, however, seems pretty sweet for that use case!
- pkrumins 13y agoHere's one of my all-time favorite way to write binary literals in C by abusing define: #define HEXIFY(X) 0x##X##LU #define B8IFY(Y) (((Y&0x0000000FLU)?1:0) + \ ((Y&0x000000F0LU)?2:0) + \ ((Y&0x00000F00LU)?4:0) + \ ((Y&0x0000F000LU)?8:0) + \ ((Y&0x000F0000LU)?16:0) + \ ((Y&0x00F00000LU)?32:0) + \ ((Y&0x0F000000LU)?64:0) + \ ((Y&0xF0000000LU)?128:0)) #define B8(Z) ((unsigned char)B8IFY(HEXIFY(Z))) And now you can write: B(01011010) Etc. If you like this, see my blog post about bithacks.h: http://www.catonmat.net/blog/bit-hacks-header-file/ http://www.catonmat.net/blog/bit-hacks-header-file/
- dbaupp 13y agoUsing octal (0o) gives you larger representable numbers, fwiw.
- halayli 13y agoI wish they add a new operator: "in" ... then it can be defined in maps and whatnot for lookups: if (123 in x)
- gamegoblin 13y agoI do find it odd that there isn't even a .contains(x) function and I have to use .count(x)
- halayli 13y agoC++ suffers from the too many cooks in the kitchen syndrome. They sometimes miss the basics.
- shin_lao 13y agoYou're not thinking C++ish. There is a wide range of algorithms to find/modify/replace data in containers. Let's say you have a set of ints, doing what you want is the following: std::set<int> blah; // ... some stuff happens ... if (blah.find(123) != blah.end()) { // ... } Now, you're saying, "but my container doesn't have find!". Not a problem, you can use std::find! std::vector<int> v; // ... some stuff happens ... if (std::find(v.begin(), v.end(), 123) != v.end()) { // ... } Note that v can be ANYTHING, as long it supports forward iterators (which all containers do). Now you're saying, "but it's not very efficient! The complexity of find is O(n)!" True, true. If your container is sorted, you should use binary search O(log n): if (std::binary_search(v.begin(), v.end(), 123)) { // ... } What's great about this is that it works on any container, provided it's sorted. Then, what you can do is write a metafunction that will call the member function find() when it exists or use std::find() when there's none. This will automatically, and at compile time, use the most efficient way to check for the existence of an entry.
- halayli 13y agoI am not talking about how I end up searching the container. I am talking about the syntax. Besides, how a container is searched should be abstracted away in the container's implementation and the algorithm should be documented. Compare this syntax: > if (std::find(v.begin(), v.end(), 123) != v.end()) To > if (123 in v) If in is an operator and overloaded by std::vector, then it's easy to implement.
- greatsuccess 13y agoFor the love of God, or some other entity you find holy or unholy. Stop using this bastard of a language. Its an offront to software engineering and must simply die
- en4bz 13y agoWhat would you suggest instead? Until there is something that is as general purpose as C++ and has the same level of performance it will continue to survive.
- Filligree 13y agoRust?
- Pacabel 13y agoMaybe in 4 or 5 years, if things go well. There hasn't even been a 1.0 release yet. That's the bare minimum necessary for a lot of existing C++ users to even consider Rust as a potentially viable option. Assuming Rust 1.0 is released sometime this year, it'll still take a number of years before Rust even begins to offer the very wide range of libraries/frameworks that are available to C++ developers. Interfacing with these existing C++ libraries/frameworks may speed things up, but at that point its disputable whether it's really Rust being used. Rust may be among the most promising alternatives, but it's just not there yet, and won't be for some time.
- elnate 13y agoCare to justify your bile?
- epi8 13y agoNot everyone works in webdev. Some people do embedded development, and use a reasonable subset of C++.
- banachtarski 13y agoDo you play games? Do you play console games, or desktop games? Do these games support 3D rendering? Soft shadows? Physically based lights? Pathfinding of crowds of people or units? Literally hundreds of thousands of projectiles? Networked replication? Leverage all the cores of your desktop/device/console while doing the above? Support unique or specialized data structures? Execute a runtime that CAN'T tolerate non-deterministic GC pauses? I make games. What am I supposed to code that in? Fucking javascript? Ruby? C#? Go stfu and die yourself. If you want to come up with a language that can get the job fucking done than by all means, go for it and fail miserably. Otherwise, stop using any of the products that leverage C++. We don't want you.
- puppetmaster3 13y agoI here by announce, that C++ next version will be called D! More links here: http://dlang.org http://dlang.org
- platform 13y agoC++ is still missing optional Reflection/Introspection. With that feature it could easily replace majority of todays typed languages (with exception of language such has Haskell or Rust). Reason is that reflextion allows to close a 'external data types' dissonance that currently is present in C++. In other words it is not possible to develop 'framework software' that can introspect plugin/consumer code to derive how they view the externally defined data sources (eg Databases, UI kits, JSON streams/etc).
- vinkelhake 13y agoC++ study group 7 (SG7) is looking at various reflection proposals. https://groups.google.com/a/isocpp.org/forum/?fromgroups#!forum/reflection https://groups.google.com/a/isocpp.org/forum/?fromgroups#!fo...
- jjoonathan 13y agoThe first time I wondered how the hell C++ didn't support introspection, I was 1/3 as old as I am now. I have literally been wondering for most of my life. But hey, at least they have a Turing-complete template language to go with their macros! Priorities, right?
- vinkelhake 13y agoYes, priorities. The evolution of C++ is driven by its users in the industry. That C++ not yet has support for reflection or introspection is an indication that there hasn't yet been a great need for it. Any C++ user (you know, the people who actually use the language) will tell you that templates is a central part of the language and something that is far more important than introspection. Anyway, like I said in the other comment, there's a study group for reflection now. We'll see what comes out of it.
- jjoonathan 13y ago> Any C++ user (you know, the people who actually use the language) Funny, because I am a heavy C++ user (why did you assume differently?). C++ probably accounts for between 1/3 and 1/2 of my lifetime lines-of-code. Trouble is, I've had to use it for more than algorithms work, which is the only place I've ever seen templates shine. I've used a half dozen C and C++ GUI frameworks that painstakingly work around the introspection issue, and while these frameworks often make do quite nicely without templates, they always have a bolted-on monstrosity of an introspection system. Qt is probably the most direct example: they built their own preprocessor/parser around C++ to take care of their need for introspection. I'm glad there is a study group, but the absence of introspection has been hurting the C++ community for a long time. It's the flaw that has launched 1,000 high-level languages and 100,000 dirty hacks.
- sippeangelo 13y ago> 3781 - Single quotation mark as digit separator Hold on a minute. Why is this even a thing? Do people really use HUGE numeric literals and have so much trouble reading them that this is needed? This just sounds like another parsing nightmare that really should belong in syntax highlighting rather than exist as some obscure language feature.
- jjoonathan 13y ago> Do people really use HUGE numeric literals Yes. Engineering code uses numeric literals with many digits all the time. > and have so much trouble reading them that this is needed? Digit separators make digit omissions/additions much easier to spot. Imagine spending a day trying to track down a "everything explodes" bug, systematically eliminating numerical sources of error one by one, only to find that the problem is a misspecified boundary condition that you didn't catch the first time around because you were counting the number of zeros as opposed to the number of digits. c = 3000'000'000 /* m/s */ ^ I can spot this out of the corner of my eye. c = 3000000000 /* m/s */ ^ This? Not so much.
- papaf 13y agoI prefer this alternative: c_millisecs = 50000 * 60 * 1000; // 50,000 minutes
- dm2 13y agoI prefer (1000 * 60 * 60 * 24 * 2) == 2 days
- jjoonathan 13y agoThat only works for unit conversions where they're defined as ratios of each other. Nature has physical constants and engineers have environmental and design parameters that can't be written that way unless you constantly change units, which is a bad idea in a language without built-in unit checking (most of them).