Skip to main content
34 votes
Accepted

Rock, Paper, Scissors in C++

It's a good start! Here are some things that may help you improve your program. Don't abuse using namespace std Putting ...
Edward's user avatar
  • 66.5k
26 votes

C++ logging library

Lots of good code comments already given. I'll focus on non-code aspects. Take this from a DevOps engineer that regularly troubleshoots complex, unfamiliar systems from logs under time pressure. You ...
Emily L.'s user avatar
  • 16.6k
25 votes
Accepted

Simple NAPI wrapper around self written C++ msgpack, horrible performance

Profiling: We could use a library like Tracy to do the sort of profiling you mention in the question. But it's quicker to ask "what's taking the most time" and get an answer with a profiler ...
user673679's user avatar
  • 11.8k
22 votes
Accepted

Modern C++ Singleton Template

Okay so first of the obligatory Singletons are bad practice so you probably shouldn't make it easy to write bad code. Ignoring the fact that the class probably shouldn't exist at all we can look at ...
Emily L.'s user avatar
  • 16.6k
20 votes

C++ logging library

I see a number of things that may help you improve your code. Separate interface from implementation The interface goes into a header file and the implementation (that is, everything that actually ...
Edward's user avatar
  • 66.5k
20 votes
Accepted

BigInt class in C++

We use std::string without including <string> - a possible portability bug. Representation as a string of ...
Toby Speight's user avatar
  • 77.3k
19 votes
Accepted

Customization of memory class C++

Try to be more consistent with naming I'm seeing camelCase, PascalCase and snake_case all mixed together. Pick one style and stick with it. Furthermore, I see redundant things in names like ...
G. Sliepen's user avatar
  • 58.8k
18 votes
Accepted

Min function accepting varying number of arguments in C++17

template <typename Less, typename T, typename... Ts> constexpr const T& min(Less less, const T& a, const T& b, const Ts&... rems) { This ...
Snowhawk's user avatar
  • 6,148
17 votes

A minimal Fraction class in C++

Unrestricted public getters and setters defeat the privacy of numerator and denominator. I recommend dropping getters and ...
vnp's user avatar
  • 56.8k
17 votes

C++ Fast Fourier transform

Prefer C++ headers (such as <cstdio>) to the C compatibility headers (<stdio.h>). The C++ headers define ...
Toby Speight's user avatar
  • 77.3k
16 votes
Accepted

Recursive shared_mutex implementation

Easy Stuff you already know. Probably part of your automated scripts to build new files. #pragma once But for new comers I would point out the more standard ...
Loki Astari's user avatar
  • 95.5k
16 votes

2D counterpart of std::array in C++17

Let me collect a couple of thoughts here. Aggregate initialization currently works like this: array2d<int, 2, 2> a{{1, 2, 3, 4}}; but wouldn't it be ...
lubgr's user avatar
  • 956
15 votes

Modern C++ Singleton Template

Singletons make it hard to test your code, and in my job I'd reject this at review for encouraging the development of untestable features. That said, I'll continue reviewing despite that. No need for ...
Toby Speight's user avatar
  • 77.3k
15 votes
Accepted

Elegantly exclude part of an operation for the last iteration in a loop

If you are just doing a single-shot printing of a container, just print the first element and then print delim-value pairs. This reduces the iterator requirements to being equality comparable, ...
Snowhawk's user avatar
  • 6,148
15 votes
Accepted

Binary Search in C++17

An idiomatic approach to implement this instead of basic arrays and raw pointers is to use iterators. Returning bool is dubious. The situation where I only ...
vnp's user avatar
  • 56.8k
14 votes
Accepted

C++17 saturating integer (arithmetic) type library

Refactor the limits There's quite a lot of repetition of std::numeric_limits<T>::max() and ...
Toby Speight's user avatar
  • 77.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,458
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
  • 66.5k
14 votes
Accepted

Implementing a logging system in C++17

Is my code thread safe? If not, how do I make it thread safe? No, of course it's not thread-safe. You don't do anything to make it thread-safe. A more nuanced answer would be: It's thread-safe as ...
Quuxplusone's user avatar
  • 19.4k
14 votes
Accepted

Implementation of std::any

Your implementation is excellent! I can hardly find any problems. I was amazed how simple a conforming implementation of any can be. And I wholeheartedly agree with ...
L. F.'s user avatar
  • 9,570
14 votes

C++ logging library

Making functions in header files static means that each translation unit gets its own separate definition. This usually isn't what we want. Standard practice is to declare the function in the header, ...
user673679's user avatar
  • 11.8k
14 votes

Japanese reading of an integer

Your magnitudes should be chou and kei (as in the supercomputer, as an aside). Also, ...
Ken Y-N's user avatar
  • 247
14 votes

BigInt class in C++

Using a power-of-10 base for extended precision is unusual, and only a good choice for specific use-cases (like if you mostly want to convert to decimal strings, or if multiplying / dividing by 10 is ...
Peter Cordes's user avatar
  • 3,346
14 votes
Accepted

C++ Fast Fourier transform

Avoid excessive memory usage At each step of the recursion, you allocate two arrays that together are as large as the input. That means that your algorithm uses \$\mathcal{O}(N \log N)\$ space. It ...
G. Sliepen's user avatar
  • 58.8k
13 votes
Accepted

Seamlessly migrating <experimental/optional> to <optional>

A modification of @Jerry's answer: ...
Yakk's user avatar
  • 921
13 votes
Accepted

Doubly linked list class in C++

However, my goal here was to create a low-level data structure that is as time and space-efficient as possible. You don’t realize that unique_ptr is a zero-...
JDługosz's user avatar
  • 11.4k
13 votes

Print-based debugging

Although it's a short function/macro, there are a number of problems here: __FILE__ and __LINE__ are expanded in the function ...
Toby Speight's user avatar
  • 77.3k
12 votes

Create a C++ string using printf-style formatting

I agree with you that 'printf-style' formatting was by many aspects better than C++'s manipulators: more concise, more varied, etc. That said, I feel like it's a step backwards if we port them into C++...
papagaga's user avatar
  • 5,757
12 votes

Min function accepting varying number of arguments in C++17

This looks nice! Two issues I see here, When compiling your template with clang, it refuses the if constexpr dispatch for every ...
lubgr's user avatar
  • 956
12 votes
Accepted

Sudoku solver program written in modern c++

...
Toby Speight's user avatar
  • 77.3k

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