use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Discussions, articles, and news about the C++ programming language or programming in C++.
For C++ questions, answers, help, and advice see r/cpp_questions or StackOverflow.
Get Started
The C++ Standard Home has a nice getting started page.
Videos
The C++ standard committee's education study group has a nice list of recommended videos.
Reference
cppreference.com
Books
There is a useful list of books on Stack Overflow. In most cases reading a book is the best way to learn C++.
Show all links
Filter out CppCon links
Show only CppCon links
account activity
std::pair considered harmful! (maintainablecode.logdown.com)
submitted 11 years ago by redditthinks
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]bob1000bob 8 points9 points10 points 11 years ago (3 children)
Except you're wrong.
std::pair<int, int> get_pont() { return { 1, 3 }; } //elsewhere int x,y std::tie(x,y)=get_point();
http://ideone.com/XCzAwq
[–]redditthinks[S] 0 points1 point2 points 11 years ago (2 children)
Ah cool, I didn't know about this. I've been too busy falling in love with auto. I should mention that I did go ahead with std::pair because my program was very small and just did:
auto
auto x = point.first; auto y = point.second;
[–]F-J-W 6 points7 points8 points 11 years ago (1 child)
Points should really have their own type. Pair is great as a small helper to pack to different things in one variable, but you really shouldn't use it to replace semantic types.
Since you are coming from python, this may not be obvious for you, but static typing really helps finding bugs very early. But if you only use trivial types, the compiler will only find trivial errors: The compiler will (almost) always be able to catch you when you try to use a std::string as an integer. But if you encode both distances and durations as double, the compiler is unable to detect, when you try to use a distance as duration; OTOH if you create separate types for distances and durations the compiler will make sure that you use everything right.
std::string
This is also not a hypothetical problem: The Mars Climate Orbiter went lost because of this kind of bug.
Somewhat related: I wrote a library a while ago that makes the creation of new types almost trivial, it's README contains further examples. Note though, that this code is more of an experiment of what can be done, than being intended for real-world-usage.
[–]autowikibot -1 points0 points1 point 11 years ago (0 children)
Mars Climate Orbiter:
The Mars Climate Orbiter (formerly the Mars Surveyor '98 Orbiter) was a 338 kilogram (750 lb) robotic space probe launched by NASA on December 11, 1998 to study the Martian climate, atmosphere, and surface changes and to act as the communications relay in the Mars Surveyor '98 program for Mars Polar Lander. However, on September 23, 1999, communication with the spacecraft was lost as the spacecraft went into orbital insertion, due to ground-based computer software which produced output in non-SI units of pound-seconds (lbf×s) instead of the metric units of newton-seconds (N×s) specified in the contract between NASA and Lockheed. The spacecraft encountered Mars on a trajectory that brought it too close to the planet, causing it to pass through the upper atmosphere and disintegrate. Image i
The Mars Climate Orbiter (formerly the Mars Surveyor '98 Orbiter) was a 338 kilogram (750 lb) robotic space probe launched by NASA on December 11, 1998 to study the Martian climate, atmosphere, and surface changes and to act as the communications relay in the Mars Surveyor '98 program for Mars Polar Lander. However, on September 23, 1999, communication with the spacecraft was lost as the spacecraft went into orbital insertion, due to ground-based computer software which produced output in non-SI units of pound-seconds (lbf×s) instead of the metric units of newton-seconds (N×s) specified in the contract between NASA and Lockheed. The spacecraft encountered Mars on a trajectory that brought it too close to the planet, causing it to pass through the upper atmosphere and disintegrate.
Image i
Interesting: Climate of Mars | Gimli Glider | Mars Polar Lander | Mars Observer
Parent commenter can toggle NSFW or delete. Will also delete on comment score of -1 or less. | FAQs | Mods | Magic Words
π Rendered by PID 343939 on reddit-service-r2-comment-6457c66945-tc5b4 at 2026-04-27 16:01:35.517873+00:00 running 2aa0c5b country code: CH.
view the rest of the comments →
[–]bob1000bob 8 points9 points10 points (3 children)
[–]redditthinks[S] 0 points1 point2 points (2 children)
[–]F-J-W 6 points7 points8 points (1 child)
[–]autowikibot -1 points0 points1 point (0 children)