12
votes
C++11 Custom Vector Implementation
This is not a bad attempt at making a vector-like container, except it is lacking support for const and makes unnecessary copies (see below for a more detailed ...
9
votes
C++ template class to calculate CRC
Here are some things that may help you improve your code.
Understand the nature of templates
In modern C++, putting headers in a header file and the implementation in a ...
8
votes
C++11 Custom Vector Implementation
T internal_buffer[BUFFER_SIZE];
This isn't what you want for types that are expensive to construct, or can't be default-constructed.
Your interviewer probably ...
7
votes
C++11 Custom Vector Implementation
This isn't bad, but it's not stellar either.
Names matter.
Stable is a very strange name here. It evokes pointer/iterator stability, a term used to indicate that ...
7
votes
C++11 Custom Vector Implementation
Debug-code
The proper destination for debug-output is std::clog (which goes to STDERR by default, ...
6
votes
Accepted
Custom implementation to provide an immutable range of a vector without copying it
You are implementing std::span
What you are trying to implement is basically C++20's std::span. It might be worthwhile to look ...
6
votes
Accepted
Time duration conversion with units
Avoid defining your own constants
There's no need to use your own constants for the duration of a millisecond, second, minute and so on; just use the right ...
6
votes
Time duration conversion with units
Looks pretty good; these comments are mainly nitpicking:
Error messages should be streamed to std::cerr, not std::cout. Whilst ...
5
votes
C++ template class to calculate CRC
use a function, not a class
A CrcCal class instance has no state (non-static member variables). The class therefore has no reason to exist. We can implement the ...
5
votes
Better rand() API
It's not clear to me why we need to downgrade from std::random_device to a timestamp-based seed on Intel platforms. If we have good reason to distrust a particular ...
4
votes
std::vector<bool> workaround in C++
If you aren’t reinventing the wheel as a learning exercise, and want to code this productively, the simplest options are to use the Boost version of ...
4
votes
C++11 Custom Vector Implementation
if(0u < used_elements)
This is confusing to read and takes more time to understand than
if(used_elements > 0u)
I can ...
4
votes
How to avoid excessive for loops in C++
Documentation
Add documentation.
I had no idea what the goal of this program is, going in, and at the end of the review I still don't, so I can't comment on whether the code is correct or efficient.
...
4
votes
Accepted
Accessing multiple dynamic libraries with the same extern C methods
The code looks correct. It looks like a weird mix of C and C++ though.
Assumptions
There was a statement that they share the same base class, but I am not sure what it means if they all use C style ...
4
votes
Accepted
C++ template and inheritance - Generic Sqrt Decomposition
Design review
Your design is mostly sound. It can be simplified a little bit, and optionally made a bit more rigorous, but the basic design is not bad.
The name for what you’re doing is the “Policy” ...
3
votes
3
votes
Custom implementation to provide an immutable range of a vector without copying it
You are asking how you can guard against invalid iterators; I assume you are most concerned about iterators that have become invalid after the vector had to re-allocate when it outgrew its capacity.
...
3
votes
How to avoid excessive for loops in C++
General points
Why does compareDNA return a double when the inputs are both ints and the output thus can only ever be an int.
...
3
votes
Accepted
C++11(14/17/20) Thread Management
Thread management in C++20
In C++20 (which you mention in the title of the question), there is std::jthread which basically does most of what you are doing in your ...
3
votes
Accepted
AEC-to-WebAssembly compiler in C++
How to create an alias for an enum
I see you are declaring 5 constants, like i32, to avoid having to write out a whole ...
3
votes
std::vector<bool> workaround in C++
Makefile review:
All makefiles should have .DELETE_ON_ERROR: to ensure erroneous output doesn't satisfy dependencies.
The targets ...
3
votes
Better rand() API
Some things to think about: different PRNG algorithms have different trade-offs. The MT19937 algorithm is very fast, but it has a huge internal state (19937 bits to be exact, which is how it got its ...
3
votes
Accepted
Lock-free, thread-safe trie container
Make it more generic
Your Trie class is templated on the type of values stored in the trie, but it's hardcoded what the arity is. Now you can only use it for tries ...
3
votes
Count the number of objects created statically and dynamically in C++
malloc is used but never defined. You probably want std::malloc, from the <cstdlib> ...
2
votes
Implement 3 stacks using a single array in C++
Don't use three separate named variables for the three stack tops. You should be able to have a single indexable piece of code when doing the pushing/popping rather than a ...
2
votes
Still an observer pattern?
As for the Subject class it makes sence to replace std::vector by std::set, which would prevent from adding the same Observer twice or even more times also this makes removing an Observer much easier.
2
votes
Event system using callback functions in C++
I'm going to update to C++20 as we go along, beginning with using modern Standard Library rather than Boost.
We need to include some headers:
...
2
votes
C++11(14/17/20) Thread Management
Pass arguments by reference
You are passing SharedData by a pointer. It would have been much cleaner to pass it by reference:
...
2
votes
Simple terminal TicTacToe
Looking at the headers first, I see that term.h is missing include guards, and colors.h is using a reserved identifier for its ...
2
votes
Accepted
Decorator Pattern with member functions
Without knowing the context, it’s impossible to say whether this design is a good idea. It seems over-engineered, but…. 🤷🏼
I will point out that you could get the same effect much, much easier, by ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
c++11 × 1723c++ × 1708
performance × 141
multithreading × 135
algorithm × 101
template × 100
pointers × 95
beginner × 82
strings × 73
template-meta-programming × 65
programming-challenge × 64
linked-list × 62
reinventing-the-wheel × 62
c++14 × 61
memory-management × 59
object-oriented × 55
vectors × 50
game × 48
tree × 44
design-patterns × 43
queue × 39
boost × 39
graph × 37
iterator × 34
sorting × 32