Skip to main content
Share Your Experience: Take the 2024 Developer Survey

Questions tagged [c++20]

Code that is written to the 2020 version of the C++ standard. Use in conjunction with the 'c++' tag.

Filter by
Sorted by
Tagged with
23 votes
6 answers
5k views

Implementing any_of in C++

I've decided to implement Python's any in C++. I've gone about this using templates to allow multiple types of data to be passed, instead of overloading the ...
Linny's user avatar
  • 10.1k
22 votes
6 answers
14k views

I created something much faster than a std::string

I've recreated std::string in a way that might be faster. System Features: Much faster than std::string. Easy to use. It was designed as part of a large database ...
Maysara Elshewehy's user avatar
22 votes
3 answers
7k views

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

I have some performance critical inter-thread messaging code in C++. Multiple producers, one or more consumers. Profiling dozens of iterations of this messaging code over several years of development, ...
Ash's user avatar
  • 364
18 votes
3 answers
3k views

trimming a string using C++20 ranges

I have a function which is supposed to trim a string by removing trailing whitespace, then exactly one instance of a fixed string, if it exists, and then any remaining trailing whitespace. It works ...
Edward's user avatar
  • 66.4k
16 votes
3 answers
7k views

2D Collision Detection in C++

I'm attempting to rewrite the classic snake game in c++. What I am inquiring about is my implementation for a 2D collision detection function. I am utilizing ...
Linny's user avatar
  • 10.1k
15 votes
2 answers
2k views

Block-free priority lock

