Hot answers tagged

74 votes

I created something much faster than a std::string

Unfortunately, your implementation is slower (sometimes substantially slower) than std::string according to your own benchmarks in every test but "create by ...
  • 4,469
51 votes

I created something much faster than a std::string

I’m not going to bother with a full review since the OP is already moving on to v2 of this project. But I think there are some very interesting things that could be helpful to many people still worth ...
  • 9,431
33 votes
Accepted

Implementing any_of in C++

The algorithm looks correct. Regarding the function signature, I'd make three changes: You're not modifying elements, so take it by constant reference rather than reference. You don't need to ...
  • 1,354
26 votes
Accepted

std::list reimplementation

As mentioned, this is a re-implementation of std::vector, not std::list. The default constructor can be set as ...
  • 1,687
26 votes

I created something much faster than a std::string

General Advice Writing a new string class is a very common exercise. You are probably not going to be able to beat the performance of the STL unless you change the contract of the STL—either the API ...
  • 2,503
18 votes

Implementing any_of in C++

I think you did a pretty good job as a beginner. In addition to what Errorsatz said: Consider making element a const reference to prevent unnecessary copying: <...
  • 9,269
17 votes

C++ lock-free, MPMC Ring buffer in C++20

I'm mostly going to play advocate for the devil here. Lock-free doesn't mean fast There is a rather persistent misconception that lock-free algorithms are faster than locking algorithms. However, that ...
  • 38.2k
16 votes
Accepted

C++20 : Simple Softmax classifier for MNIST dataset

In addition to Toby Speight's remarks, I would add: Use constexpr for all constants I see you already used constexpr for ...
  • 38.2k
15 votes

2D Collision Detection in C++

const bool Game::isColliding(... This indicates that the returned type is const, and should not be modified by any part of your ...
14 votes
Accepted

C++ basic bank money class

Store Money as Fixed-Point Monetary quantities are the classic example of something that might have fractional values, but you do not want to represent as a floating-point number, because you need ...
  • 2,503
12 votes

Checking for NaN bit patterns in C++

First of all, the compiler is not hostile; by using -ffast-math you are asking for an optimization that the compiler dutifully performs. Perhaps it is not what you ...
  • 38.2k
12 votes
Accepted

Block-free priority lock

Should You Really Create the High-Priority Mutex Separately? This introduces a new, invalid state (where the high-priority mutex hasn’t been created yet), and prevents you from checking multiple state ...
  • 2,503
12 votes

Palindrome Permutation string

#include <vector> is unnecessary for this program. There are clearly insufficient tests, because there's a bug here: ...
11 votes
Accepted

2D Collision Detection in C++

SFML implements functionalities that allow you to determine if two rectangles intersect. You can significantly shorten your current code: ...
  • 290
11 votes

I created something much faster than a std::string

Correctness The correctness of code is always important when it compares with the speed / performance. There is nothing useful for running fast and generating unexpected results, especially dealing ...
  • 3,646
10 votes

2D Collision Detection in C++

John's answer is correct on programming matters. I want to comment on the logic of your code. I found the collision detection calculation difficult to interpret. Which point on the square is ...
  • 1,795
10 votes

C++20 : Simple Softmax classifier for MNIST dataset

That's a very big list of includes! It might be a sign that you have functionality that should be split out to separate source files (e.g. filesystem read/write away from the core computation). ...
10 votes

std::list reimplementation

The front, back, and swap methods don't check for an empty list. You leak a lot of memory. ...
10 votes

Block-free priority lock

Don't use CAS for bools There is no need to use atomic compare-and-swap when toggling a boolean value. Consider that if you want to set the flag to ...
  • 38.2k
10 votes

I created something much faster than a std::string

The reason lies in the way I handle the heap memory, I don't need to realloc memory every time the value changes, and I don't need to completely reset the object when any modification is made. ...
10 votes
Accepted

Goat racing up a hill (C++ hiring take-home)

M_SQRT2 is not part of the standard library and does not exist on all conforming implementations. The portable C++20 version is ...
  • 9,269
10 votes
Accepted

Portable Object-Oriented WC (Linux Utility word Count) C++ 20, Counts Lines, Words Bytes

Usability Sorting the files in output is surprising, given that commonly-used implementations produce output in the same order that the files were specified. Scripts likely depend on the order ...
9 votes
Accepted

C++20 Vector2D Template

Overview Your code as written is perfectly fine (apart from the one bug in subtraction). Anything mentioned here is mainly to help future readers. You overcomplicated the design by adding constructors ...
  • 92.3k
9 votes

C++ lock-free, MPMC Ring buffer in C++20

template<class T, uint8_t BitsForItemCount> class RingBuffer This is missing ...
9 votes
Accepted

Checking whether a string is a permutation of a palindrome in C++20

While your algorithm is \$O(n)\$, the constant factors are considerable. Specifically, you are suffering due to all the nodes the map needs. Better options are: Just ...
  • 18.2k
9 votes
Accepted

3D Inverse Discrete Cosine Transformation Implementation in C++

Use std::uint8_t instead of BYTE I see you are declaring a type alias BYTE. However, I think ...
  • 38.2k
8 votes

C++20 standard compatible vector

Non-conformance: [Derivation].4: All types specified in the C++ standard library shall be non-final types unless otherwise specified. std::vector is not an ...
  • 18.2k
8 votes
Accepted

Max function with variable number of arguments

I think this function is unnecessary. We can deal with defective classes (that don't properly implement the standard LessThanComparable concept) by either fixing ...
8 votes
Accepted

C++ class to create and evaluate Chebyshev approximations of arbitrary functions

Naming things You have a bounds checking evaluation function, operator(), and one that doesn't do bounds checking named ...
  • 38.2k
8 votes

C++20 : Simple Softmax classifier for MNIST dataset

Toby Speight and G. Sliepen gave excellent feedbacks from the programmer's perspective; A friend of mine gave some feedbacks from the machine learning researcher's perspective, as follows: User ...
  • 1,643

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