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 ...
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 ...
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 ...
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
...
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 ...
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 <...
9
votes
Accepted
Connect to telnet server
Ephemeris::Ephemeris()
{
}
No need for a constructor if it does nothing.
...
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 ...
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 ...
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 ...
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.
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
5
votes
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, ...
5
votes
Filter out elements from std::vector
Pointless typedef
In C, it's fairly common to have a typedef like this:
...
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,...
5
votes
Processing XYZ data from a large file
Preallocate space in your vector for storage of your points, with .reserve(size). Without preallocation, ...
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 ...
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 (...
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();
...
4
votes
Accepted
C++ Query String Parser
Looks largely correct on the surface. Of course there's plenty to fix!
...
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 ...
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 ...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
boost × 173c++ × 172
c++11 × 40
performance × 19
recursion × 17
c++20 × 14
multithreading × 12
c++17 × 12
template × 9
c++14 × 8
asynchronous × 7
networking × 7
lambda × 7
numerical-methods × 6
producer-consumer × 6
parsing × 5
unit-testing × 5
file-system × 5
memory-management × 5
mathematics × 5
formatting × 5
socket × 5
algorithm × 4
strings × 4
error-handling × 4