Background I wanted to write an event loop that supports scheduling, but found that no implementation of priority queue that I know of supports waiting on a condition variable (the idea is that the ...
Incomputable's user avatar
  • 9,494
14 votes
1 answer
1k views

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

I recently needed to create a function to approximate a complex trigonometric function on an embedded system without a floating point unit and without a fast trigonometric library. So I pulled out my ...
Edward's user avatar
  • 66.4k
12 votes
5 answers
2k views

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

This question Code lines counter prompted me to write my own line counting program. I program on both Windows and Linux and I know about the Linux utility wc. The command line and output format are ...
pacmaninbw's user avatar
  • 23.9k
12 votes
3 answers
4k views

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

This is an interview take-home challenge that has been translated to avoid compromising the company's question. Problem statement You are a goat that needs to race up a hill. Designated waypoint rocks ...
Reinderien's user avatar
  • 62.1k
12 votes
1 answer
5k views

C++17 <span> implementation

C++20 added the span library under the header <span>. As voluntary exercise (not homework!), I spent approximately 1.5 ...
L. F.'s user avatar
  • 9,560
11 votes
1 answer
2k views

Implementing a `concat` range view using C++ std::ranges

The code below is my first attempt to create a concat "range adapter" using C++20 ranges. It compiles and runs with the latest Clang. The little test ...
Rob N's user avatar
  • 211
11 votes
1 answer
2k views

C++ : B-Tree in C++20 (+Iterator support)

I wrote a B-Tree implementation in C++20, based on my previous Red-Black Tree implementation. Unit Test Demo : https://wandbox.org/permlink/Brw6TgAhdy89OIyj Any feedback will be welcomed! ...
frozenca's user avatar
  • 1,703
10 votes
4 answers
2k views

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

(See the next iteration/follow-up here.) I have this short function is_permutation_palindrome, which returns true only if the ...
coderodde's user avatar
  • 28.5k
10 votes
2 answers
4k views

A* algorithm implementation in modern C++

I've written the A* search algorithm in C++. My goal is primarily writing concise and understandable code, while making use of some new features of modern C++ (where appropriate) and having generally ...
Green绿色's user avatar
10 votes
3 answers
461 views

C++20 standard compatible vector

I decided to write my own vector class template for learning purposes. My main goal was a correct interpretation of C++20 standard (as of n4810). I took some liberties and decided to use concepts ...
user avatar
10 votes
1 answer
2k views

C++20 ScopeGuard

The idea of a defer statement or a ScopeGuard has, for a while, been something I have wanted in C++, but up until recently I had always assumed that C++ did not have it. However, that's when I found <...
nullptr's user avatar
  • 669
10 votes
1 answer
567 views

Two constexpr ceil functions

ceil_constexpr is is based on: https://stackoverflow.com/questions/8377412/ceil-function-how-can-we-implement-it-ourselves/8378022#8378022 ceil_constexpr2 is a simpler version that takes advantage of ...
VevsVire's user avatar
  • 101
9 votes
4 answers
2k views

std::list reimplementation

I've decided to rewrite the standard library list in a smaller version. This is similar to another question of mine, where my main concern is memory management. I allocate a new array each time the ...
Linny's user avatar
  • 10.1k
9 votes
4 answers
2k views

C++20 : Simple Softmax classifier for MNIST dataset

I wrote a simple softmax classifier to classify MNIST digit handwriting data set. Feel free to comment anything! ...
frozenca's user avatar
  • 1,703
9 votes
3 answers
1k views

C++20 Vector2D Template

Pretty simple 2-Dimensional Vector template with operators and two utility functions making use of C++20 concepts. Header-only templates, function inlining and operator overloading, etc. is not ...
Eric's user avatar
  • 389
9 votes
2 answers
766 views

Draw a histogram of the characters in input

It's sometimes fun to implement the exercises from K&R in C++. It's certainly interesting to see what C++ makes easier and what's still difficult. I've had a go at Exercise 1-14 in the second ...
Toby Speight's user avatar
  • 76.2k
9 votes
1 answer
540 views

3D Inverse Discrete Cosine Transformation Implementation in C++

This is a follow-up question for 3D Discrete Cosine Transformation Implementation in C++. In this post, I am trying to follow user17732522's answer to update ...
JimmyHu's user avatar
  • 5,070
8 votes
3 answers
2k views

fmap for containers in c++

I implemented a simple fmap for containers. However containers don't have a unified function to add elements. So I wrote different concepts for different containers. Is there a better way to implement ...
Yu Cong's user avatar
  • 83
8 votes
3 answers
3k views

C++ std::optional implementation

Took a shot at implementing a subset of std::optional functionality. A lot of core features are there but some things like converting constructors, etc are missing ...
jdav22's user avatar
  • 361
8 votes
3 answers
836 views

Find steps to sort unsorted string list

Let's say that we have a list of strings and we want to find the steps (pair representing swaps to be made) to sort it. Here is my current implementation: ...
Clément Jean's user avatar
8 votes
2 answers
445 views

Two dimensional gaussian image generator in C++

This is a follow-up question for Two dimensional bicubic interpolation implementation in C++ and Two dimensional gaussian image generator in C. Based on user673679's answer, another file ...
JimmyHu's user avatar
  • 5,070
8 votes
2 answers
927 views

Floyd's cycle-finding algorithm

I am writing a piece of code for some students and I came up with the following implementation of Floyd's algorithm for finding cycles in linked lists. I was wondering if there are ways I can improve ...
Davide Spataro's user avatar
8 votes
2 answers
315 views

What should a C++ error reporting exception class have to be portable across language versions? (ver 1)

Link to revised (ver 2) question This question contains the first version of the code for the task explained below. The revised version is at C++ exception class for error reporting, compatible with ...
Scott McPeak's user avatar
8 votes
2 answers
441 views

Image Rotation and Transpose Functions Implementation in C++

This is a follow-up question for Gaussian Fisheye Image Generator Implementation in C++ and An Updated Multi-dimensional Image Data Structure with Variadic Template Functions in C++. I am trying to ...
JimmyHu's user avatar
  • 5,070
8 votes
1 answer
520 views

Improving the speed of an MD5 implementation from scratch in C++

I wrote an implementation of the MD5 hashing algorithm from scratch in C++, following the original RFC: https://www.ietf.org/rfc/rfc1321.txt . It works as expected, and the outputs match all the test ...
Prashant Sinha's user avatar
8 votes
1 answer
2k views

Enabling bitset-like behavior for enum classes (C++20)

I want to enable bitmask-like behavior (ie. overloaded operator|, operator& and operator^...
Frederic Schönberger's user avatar
7 votes
5 answers
985 views

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

This post is the follow-up of Checking whether a string is a permutation of a palindrome in C++20. So, what's new? Well, nothing else except that the procedure is now generic and accepts all ...
coderodde's user avatar
  • 28.5k
7 votes
3 answers
1k views

Checking for NaN bit patterns in C++

I live in hostile environments (GCC and Clang) which remove calls to isnan which prevents me to perform validation of my input before running computations. Here is ...
Jean-Michaël Celerier's user avatar
7 votes
2 answers
795 views

Basic scoped timer struct design

I have written the following simple scoped timer struct in order to help me measure the execution time of arbitrary scopes. Here is the code (live): ...
digito_evo's user avatar
7 votes
3 answers
780 views

Optimizing Vector 2D Length Comparisons in C++

I've encountered a readability issue in C++ when comparing the length of a vector to a scalar. Commonly, I see solutions like this: ...
nowox's user avatar
  • 1,099
7 votes
2 answers
2k views

C++ Thread Pool with suspend functionality,

This implementation of thread pool that includes support for suspend functionality, which is necessary for refreshing reference data periodically. I would appreciate your review to ensure that there ...
G. Nass's user avatar
  • 133
7 votes
2 answers
1k views

Generic way to remove all duplicates from a not-sorted container

Here's an interesting article called "How to Remove Elements from a Sequence Container in C++". At some point, the author also explains how to remove duplicates from a container, but only with the ...
papagaga's user avatar
  • 5,757
7 votes
2 answers
2k views

C++20 : N-dimensional minimal Matrix class

I wrote a N-dim matrix (tensor) class, based on my previous 2D matrix implementation(2D Matrix in C++20 and Strassen's algorithm), accepting many helpful reviews from here. MatrixBase.h ...
frozenca's user avatar
  • 1,703
7 votes
2 answers
387 views

Priority Queue (With raise priority operation) using Vector

Here I have implemented a priority queue, with the addition of the raise_priority (also known as reduce key) operation. The reason I have effectively reimplemented std::priority_queue is because the ...
FreezePhoenix's user avatar
7 votes
2 answers
241 views

constexpr Precalculate size of serialized data with templates and C++20 concepts

Im writing a serializer that will do serialization/deserialization as fast as possible, and that uses templates so that i dont have to create a ton of functions for every data structure, This is the ...
OptoCloud's user avatar
7 votes
2 answers
367 views

C++2a comparison-based topological sort algorithm

Here's my attempt at a C++2a Standard Library–friendly "topological sort" algorithm. There are several areas of interest here: The algorithm is comparison-based and in-place, just like ...
Quuxplusone's user avatar
  • 19.4k
7 votes
1 answer
385 views

3D Discrete Cosine Transformation Implementation in C++

This is a follow-up question for Parallel 3D Discrete Cosine Transformation Implementation in Matlab and Operator overloading in Image class implementation in C++. I am trying to implement 3D Discrete ...
JimmyHu's user avatar
  • 5,070
7 votes
1 answer
1k views

Lock-free triple buffer

I have a single producer and single consumer, and the producer never stops, but the consumer might not keep up. There's no need to consume every item, as long as we always access the most-recently ...
Toby Speight's user avatar
  • 76.2k
7 votes
1 answer
428 views

A recursive_transform for std::vector with various return type

This is the follow-up question for A recursive_transform Function For Various Type Nested Iterable With std::variant Implementation in C++ and A get_from_variant function in C++. Thanks to G. Sliepen ...
JimmyHu's user avatar
  • 5,070
6 votes
4 answers
3k views

UTF-8 to UTF-16 (char8_t string to char16_t string)

Below is an implementation of a UTF-8 string to UTF-16 string. Kind of like MultiByteToWideChar on Win32, but it's cross-platform and ...
Aykhan Hagverdili's user avatar
6 votes
4 answers
2k views

Nelder-Mead optimization in C++

I've implemented the Nelder-Mead optimization algorithm in C++. I found this document to be a very good explanation of how the algorithm works, but I'll try my best to explain it (with an example) ...
IEatBagels's user avatar
  • 12.4k
6 votes
3 answers
1k views

Array based queue implementation with C++20

I implemented a queue that holds elements on an array as underlying data type: ...
user avatar
6 votes
3 answers
483 views

locale-aware trim functions for std::string

I have written the below two trim functions for std::string and std::basic_string that are locale-aware. Both trim all white ...
digito_evo's user avatar
6 votes
2 answers
1k views

A not so simple C++20 circular queue

This container reduces the number of memory allocations on queue-type operations (push + pop) compared to std::deque. Basic performance tests indicates a performance similar to std::deque where main ...
Gerard Torrent's user avatar
6 votes
3 answers
686 views

generic implementation of median

Below is a generic implementation of the summary statistics function Median. Discussion of efficient use of std::nth_element and ...
Oliver Schönrock's user avatar

1
2 3 4 5
7