Questions tagged [c++]

C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. This tag should be used for any question which requires knowledge or expertise with the C++ programming language. This is a general tag which is used for any of the C++ language standards (C++98, C++11, C++17, etc.). The question should identify the compiler being used, the operating system, and which of the C++ standards is being targeted.

Filter by
Sorted by
Tagged with
3 votes
2 answers
93 views

Income Tax Calculator using 1913 tax standards

I am a beginner in a class and recently given a problem where I have to design a income tax calculator but using the 1913 tax standards. I was able to get it down I think but I was just wondering if ...
Friedhegg's user avatar
4 votes
2 answers
548 views

Constexpr flat_multimap

About the Reasoning I wrote a flat_multimap because it was slightly more efficient to read/write from disk (contiguous memory block) and because it would keep the logarithmic efficiency from a tree (...
FreezePhoenix's user avatar
4 votes
2 answers
816 views

Fast OrderBook Implementation

I'm creating a simple yet fast OrderBook, that only adds orders and matches them (no cancelling or modifications, etc.). I'm using partial template specialization to reduce branching in the hotpath, ...
jpf's user avatar
  • 63
3 votes
1 answer
127 views

Improving execution time of physics, data acquisition triggering system simulation

Background I'm attempting to write a physics simulation code, one portion of which involves simulating the triggering system of some equipment. The equipment works as follows: environmental noise (...
MomentumEigenstate's user avatar
4 votes
2 answers
149 views

Create classes for matrices, including inheritance

I've been learning C++ on and off, and recently learnt about overloading and templates. I wanted to used these concepts to create classes about matrices using ...
eccentricOrange's user avatar
7 votes
3 answers
174 views

C++ String Class Reimplementation

I started learning C++ about a week ago and I was hoping somebody can critique my code. I decided to implement my own basic String class just for the sake of applying all that I've learned about ...
Janriz Libres's user avatar
6 votes
3 answers
228 views

Unit testing a Linked List implementation in C++

Recently I wanted to use the gtest library to unit test my program but for some reason, it's incredibly hard to make it work and configure (at least for me it was), ...
I_throw_but_dont_catch's user avatar
3 votes
1 answer
443 views

C++ enum to string conversion utility

I needed to find a way to convert a bunch of enums to string for displaying in C++. The two main ways I found when searching was using dark magic macros or voodoo magic template metaprogramming. As I ...
adepierre's user avatar
5 votes
1 answer
81 views

leetcode 530. In-order traversal of a binary search tree (C++17)

Given a binary search tree, the problem requires calculating the minimum absolute difference between any two keys in the tree. Given the binary search property, the minimum difference must be between ...
loonatick's user avatar
  • 153
7 votes
1 answer
89 views

Breadth-first search implementation for finding edge of grid c++

I have implemented a breadth-first search algorithm to find the distance from a point to an edge of a grid. The grid consists of spaces that may have walls between them, effectively blocking certain ...
Andreas Tostrup Christensen's user avatar
7 votes
1 answer
1k views

Pet Shelter in C++

The provided code represents an implementation of a Binary Search Tree (BST) in C++, specifically tailored for a "Pet ...
I_throw_but_dont_catch's user avatar
10 votes
2 answers
2k 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
4 votes
2 answers
475 views

Text-based Tic-Tac-Toe

I am just beginning to learn coding and decided to create a text based tic tac toe board as my first solo C++ project. My goals were as follows: be able to test if there is a winning state on any ...
Alice Aaron-force's user avatar
6 votes
1 answer
167 views

C++ Eigen/Mex function to perform two pagewise convolutions on a 3D matrix with a simple kernel

I am trying to accelerate an algorithm where I am computing a 2D variance of many complex matrices stored as pages of a 3D array in Matlab. My implementation uses a Mex function with the C++ Matlab ...
drakon101's user avatar
  • 181
1 vote
1 answer
86 views

sendmsg() scatter-gather coroutine awaiter, optimized suspending

My attempt at an Awaiter for sending scatter-gather data over an open file descriptor. Tested only on gcc-13.1.1 Micro-optimizing by suspending the coroutine only ...
serafean's user avatar
1 vote
1 answer
169 views

Lock Guard Atomic alternative

I've recently written a Vulkan library for creating 2D applications with ease. The catch was I need std::lock_guard for my window resize event to resize resources ...
FatalSleep's user avatar
8 votes
1 answer
173 views

Lightweight general-purpose graph library in C++

As a personal side project I started building a graph library in C++ (I know, very original). The code is open source, but for the purpose of this question I will provide the relevant details and the ...
Bobray's user avatar
  • 81
3 votes
1 answer
122 views

Implementing The Decorator Design Pattern in C++

I recently tried to implement the decorator design pattern in C++. Here is the code in full: ...
Sc2046's user avatar
  • 33
-1 votes
1 answer
112 views

Copying allocated data into std::map in a smart way [closed]

I come across a problem and I solved it. The solution works but I have some feelings that there is something wrong with my solution/code. To be clear, let's assume that cars on the race track transmit ...
unique's user avatar
  • 101
3 votes
2 answers
80 views

Enhancing a non-multithreaded Circular buffer

Looking to get some feedback on a simple non-multithreaded circular buffer. Ideally, I'd want to have a logic to prevent the data from getting overwritten but couldn't find a reasonable way. For ...
xyf's user avatar
  • 508
1 vote
3 answers
115 views

C++ getline implementation for custom stdlib

I'm writing my own "standard library". It relies on nothing but syscalls, so I've had to make my own implementations of everything, including getline (...
Fuzzy Muffin's user avatar
7 votes
2 answers
219 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
4 votes
3 answers
1k views

O(NlogN) sorting algorithms in C++

The following code is my lab which focused on implementing any 3 known sorting algorithms out there. Since the professor gave us a choice to pick any of them and compare their execution time I chose <...
I_throw_but_dont_catch's user avatar
3 votes
2 answers
124 views

Covid Data Base Hash Map in C++

This is a follow up question to Date Checking in C++ I have these two function prototypes: void CovidDB::add_covid_data(std::string const COVID_FILE) ...
I_throw_but_dont_catch's user avatar
5 votes
1 answer
148 views

Is there a more idiomatic way than this to use template-generic C++23 multidimensional array subscripts?

C++23 is going to add multidimensional array subscript operators to the language, yippee! Alas, I have not yet come across a way to adapt them to types where the number of dimensions is templated, so ...
saxbophone's user avatar
2 votes
2 answers
93 views

For two sequences N and M, display counts of elements n from N below each m from M up to the first n above m

A school's task: There are two sequences n_tab and m_tab. For every element m in m_tab ...
Szyszka947's user avatar
1 vote
1 answer
236 views

Factory pattern with variadic constructor

I have this code for a factory design pattern that will take into account any number of arguments in the constructor. Through a static boolean in the class a ...
Thomas Jerry's user avatar
7 votes
2 answers
1k views

Date Checking in C++

I am working on one of my assignments (Hash Tables) for my Data Structures class(1st year), the assignment focuses on OOP and understanding of Hash Tables. Restrictions: Usage of raw pointers C++11 ...
I_throw_but_dont_catch's user avatar
4 votes
1 answer
132 views

Simple Model of Library, Books, Checkout, Patrons and Fees

This is an exercise I solved in the PPP book in C++. If there's a better way I could have done something, please tell me. (No main() and Date (just year)) Thank you! For context here is the exercise: ...
PhaazeReborn's user avatar
-3 votes
1 answer
69 views

Catching any exception and actually do something with it [closed]

Say I have a framework, which should catch any exceptions raised from user code, and actually do something with it, such as converting it to a return value ...
user877329's user avatar
4 votes
1 answer
113 views

Tokeniser which yields a Range of string views

In my answer to string_view tokenizer function template I suggested that a flexible tokeniser would yield a Range that could be iterated over. This is my implementation of such a tokeniser. ...
Toby Speight's user avatar
6 votes
1 answer
273 views

Image stitching using SIFT keypoint descriptor and homography matrix

I have written a code to stitch 2 images using SIFT keypoint descriptor and homography matrix for perspective transform. Are there any areas where code an be improved or optimized? ...
Dushyant Patil's user avatar
5 votes
1 answer
129 views

string_view tokenizer function template

Below is a function template that tokenizes a given std::basic_string_view using a given delimiter and assigns the tokens to a buffer (via a ...
digito_evo's user avatar
2 votes
0 answers
103 views

Point addition on secp256k1. Exploring other alternatives for practical purposes

...
Knm's user avatar
  • 21
1 vote
2 answers
138 views

C++ Unsign 128 Bit Intrinsic Number

Per feed back for this question, I have written an unsigned 128 bit integer for Windows. The class first determines if it is in a 64 bit environment. It only creates the class if it is in a Windows ...
StormCrow's user avatar
  • 369
2 votes
1 answer
2k views

part of a c++ program which mods a game using code injection

https://github.com/speedrun-program/amnesia_load_screen_tool/blob/main/code_injection.cpp https://github.com/speedrun-program/amnesia_load_screen_tool/blob/main/file_helper.h ...
my_stack_exchange_account's user avatar
3 votes
0 answers
97 views

Simple Network Time Server in C++ with improvements from prior code analysis

From code review: OO simple network time server with changes from a previous code inspection and added Windows support I made many changes as per the review comments. The code has been significantly ...
arcomber's user avatar
  • 2,449
14 votes
2 answers
1k views

Arcsine function for a real-time control program

I have been developing control software for a three-phase induction motor. The main task of this C++ code is to control the torque of the motor. In one part of the algorithm (The control algorithm is ...
Steve's user avatar
  • 355
2 votes
1 answer
264 views

Spherical distance (Vincenty distance) between two geographic points [closed]

I am trying to speed up the code of a R function that calculates a Moran's I autocorrelation coefficient from very large distance matrices between geographic points. So I am exploring approaches to ...
Pierre Levoisin's user avatar
1 vote
1 answer
105 views

C++ Dynamic Balancer on a Threadpool

I have a Balancer Class in my project which should dynamically increases/decreases the amount of Worker Thread based on the current amount of Messages which are ...
Kevin's user avatar
  • 145
1 vote
0 answers
63 views

A recursive_reduce Template Function with Unwrap Level Implementation in C++

This is a follow-up question for A recursive_sum Template Function Implementation with Unwrap Level in C++ and A recursive_reduce_all Template Function ...
JimmyHu's user avatar
  • 3,974
2 votes
1 answer
94 views

QuadTree implementation in c++

I'm new on C++ and OOP. I wrote the following QuadTree implementation (I didn't wrote the remove object part yet). please take a look on it and provide feedback, mainly about C++ OOP design, ...
Joseph Hod's user avatar
6 votes
2 answers
226 views

ds - A directory switcher via tags in Windows command line

I have this repository. The idea is that there is a file tags sitting in the users home directory, and which contains the tag declarations of the format ...
coderodde's user avatar
  • 27k
4 votes
0 answers
48 views

Variadic pack class providing operations over types without constructing objects of those types

Sometimes I find I want to call a function passing each of a set of types as a template parameter, but without needing to construct an object of those types. I also may want to do this in multiple ...
John Ilacqua's user avatar
4 votes
1 answer
93 views

Custom binary file format serializer

I am creating a binary file format to store a series of vectors alongside some metadata. The vectors will be stored at the start of the file which will have a predetermined size, and the metadata ...
dearn44's user avatar
  • 165
3 votes
1 answer
63 views

Access integer field in network packet

I see three complexities in accessing (reading/writing) integer field in network packet. Handle endianness. Integer in network packet is big-endian (BE). The host may be either big-endian or little-...
Lingxi's user avatar
  • 818
4 votes
2 answers
1k views

Multi-threading Class in C++

I wrote a C++ class which can take a vector of functions and their respective arguments and execute them in parallel and return a vector of results from its respective functions. ...
Darth-CodeX's user avatar
3 votes
2 answers
250 views

Search function using SIMD

I wrote a search function, similar to std::find, that uses SIMD instructions. Since I am new to SIMD, I would appreciate comments on other SIMD instructions I have ...
builtin.ctz's user avatar
2 votes
1 answer
105 views

Any amount bits integer

This class is meant to work exactly as an unsigned integer should work, but it limits the value based on a set amount of bits. ...
RhinoRunner's user avatar
2 votes
2 answers
244 views

Code for asynchronous data stream processing with multistage pipelines

I am trying to write some code for processing streams of asynchronous data from multiple sources (Producer Nodes), process them ...
Haaput's user avatar
  • 23