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
2 votes
2 answers
48 views

First contact with C++ - Graphics Library

I am trying to learn C++ by writing a basic graphics library; undergrad-toy-project level. I am trying to write modern C++ (C++ 20 standard), but avoiding features that are not well supported by my ...
  • 781
7 votes
1 answer
86 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 ...
5 votes
2 answers
919 views

Find the best couple of an array in 1.5 seconds

I faced this exercise. Given a sequence \$S\$ (\$2 <= |S| <= 10^6\$) of numbers (\$1 <= S_x <= 10^7\$), determine \$max(abs(S_i - S_j) + abs(i -j))\$. Here is the solution I found: ...
3 votes
2 answers
114 views

Goats up hills II: revenge of the goat

This is a continuation of 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 ...
  • 53.5k
5 votes
1 answer
58 views

Character source with lookahead for lexer

I've been out of the C++ game for a few years and I'm trying to knock the rust off by implementing a programming language. This Source interface is used to read ...
  • 3,261
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 ...
  • 53.5k
5 votes
1 answer
85 views

Executing a Bash script from C++

I am trying to execute a Bash command, get the pid, read the (error) output and optionally pass input. I am still quite new at C++ and I would like to know if this is a correct & safe ...
2 votes
1 answer
40 views

Ring buffer for non-trivial types

I tried to explain in detail everything there should be of concern regarding this particular implementation, and non-code body turned out quite long, scroll down if you just want to read the ...
  • 21
2 votes
3 answers
101 views

Find long palindrome multiplications in modern C++

I'm a former C# programmer, updating my rusty C++98 (perhaps I should try Rust instead) to modern C++20. My main goal is to get used to C++ standard library types and algorithms. I chose to solve a ...
2 votes
1 answer
80 views

Reimplementation of Diep.io in C++ with SFML and Box2D

Here's my attempt at reimplementing part of https://diep.io/, a 2D game where tanks battle with each other. The tanks are circular and they have cannons which fire bullets. The bullets can hit other ...
  • 123
5 votes
5 answers
867 views

Palindrome Permutation string

I’m starting to learn C++ by doing a lot of exercises, and I need your help so I can improve, Here is how it goes, I will try to solve an exercise and post both the ...
3 votes
2 answers
506 views

Printing a C++ struct

Critique? ...
  • 1,404
2 votes
3 answers
81 views

A constexpr, const correct matrix class with compile-time checks

I've expanded, and enhanced my matrix class which uses, aside from dynamic memory for the elements, only 3, const literals. These are rows, cols, and a ptr. The methods are all constexpr and the ...
  • 173
2 votes
1 answer
73 views

A parse function for text line with fields separated by a comma with the known number and their type

I am trying to parse a line with a fixed amount of fields and known types. ...
  • 23
4 votes
1 answer
94 views

C++ Binary search using SIMD

Recently I found that the binary search (std::ranges::lower_bound and std::ranges::upper_bound) is the main bottleneck in my ...
  • 1,643
4 votes
3 answers
108 views

C++ B-Tree serialization/deserialization

Yesterday I wrote a serialization/deserialization for my B-Tree library. Since the code for whole tree is too large to upload here, I'll upload only serialization/deserialization and node class ...
  • 1,643
1 vote
0 answers
33 views

C++20 B-Tree v1.0 with disk file supports and perf test

I've improved my in-memory B-Tree (Link) to release a B-Tree with support for memory-mapped disk files and fixed-size allocators: Repository: https://github.com/frozenca/BTree Code: ...
  • 1,643
3 votes
1 answer
309 views

C++ disk-file memory resource

After writing a C++ simulator for malloc() and free(), (C++ imitation of glibc malloc(), free()), I thought: "My simulator ...
  • 1,643
5 votes
2 answers
214 views

A matrix class using const members

I've long used a simple matrix class with a vector and rows/cols for the shape. But I've always disliked getters even when necessary to prevent exposing invariants. Then came c++20 which provided the ...
  • 173
3 votes
1 answer
36 views

Constraining a templated method to accept any integral std::chrono::time_point

Recently I was writing a class that had overloaded read methods for various data types. One of the sets of types I wanted to handle were integral ...
  • 133
1 vote
0 answers
43 views

C++ Static polymorphism at compile-time [closed]

With C++20 constraints and concepts, we are able to retrieve some information about class at compile time. Using such information in template lead to static polymorphism. This toy code works as ...
  • 163
0 votes
0 answers
26 views

UPDATE #2: Lengthening the time it takes to access files using function hooking

https://github.com/speedrun-program/load_extender This is the previous post: UPDATE #1: Lengthening the time it takes to access files using function hooking I came back to this to try to improve it. I'...
2 votes
2 answers
391 views

C++ Hash table, Hash function, benchmark vs std::unordered_set and std::hash

I wrote my own hash function and my own hash table. My hash function seems to work surprisingly well! Feel free to comment anything! Hash function: ...
  • 1,643
2 votes
1 answer
55 views

