Favorite little known or underused C++ features
#2 Moderators - Reputation: 7599
Posted 22 October 2012 - 01:34 PM
I'd further suggest that good portions of the standard library is of little use to games development.
/edit:
For underuse examples, most people will write their own simple functions rather than relying on the algorithm library. Some of the ordering and searching functions are used occasionally, but few people will use std::transform(), std::generate() when they need to come up with a bunch of items. I've seen programmers run full sorts rather than functions like stable_partition() or partial_sort() when they need just a few items. And almost nobody normally uses the heap functionality, even though it can be a very solid alternative to sorted containers, especially when it comes to bulk changes.
For not applicable functionality examples, the entire Localization library of the C++ standard library is difficult to apply to game development; it doesn't play nice with the major game development localization tools. The Diagnostics library is of limited use -- most games implement their own custom asserts, warnings, and such, and many game companies have exceptions disabled for better or worse. RNG in the standard library is not sufficient for games. Most of the IO libraries are useless for games because they are blocking. Etc.
Edited by frob, 22 October 2012 - 06:01 PM.
#4 Members - Reputation: 563
Posted 23 October 2012 - 01:52 AM
union {
struct {int x, y; };
struct {int u, v; };
}
x = 45;
cout << u;
I also like that the library and language is designed in such a way that the compilers can optimize usage of the library really well; gcc can optimize through almost everything in there.
Edited by patrrr, 23 October 2012 - 01:55 AM.
#5 Members - Reputation: 1950
Posted 23 October 2012 - 02:11 AM
It's potentially very relevant to games development too, yet I've never heard of its actual use anywhere.
My website dedicated to sorting algorithms
#6 Members - Reputation: 470
Posted 23 October 2012 - 03:10 AM
Especially std::function, auto built-in smart-pointers are some of my new friends
I think a lot of features are just not known to many developers and the STL contains a huge load of stuff that comes in very handy quite often, but one has to know that it is there in the first place
Edited by doeme, 23 October 2012 - 08:02 AM.
#8 Marketplace Seller - Reputation: 8925
Posted 23 October 2012 - 09:42 AM
Just FYI, there is a better RNG in the standard library for C++11 (Also higher-accuracy cross-platform timers).RNG in the standard library is not sufficient for games.
C++11, while mostly focused on improving the core language (which it did), does add a few things of interest to the standard library that will help game developers moving forward (such as easier multithreading and the TR1-promoted smart pointers).
I'm personally trying to learn the algorithms that have always been in C++, since I've not much experience in them; later I'd love to learn the proper usage of streams.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal
#9 Members - Reputation: 892
Posted 23 October 2012 - 10:00 AM
later I'd love to learn the proper usage of streams.
If you mean iostreams... i advise to skip those. They're not asynchronous (if you're using file streams), they're internally complex with many trippings for you to discover (even ignoring threading issues); you're gonna have problems with I18N (you can't use the format string as a resource, as is possible with [possibly positional] printf parameters), it's more cumbersome to read/write formatting specifications and so on...
STLport | Lua | Squirrel | Doxygen | NASM | bochs | osdev | Ruby | FreeBSD | Zend Framework 2 | YUI 3 | VP UML| ZFS | Linux Mint (Cinnamon)
#10 Members - Reputation: 2761
Posted 23 October 2012 - 10:24 AM
Professional Free Software Developer
#11 Moderators - Reputation: 1918
Posted 23 October 2012 - 10:41 AM
Steve Macpherson
Senior programmer, Firebrand Games
#13 Members - Reputation: 1027
Posted 23 October 2012 - 10:56 AM
#15 Senior Moderators - Reputation: 3113
Posted 23 October 2012 - 12:43 PM
That you can read and write from different elements in a union if the elements are structs and have the same prefix structure:
union { struct {int x, y; }; struct {int u, v; }; } x = 45; cout << u;
I also like that the library and language is designed in such a way that the compilers can optimize usage of the library really well; gcc can optimize through almost everything in there.
structures declared within an anonymous union are not legal C++. Its a visual studio extension.
-changed wording slightly
Edited by Washu, 23 October 2012 - 02:10 PM.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ScapeCode - Blog | SlimDX
#16 Members - Reputation: 563
Posted 23 October 2012 - 01:26 PM
anonymous structures within an anonymous union are not legal C++. Its a visual studio extension.
Crap, I've been looking the standard up and down and I didn't find anything that would make this illegal. Though I could've looked harder. Maybe there's a difference between C11 and C++11 in this regard? But I do know that it's not just a visual studio extension; it works well on gcc and clang as well.
#17 Members - Reputation: 427
Posted 23 October 2012 - 01:30 PM
Initializer lists are a much needed addition to the language. They add the ability to make classes feel more like POD's, even when they aren't.
std::vector<int> ivec = {1, 2, 3, 4};
//vs.
std::vector<int> ivec;
ivec.push_back(1);
ivec.push_back(2);
ivec.push_back(3);
ivec.push_back(4);
#18 Senior Moderators - Reputation: 3113
Posted 23 October 2012 - 01:55 PM
anonymous structures within an anonymous union are not legal C++. Its a visual studio extension.
Crap, I've been looking the standard up and down and I didn't find anything that would make this illegal. Though I could've looked harder. Maybe there's a difference between C11 and C++11 in this regard? But I do know that it's not just a visual studio extension; it works well on gcc and clang as well.
C++98 - §9.5.2
[Note: nested types and functions cannot be declared within an anonymous union.]
C++11 - §9.5.5
[ Note: Nested types and functions cannot be declared within an anonymous union. —end note ]
Edited by Washu, 23 October 2012 - 01:55 PM.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ScapeCode - Blog | SlimDX
#20 Senior Moderators - Reputation: 3113
Posted 23 October 2012 - 02:13 PM
Out of curiosity I'm guessing it was left out of the C++11 standard do to ambiguous naming as functions/variables would live in an unnamed inner scope?
In the anonymous case:
void f() {
union {
struct { int x, y; };
struct { int x, y; };
} u;
}
In the not so anonymous case its harder to come up with the same example, but there are similar issues.
I should note that the only places I've actually seen people use anonymous unions/structures was usually almost always a hack that could have been avoided.
Edited by Washu, 23 October 2012 - 02:15 PM.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
ScapeCode - Blog | SlimDX






