New answers tagged

2 votes

Binary file reader and writer

Missing error checking There are many things that can go wrong when operating on files. You only check if the file was opened correctly, but things can also fail when reading, writing and even closing ...
G. Sliepen's user avatar
  • 50.5k
2 votes

Recreating Minesweeper

There are already some good reviews from the C++ point of view. So let me give suggestions from a software architecture point of view. The code scores an absolute zero from an architecture point of ...
Ajinkya Kamat's user avatar
1 vote

Asynchronous OOP-based networking using the Epic EOS SDK

Naming things There are several things that are named confusingly. Names should be precise and concise; they should convey quite clearly what they stand for in one or a few words. Prefer to use ...
G. Sliepen's user avatar
  • 50.5k
2 votes

A recursive_minmax Template Function Implementation in C++

Bug You iterate the range twice, once for each partial result, which is forbidden for a simple std::ranges::input_range. You need at least a ...
Deduplicator's user avatar
  • 18.9k
1 vote
Accepted

A recursive_minmax Template Function Implementation in C++

Separate concerns You are not following the principle of separation of concerns. Whenever you write a recursive_foo() function, you should separate the concern of ...
G. Sliepen's user avatar
  • 50.5k
1 vote

A simple threadpool in C++17

Incorrect #includes You have lots of unnecessary #include statements, for example ...
G. Sliepen's user avatar
  • 50.5k
6 votes
Accepted

Binary file reader and writer

Here are some things that may help you improve your code. Avoid redundant code The BinaryFile class adds very little other than some error messages. I'd suggest ...
Edward's user avatar
  • 65.3k
2 votes
Accepted

Re: C++ 4X Game

Just seperating the game_logic from input processing has made a huge difference in terms of code clarity. In this review, I will start with nitpicks with the ...
Ajinkya Kamat's user avatar
3 votes
Accepted

C++ printing library with templates

C++23 and the {fmt} library can print ranges I was mad C++ did not have support for printing containers. C++23 will have the ability to print the contents of containers, and even better of any range....
G. Sliepen's user avatar
  • 50.5k
2 votes
Accepted

Implementing an Object type in C++

Use std::variant instead With your code you have to write a visitor like this: ...
G. Sliepen's user avatar
  • 50.5k
3 votes
Accepted

Spatial radius search in Boid simulation

Nice problem! I gotta tell ya, QuadTrees is definitely the appropriate datastructure. And it's just not that hard. Let coord be the bit interleaving of ...
J_H's user avatar
  • 16.9k
3 votes

Spatial radius search in Boid simulation

The slowness comes from drawing Your query() function is actually quite efficient. The problem comes from drawing the boids. If you remove the calls to ...
G. Sliepen's user avatar
  • 50.5k
9 votes
Accepted

Gaussian elimination algorithm in C++

Adding to pacmaninbw's answer: Naming things matrix2 is not a matrix, it's a vector. I would just call it a vector to avoid any confusion. Of course, since you used ...
G. Sliepen's user avatar
  • 50.5k
12 votes

Gaussian elimination algorithm in C++

Don't Mix C Language I/O with C++ I/O The code is using both printf() statements combined with std::cout, this is generally a ...
pacmaninbw's user avatar
  • 23.5k
2 votes

Terminal Based Game [v2]

Here are some things that may help you improve your code. Use the required #includes Within GameField.h, the code refers to <...
Edward's user avatar
  • 65.3k
1 vote

Casino Number Guessing Game

seems pretty solid, I only have 2 small things to say: first inside bool continuePlaying() you don't need Ternary Operator you can just write it as ...
Ellie's user avatar
  • 347
1 vote
Accepted

Lazy/deferred OOP-based networking using the Epic EOS SDK

Separate concerns Try to separate concerns in your code where possible. For example, your QueueCommands deals with too many things at the same time: it is a queue, ...
G. Sliepen's user avatar
  • 50.5k
2 votes

Terminal Based Game [v2]

I couldn't read everything, but I have several things to say: Beautiful usage of std::count here: ...
Coral Kashri's user avatar
2 votes

