Skip to main content
Search type Search syntax
Tags [tag]
Exact "words here"
Author user:1234
user:me (yours)
Score score:3 (3+)
score:0 (none)
Answers answers:3 (3+)
answers:0 (none)
isaccepted:yes
hasaccepted:no
inquestion:1234
Views views:250
Code code:"if (foo != bar)"
Sections title:apples
body:"apples oranges"
URL url:"*.example.com"
Saves in:saves
Status closed:yes
duplicate:no
migrated:no
wiki:no
Types is:question
is:answer
Exclude -[tag]
-apples
For more details on advanced search visit our help page
Results tagged with
Search options answers only not deleted user 489

Code that is written to the 2011 version of the C++ standard, sometimes known by its pre-publication name of "C++0x". Use in conjunction with the 'c++' tag.

4 votes
Accepted

Using inputted data from vector to create two outputs

Although there's room for argument that it might be an abuse, one way you could do the adjacent sums part of this would be to use std::adjacent_difference, but pass it a function that adds instead of …
Jerry Coffin's user avatar
  • 33.6k
3 votes

Better way to un-define a set of defines based on version numbers in C++?

While it's somewhat uncertain whether you'll like it (some compilers warn about doing so) it's entirely permissible to #undef a value that wasn't defined to start with, so you can consolidate these do …
Jerry Coffin's user avatar
  • 33.6k
1 vote
Accepted

Greatest Common Divisor of two or more integers

I think Martin R's suggestion is a good one, but I won't repeat it. I'll start by considering your questions directly: As far as the iterator-based gcd goes, my immediate reaction is to wonder whet …
Jerry Coffin's user avatar
  • 33.6k
6 votes

Flatmap implementation

There's a reason the algorithms in the standard library use iterators instead of dealing with containers directly. One is that it makes code like this quite a bit simpler. For example, using iterators …
Jerry Coffin's user avatar
  • 33.6k
6 votes
Accepted

A version of operator<< that returns ostringstream instead of ostream

Bjarne gives a pretty succinct description of why this (and many similar) features aren't in the standard. He points out that virtually everybody who talks to him about C++ has essentially the same th …
Jerry Coffin's user avatar
  • 33.6k
2 votes

Customizing output in accordance to the input

Streams already have a mode in which they detect the base of a number from the prefix, exactly as desired here. To get to it, you set the base for the stream to 0. So, a mildly simplified version of …
Jerry Coffin's user avatar
  • 33.6k
28 votes

shared_ptr and FILE for wrapping cstdio (update: also dlfcn.h)

I should start with the fact that I don't entirely agree with the widespread belief that "explicit is better than implicit". I think in this case, it's probably at least as good to have a class that j …
Jerry Coffin's user avatar
  • 33.6k
6 votes

Printing certain number of words from file

I can't help thinking that this seems somewhat...over-engineered. I think I'd consider something on this order as a starting point: #include <string> #include <algorithm> #include <sstream> #include …
Jerry Coffin's user avatar
  • 33.6k
11 votes
Accepted

Bezier curves of grade n

Just a few comments: std::vector<Vector2f> make_bezier(const std::vector<Vector2f>& anchors, double accuracy=10000.0) You're using float for all your other floating point variables. Unless there's …
Jerry Coffin's user avatar
  • 33.6k
5 votes

Asynchronous leadership election

First, a general observation: you have a fair number of typos in your comments. Although the compiler doesn't check such things, I prefer to think of the comments as an integral part of the code, so e …
Jerry Coffin's user avatar
  • 33.6k
8 votes
Accepted

Socket wrapper class

There are at least a few things I think I'd do differently, at any rate. const int MAX_RECV_LEN = 8096; const int MAX_MSG_LEN= 1024; const int PORT_NUM = 1200; The ALL_CAPS convention was original …
Jerry Coffin's user avatar
  • 33.6k
4 votes

Singly-linked grocery list

I'd start by making the code more generic: template <class T> class LinkedList { Then I'd probably separate the user's data (what you're storing) from "your" data (the links used by the list itself …
Jerry Coffin's user avatar
  • 33.6k
8 votes
Accepted

n-dimensional Euclidean space calculation templates

To reduce redundancy, I'd probably move the check for the inputs being the same size into a function template by itself, and just invoke that from the other three: template <typename T> void check_si …
Jerry Coffin's user avatar
  • 33.6k
2 votes

Generic Multiway Merge

My immediate reaction would be to accept a collection of ranges of some sort (e.g., Boost Range, or even just a pair of iterators). Since the range (or iterator) types would be template parameters, t …
Jerry Coffin's user avatar
  • 33.6k
4 votes
Accepted

Tree implementation for unordered keys

At least as it stands right now, quite a bit of your code accomplishes nothing. template<typename T, typename H> class tree; template<typename T, typename H> class tree : public std::unordered_map<T …
Jerry Coffin's user avatar
  • 33.6k

1
2 3 4 5
7
15 30 50 per page