C++ Doubly linked list, including benchmark vs std::list

I wrote a rudimentary implementation of doubly linked list. Feel free to comment anything! ...
  • 1,643
2 votes
1 answer
319 views

C++20 Multi-queue Thread Pool with Work Stealing

This is a follow up to my previous post which also follows up on my first post regarding my thread pool implementation. I have since made some further changes and attempted to improve performance with ...
1 vote
1 answer
65 views

Using std::variant with std::ranges algorithms

I have some predicate objects that take some value and return the result of some criteria. (My real implementation is more complex, this is only a minimal example): Run on Compiler Explorer ...
  • 125
1 vote
1 answer
108 views

Storing different types with common base using atomic-based typeid

I'm trying to develop some kind of in-memory store for my entities. These entities are representations of the devices available on the system. There may be eg. 3 leds, 1 temp sensor, 2 engines etc. ...
  • 241
2 votes
1 answer
52 views

UPDATE #1: Lengthening the time it takes to access files using function hooking

https://github.com/speedrun-program/load_extender This is the previous post: Lengthening the time it takes to access files using function hooking I tried adding everything from the previous post's ...
2 votes
1 answer
57 views

Lengthening the time it takes to access files using function hooking

https://github.com/speedrun-program/load_extender This is something I made and posted here about a year ago, but I decided to remake it. To compile this on Windows, you need to install EasyHook. ...
0 votes
1 answer
35 views

C++20 Wrapper class for an unsigned integer type and a templated derived class that codes modular arithmetic type

The context is a library to represent numbers (in this case integers) by wheighted position by radix powers for every radix R, passed as template argument. These derived types are digits of radix R, ...
1 vote
1 answer
50 views

Verified downcasting if RTTI is active

In an application that uses heavily polymorphic classes, I have often the need to downcast a pointer or a reference to the correct derived class. They should always be of the correct derived class, ...
  • 188
1 vote
1 answer
115 views

C++ merge sort, logging, unit test, performance check

I wrote a merge sort implementation in C++ today in C++20 way. ...
  • 1,643
21 votes
6 answers
8k 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 ...
1 vote
1 answer
92 views

Yet another command / event dispatcher

I'm trying to implement some kind of command dispatcher. I've already developed some code, but I'm not sure about a few things. My dispatcher is a simple command dispatcher, so for each command, there ...
  • 241
3 votes
1 answer
200 views

Mapping between Enum <-> Enum <-> String view

I've been working on some kind of mapper that would allow me to map between types. My objectives: it should allow mapping between two enums it should allow mapping enum to string_view it should allow ...
  • 241
4 votes
2 answers
308 views

C++20 Single Queue Thread Pool

This is a follow up to my previous post. I've made a number of improvements to the thread pool and corrected some bugs as well. The most up to date version of the code is available on my Github. I ...
4 votes
1 answer
125 views

Searching for a performance bug in a C++20 pathfinding algorithm (NBA*)

(See the next iteration.) I have this pathfinding algorithm: DirectedGraph.hpp ...
  • 26.1k
3 votes
1 answer
49 views

checked conversion function for C++20

Similar to C++ int_cast<> function for checked casts?, but C++20, and with target type deduced from context. The goal is to implement a runtime check that the value being converted can be ...
3 votes
1 answer
91 views

function template for string_view-to-integer conversion

I want to make the following function a function template that supports all the integral types: ...
2 votes
1 answer
50 views

functor chaining function for c++20

How might chain_apply() be improved? ...
  • 1,404
6 votes
3 answers
431 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 ...
0 votes
1 answer
45 views

Class accepting data input by variable, function pointer or lambda

Background I am writing a library that takes some data from the user and works with it. I was experimenting with ways to allow users to provide the data by the following methods: As a (global) ...
  • 103
1 vote
1 answer
113 views

Strong typing -> Named type

I'm trying to generate a strong(er) type wrapper for C++. I've seen the NamedType by Jonathan Boccara, but I want a slightly different behavior. Ideally I would be ...
6 votes
3 answers
673 views

Custom string-to-int converter

I have written the following function: ...
15 votes
2 answers
1k 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 ...
  • 9,171
2 votes
1 answer
116 views

An rough implementation of `std::is_constructible`

As a challenge/fun activity/task, I have implemented my version of std::is_constructible. Here is the source code: ...
5 votes
4 answers
2k views

C++ basic bank money class

I am trying to create a basic money class that fits into a small console banking application I am making. Money.h ...
2 votes
2 answers
110 views

Checking image size in C++

This is a follow-up question for 3D Inverse Discrete Cosine Transformation Implementation in C++. After checking G. Sliepen's answer, I am trying to update the part of width and height checking of <...
  • 3,596
6 votes
4 answers
551 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) ...
  • 12.3k
2 votes
0 answers
68 views

invocable_traits v5

Goal: implement traits that for anything callable return its arity, return type and the argument types. Since pointers to data members are also callable, those should be handled (and be considered 0-...

1
2 3 4 5