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 ...
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 ...
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 ...
21
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 ...
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 ...
20
votes
Accepted
BigInt class in C++
We use std::string without including <string> - a possible portability bug.
Representation as a string of ...
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 ...
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 ...
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 ...
17
votes
C++ Fast Fourier transform
Prefer C++ headers (such as <cstdio>) to the C compatibility headers (<stdio.h>). The C++ headers define ...
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 ...
16
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, ...
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 ...
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 ...
14
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 ...
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 ...
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 ...
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, ...
14
votes
Japanese reading of an integer
Your magnitudes should be chou and kei (as in the supercomputer, as an aside). Also, ...
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 ...
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 ...
13
votes
Accepted
Seamlessly migrating <experimental/optional> to <optional>
A modification of @Jerry's answer:
...
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-...
13
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 ...
13
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 ...
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 ...
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++...
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 ...
12
votes
Accepted
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
c++17 × 561c++ × 546
algorithm × 67
beginner × 58
template-meta-programming × 58
programming-challenge × 47
template × 37
performance × 34
reinventing-the-wheel × 32
multithreading × 22
iterator × 22
strings × 19
object-oriented × 17
variadic × 17
c++11 × 16
memory-management × 16
pointers × 14
c++14 × 12
boost × 12
parsing × 11
linked-list × 11
collections × 11
array × 9
game × 9
sorting × 8