Hot answers tagged

16 votes
Accepted

Processing XYZ data from a large file

There are a number of things that may help you improve your program. Don't abuse using namespace std Putting ...
Edward's user avatar
  • 65.3k
14 votes

FizzBuzz, ’17-style

You're using cout without namespace qualifier which should not work. Personally I think typing std::string is better than ...
yuri's user avatar
  • 4,450
14 votes

FizzBuzz, ’17-style

It looks pretty good, but I think there are some small improvements to be made here. Spell out namespace The using std::string; isn't really particularly useful ...
Edward's user avatar
  • 65.3k
11 votes

Filter out elements from std::vector

You're essentially copying copy_if with some additional debug messages. One can rewrite your code with ...
Zeta's user avatar
  • 19.2k
11 votes

Processing XYZ data from a large file

Well, lets start from the CodeReview: Since this is not really a library, I will omit my typical "Make it easy to use correctly, hard to use incorrectly", but it is still important thing to ...
Incomputable's user avatar
  • 9,374
10 votes
Accepted

Random Number Generator with Loads of Useless(-ish) Features

First impressions I enjoyed reading this code. It's logically laid out (even the includes are alphabetical, so I can check at a glance), and I never felt like I was lost in the code. I do prefer my <...
Toby Speight's user avatar
9 votes
Accepted

Connect to telnet server

Ephemeris::Ephemeris() { } No need for a constructor if it does nothing. ...
Toby Speight's user avatar
8 votes

FizzBuzz, ’17-style

Be mindful of future enhancements (code always gets more complex over time) and localization. Your method assumes a very narrow range of future enhancements. You'll have trouble in the following ...
Winston Ewert's user avatar
8 votes

Processing XYZ data from a large file

Suggestion 1: Don't split the lines I don't see the need for splitting each line into tokens and extracting the numbers from each token. You can extract all the numbers from a line by using a ...
R Sahu's user avatar
  • 3,502
8 votes
Accepted

A Matrix Library in C++;

using namespace std; Never do that; certainly not in a header - that inflicts the harm onto every source file that includes the header. Prefer to include your ...
Toby Speight's user avatar
7 votes
Accepted

Detect if string contains more than 1 period

Optimize for maintainability first Is the complexity of your function really needed? The functionality can be implemented in one line using only standard-library algorithms. ...
5gon12eder's user avatar
  • 4,260
7 votes

FizzBuzz, ’17-style

Here are some more things that bother me a little (adding to what yuri already wrote in their answer): Design Ugh, globals Globals are bad. They introduce hidden state that the execution of your ...
Ben Steffan's user avatar
  • 5,228
7 votes

Processing XYZ data from a large file

class XYZCoordinate{ public: int x; int y; float z; XYZCoordinate(int X, int Y, float Z){ x = X; y = Y; z = Z; } }; Integrate a ...
Snowhawk's user avatar
  • 6,148
6 votes
Accepted

HTTP downloader using Beast

Missing Headers Before going any further, the current code is missing a few headers that it needs, namely: <functional> and ...
D. Jurcau's user avatar
  • 3,010
6 votes

Completed Makeshift Bash & Makefile To Compile C++ Examples

The biggest problem I can see is that you are not using idiomatic Makefile names, which will confuse readers and frustrate users who want to change things via the command line. Typically CFLAGS is ...
user141353's user avatar
6 votes

Printing a C++ struct

It only works for some structs Your print_struct() function only works for types that support aggregate initialization; it's not a perfect generic solution for ...
G. Sliepen's user avatar
  • 50.3k
5 votes
Accepted

Smart pointer memory pool

Per the comments, this isn't really a "pool" because things don't go back into it when you're done using them. It's just an "incremental allocator" that does allocation in "chunks". A better name for ...
Quuxplusone's user avatar
  • 19.3k
5 votes

Calculate the crc32 of the contents of a file using boost

I've got little to add to Martin Yorks great answer. I also think the loop approach is the better one, since it limits the amout of memory used for bigger files. However, I found a little mistake in ...
Jörn Schellhaas's user avatar
5 votes

time_t to string

Here's how to do this with std::put_time as mentioned in a comment. ...
Edward's user avatar
  • 65.3k
5 votes
Accepted

Brute-force search for solution to an unsolved mathematical inequality

A first step in optimizing would be to avoid computing the same values multiple times. Secondly, I would drop the floating point arithmetic altogether. You have integer bases with integer exponents, ...
D. Jurcau's user avatar
  • 3,010
5 votes

Filter out elements from std::vector

Pointless typedef In C, it's fairly common to have a typedef like this: ...
Jerry Coffin's user avatar
  • 33.5k
5 votes

Compile-time Lagrange polynomials in C++

struct evaluate ⋯ Compile-time computation is much easier today using constexpr! Rather than going for a pre-2014 TMP library,...
JDługosz's user avatar
  • 11.3k
5 votes

Processing XYZ data from a large file

Preallocate space in your vector for storage of your points, with .reserve(size). Without preallocation, ...
AJNeufeld's user avatar
  • 33.3k
5 votes
Accepted

Automatic Differentiation with C++ Header-Only Library

Does RealType have to be a type of floating point number (at least at the root level)? If so, perhaps this should be enforced using ...
user673679's user avatar
  • 11.6k
5 votes
Accepted

Using Boost.Spirit to transform expression to AST

I'll narrate this in the order I "discover" your code. Then I'll present some tweaks which I think mattered the most in the end. I'm liking a lot of what you've done. A few names could (...
sehe's user avatar
  • 1,322
4 votes
Accepted

Calculate the crc32 of the contents of a file using boost

You seem to be missing a seek to the end. This will always be zero. std::ifstream is{fp, std::ios::in | std::ios::binary}; size_t file_size = is.tellg(); ...
Martin York's user avatar
  • 94.3k
4 votes
Accepted

C++ Query String Parser

Looks largely correct on the surface. Of course there's plenty to fix! ...
Quuxplusone's user avatar
  • 19.3k
4 votes

Pattern for writing a generic string transformation function

Look at Boost.Range. Your first point drives most of the rest of the concerns. Write your template function to take a Range. You can pass it a C string literal, a std::string, an array, vector, or ...
JDługosz's user avatar
  • 11.3k
4 votes
Accepted

Calculating a ton of mathematical constants

I see some things that may help you improve your program. Use static const for performance The way it works right now, each function recalculates the value ...
Edward's user avatar
  • 65.3k
4 votes
Accepted

SCOPE_EXIT implementation

Move semantics: The makeScopeGuard() function accepts the lambda by r-value ref; but passes a normal ref to the constructor of ...
Martin York's user avatar
  • 94.3k

Only top scored, non community-wiki answers of a minimum length are eligible