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 ...
15
votes
FizzBuzz, ’17-style
You're using cout without namespace qualifier which should not work.
Personally I think typing std::string is better than ...
15
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 ...
12
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
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 ...
9
votes
Accepted
Connect to telnet server
Ephemeris::Ephemeris()
{
}
No need for a constructor if it does nothing.
...
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
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 ...
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 own ...
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
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
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
Filter out elements from std::vector
Pointless typedef
In C, it's fairly common to have a typedef like this:
...
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
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 (...
5
votes
Accepted
Photo Reduction Tool version 2 - Possible reinvention of the wheel
Be consistent
You are not very consistent with how you name things. Here is a non-exhaustive list of inconsistencies:
FileCtrlValues: you use the abbreviation <...
5
votes
Accepted
Command Line Photo Size Reduction Tool - version 3
Pre-review check
Before I review anything, I want to make sure I understand what the intention of this code is.
So, with the way your program is currently set up, you have three program options that ...
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
SCOPE_EXIT implementation
Move semantics:
The makeScopeGuard() function accepts the lambda by r-value ref; but passes a normal ref to the constructor of ...
4
votes
Accepted
Compile-time Lagrange polynomials in C++
I don't want the whole function to be constexpr. I'd like to do without a for loop, but still supply the x at which to evaluate at runtime.
About constexpr
...
4
votes
Run an asynchronous child process with timeout
I'm still getting used to Boost::Process, so maybe I've got this wrong. However, do you really need the c.wait() after ...
4
votes
Accepted
C++ observer pattern via boost.signals2
Boost.Signals2 is a thread-safe library. It uses mutex locking internally. There are some caveats, as explained in this article:
Almost all classes provided by Boost.Signals2 are thread safe and can
...
4
votes
Fibonacci and Lucas sequence generator using Boost and GMP
I recommend using more compiler warnings - they can highlight issues such as
...
4
votes
Accepted
Non-nested std::deque and std::list Generator Function for arithmetic_mean Function Testing in C++
Make the desired container type a template parameter
You are duplicating a lot of code, when the only thing that changes is the type of container that your are returning. You should make the container ...
4
votes
Accepted
A Various Container Type Arbitrary Nested Iterable Generator Function Implementation in C++
Template vs. function parameters
Template parameters should normally be used for things that affect the type of the result, but not for other things. The template parameter ...
4
votes
Accepted
Nested std::deque and std::vector Type Test Cases for recursive_transform Template Function in C++
You are correct in your intuition that this isn’t really the best way to do this with Boost.Test. In fact, Boost.Test has about a half-dozen better ways to handle this, but I’ll focus on the one that ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
boost × 179c++ × 178
c++11 × 40
performance × 18
recursion × 16
c++20 × 14
multithreading × 12
c++17 × 12
asynchronous × 9
template × 8
c++14 × 8
networking × 7
parsing × 6
file-system × 6
lambda × 6
numerical-methods × 6
producer-consumer × 6
mysql × 5
unit-testing × 5
memory-management × 5
mathematics × 5
formatting × 5
socket × 5
algorithm × 4
strings × 4