C++ implementation of a concurrent queue and of a thread pool

Remove empty() The result of empty() is a lie. Consider that between returning the result and the caller looking at it, some ...
G. Sliepen's user avatar
  • 50.5k
0 votes
Accepted

ReadDirectoryChangesW Improvements

Simplify the interface Do you really need all those public member functions? It looks like processedFilesCount() and ...
G. Sliepen's user avatar
  • 50.5k
1 vote

How to interface a "pull" library with a "push" library using callbacks

You are using a busy-loop to wait for publish_count to be incremented by the interrupt handler. In general, this is a bad way to wait for something to happen, as it ...
G. Sliepen's user avatar
  • 50.5k
2 votes

Terminal based game - walking and collecting points

Point class: Consider using an existing math library (e.g. glm). It can be more complicated to set up initially, but provides things like simple math operators (e....
user673679's user avatar
  • 11.6k
0 votes

C++ ring buffer using some C++ 17 and coming C++ 20 std::span

As long as the index values are not insanely high, you could use recursion and still have odd size arrays. ...
Paul Bruner's user avatar
-1 votes

Parser Composition - a parser directive for Boost Spirit X3

@Justin, I'd suggest filter_input as a more descriptive name since that's, in essence, what it does. It changes the input to the Secondary parser using the std::...
user1681377's user avatar
1 vote

"Rock Paper Scissors" game

The code looks good and well-organized. Here are a few suggestions: Use const wherever possible to make the code more readable and safe. For example, in ...
ubuntubuntu's user avatar
1 vote
Accepted

Partial specialization of class template with minimal code duplication

I would avoid inheritance and go for the implementation in the addendum. However, you can significantly simplify it: It's fine to unconditionally use std::ref() in ...
G. Sliepen's user avatar
  • 50.5k
8 votes
Accepted

"Rock Paper Scissors" game

Overview I don't like how you are simply passing strings around for the values. Its simple but not very optimal. I would create some enum types to represent the different states (Win, Lose, Draw) and/...
Martin York's user avatar
  • 94.3k
7 votes

"Rock Paper Scissors" game

Computing pcSelection can be factored out into a separate function. If users enter an invalid choice, promptUserInput still ...
Ajay Theetharappan's user avatar
3 votes

Integer endianness types for protocol structures, take 2

Adopt C++23 Since the code was written, C++23 introduced std::byteswap(), which enables a completely different implementation for the common case where native-...
Toby Speight's user avatar
4 votes
Accepted

BF Interpreter in C++

...
Toby Speight's user avatar
4 votes
Accepted

Class for locking shared disk directory

This is not safe Let's consider two threads that each call tryToLock() at the same time, and there is an expired lockfile on the disk: ...
G. Sliepen's user avatar
  • 50.5k
4 votes

Class for locking shared disk directory

spec at first glance works without errors. I'm willing to believe that's true. You've not made it easy to verify it at second glance. What I'm looking for is a concise specification of intended ...
J_H's user avatar
  • 16.9k
5 votes

C++ heap allocator using an explicit free list

Overview Must say that when reading complex code, the first thing I want to read is the constructor and destructor. Personally I always put these first in a source file. Without understanding these ...
Martin York's user avatar
  • 94.3k
5 votes
Accepted

C++ heap allocator using an explicit free list

You are overthinking alignment malloc() and new will return a pointer that is already suitably aligned for any built-in type, ...
G. Sliepen's user avatar
  • 50.5k
3 votes
Accepted

Multi producer/consumer lock-free queue

This is not lock-free Unfortunately, your queue is not lock-free. Basically, your _canUpdate is used as a lock. Consider a thread that has taken the lock, so it's ...
G. Sliepen's user avatar
  • 50.5k
0 votes

Calling fgets() twice

This is DavidC.Rankin's code with modification for overflow. ...
mortenlund's user avatar
12 votes
Accepted

Calling fgets() twice

Well, for starters, you really want to decide whether you are coding in C or C++. You #include <iostream>, but make no use of any iostream functions (...
David C. Rankin's user avatar

Top 50 recent answers are included