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

How to efficiently build an object from list or array of strings

I am working with an API that delivers some data in a QStringList or basically a list of strings. The data contains keys and values but it is not a ...
  • 121
0 votes
1 answer
80 views

Count the number of objects created statically and dynamically in C++

I have written below program to count the number of static and dynamically created object of the class. ...
1 vote
1 answer
74 views

game interface setup

I've learned that magic numbers are bad in code. However, should the coordinates, and rotation angles of all the sprites be stored in variables? Is the convention in game development to leave those ...
3 votes
1 answer
310 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
10 votes
1 answer
174 views

C++ imitation of glibc malloc(), free()

I wrote a C++ simulator that performs algorithms for glibc malloc() and free(). The core logic is basically the same, with the ...
  • 1,643
5 votes
2 answers
215 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
1 vote
1 answer
79 views

C++ - Memory allocation utility functions. Is there memory leakage here?

I am quite new at C++ and I really wanna learn how to work with allocating memory. So I have created some utility functions. I am aware that C++ uses new and ...
1 vote
1 answer
71 views

Deque implementation using Arrays in C++

I have written code for the basic implementation of a Deque in C++ using Array(pointer). Please review my code and suggest ways to make it simpler, compact, and efficient. Also would appreciate ...
4 votes
2 answers
59 views

Simple multi-threading setup for tile rendering (C++)

I am writing a small framework that I intend to build upon in the future. I am also using this framework to teach people how to support multi-threading in 3D rendering, and thus wanted to be sure I ...
  • 141
2 votes
1 answer
76 views

Portable noreturn in C/C++ between compilers

I'm writing a C/C++ (intended to also be valid C code) for having a noreturn macro variable as widely portable as possible between C and C++ compilers. ...
  • 163
1 vote
1 answer
36 views

linked list based stack and queue implementations

Created a linked-list based queue and stack. I was required to use my Dlist implementation when coding the queue and stack. ...
  • 141
2 votes
2 answers
81 views

A C++ WinAPI program for changing the process priority classes via PIDs - take 2

After improving the previous post, I came up with the following program: ...
  • 26.1k
4 votes
1 answer
178 views

A C++ WinAPI program for changing the process priority classes via PIDs

(See the next iteration .) I have this program (call it, for example, prioset.exe), that asks for two command line arguments: (1) the target process PID, (2) a ...
  • 26.1k
1 vote
1 answer
56 views

Library to represent graphs

I have been working on a library to represent graphs (directed graphs and undirected graphs). I know that there are already many such libraries but I wanted to create my own as a learning exercise. I ...
3 votes
1 answer
167 views

C++ String utility functions - Code check

I am trying to create a string class without std::string. Just for educational purpose. So I created some utility functions, and it would be very nice if you guys ...
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
5 votes
2 answers
2k views

C++ I wrote a simple and fast formatting library for strings

C++ FString A quick C++ formatting library I was working on a logging library, and needed some way to format strings quickly, simple and clean, so I wrote this library. This library is not the best in ...
5 votes
1 answer
78 views

C++ Graph class (undirected/directed, weighted/unweighted, adj list/adj mat)

I wrote a rudimentary graph class that supports the following eight combinations: Undirected/directed Weighted/unweighted Adj list/Adj matrix implementation ...
  • 1,643
4 votes
2 answers
82 views

I wrote a simple time measurement/compare library in C++ [TimeIt]

C++ Timeit A quick C++ library to measure/compare code execution time Features Easy include and just call timeit() or ...
4 votes
2 answers
101 views

Game loop using Future.wait_for to check for input

I started writing this game from scratch yesterday, and I wasn't completely new to C++'s future library. I only use the ...
  • 143
3 votes
1 answer
237 views

I wrote a simple time measurement library in C++

welcome everybody I wrote a simple code to measure time easily Features Easy include and just call timeit() Fast It just calculates the average time in the loop ...
7 votes
1 answer
200 views

TFunction: std::function replacement for event system

I've been trying to implement delegate for my event system. I thought that maybe std::function can do the trick for me, but it turned out to be not comparable, so what i have end up doing is this - ...
  • 71
1 vote
0 answers
103 views

C++: STL-like AVL Tree (+ benchmark vs. my red-black tree and std::set)

AVL trees and red-black trees are most famous balanced binary search trees. I've always wondered "Why do all major C++ standard library implementations use red-black trees as their ordered ...
  • 1,643
3 votes
1 answer
70 views

Fast way to compute a^d mod n

For a Miller-Rabin primality test I need a fast way to compute a^d mod n. Where a is one of 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, ...
5 votes
1 answer
185 views

Evaluating math terms as nested lambdas instead of expression tree

I need to store some math terms. Originally I would use a tree to do it, especially if parsing strings was involved. However, since the expressions are built within the code and need not be parsed, I ...
1 vote
1 answer
81 views

A C++ Job Manager Class (Rev 1)

This is a revised version of the JobManager class originally posted here. The revisions made were centered around: Encapsulating the ...
2 votes
1 answer
52 views

C++ Connect 4 in SFML

After a substantial amount of programming experience in high level languages like Javascript and Python, I decided to try learning a low level language for once, so I did C++. As my first project I ...
1 vote
2 answers
82 views

A C++ Job Manager Class

I've created a JobManager class that manages the execution of submitted Jobs on periodic intervals. While the ...
2 votes
2 answers
89 views

Coordinate Descent Non-negative Least Squares optimization

In my fast implementation of Non-negative Matrix Factorization (Rcpp Machine Learning Library, RcppML), about 40% of the runtime is spent solving Non-negative Least Squares (NNLS) systems (the rest of ...
  • 143
1 vote
2 answers
75 views

Finding the cheapest path between two points using Dijkstra

I am trying to use Dijkstra to find the cheapest path between two pixels in an image. Implementation: ...
2 votes
1 answer
125 views

non recursive quick sort in c++

I'm relatively new to c++ programming. I have a few years of experience writing simple Arduino programs, but I always kept to the basics. I also have some more experience with Python. I set myself the ...
  • 21
2 votes
2 answers
64 views

Virtual method with variations for different types

Each animal type will call reactToOwner() and exhibit its own behaviour. So simply define a reactToOwner() override for each ...
  • 1,109
1 vote
1 answer
102 views

A uniform interface for storing data by fd or container

I need to store the data in three different ways: storing the data to a std::string writing the data to a given file descriptor both of the above And I hope to ...
  • 29
2 votes
1 answer
95 views

Boolean evaluation

Given a boolean expression consisting of the symbols 0 (false), 1 (true), & (AND), | (OR), and ^ (XOR), and a desired boolean result value result, implement a function to count the number of ways ...
1 vote
1 answer
62 views

Minimum number of swaps to sort a array, but swaps only allowed with elements 2 apart

I wanted to solve a problem where I sort an array of any size and return the minimum number of swaps. The explanation for the distance 2 is that I choose 3 neighboring elements ABC and then swap them ...
1 vote
1 answer
349 views

Convert string to date C++

New to C++ here, by combining different pieces of code I've found, i came with this solution below to convert a date in string to a date object. It works as I want but I'm not certain to do the ...
  • 219
2 votes
2 answers
125 views

Bogo Sort Algorithm

I am a beginner programmer and have written a program that sorts a number of integers of your choosing using bogo sort. Are there any improvements that could be made to make this code more efficient (...
3 votes
2 answers
76 views

Ball movement within an area

I was asked to write a code in C++ using threads, in which I have to have two limits and 4 characters. Characters can go inside the area limited at the same time when they approach from opposite sides....
  • 31
-3 votes
1 answer
45 views

Printing contiguous sub-arrays

The following method of printing all subarrays(contiguous subsequences) of an array is faster as compared to the general method of using three nested for loops: ...
1 vote
2 answers
133 views

Why my implementation of Anagram function is redundant and might have cache issues?

Task I was asked to write a function, which can determine (return a bool) whether 2 given strings are anagrams of each other? That function should have the following constraints: Upper and lowercase ...
  • 263
11 votes
4 answers
2k views

String formatting in C++

To develop my understanding of C++, I've written an overload function that allows users to use & to insert strings within other strings (denoted by a ...
  • 9,652
1 vote
3 answers
217 views

Printing subarrays ⚡

I was trying to to print all subarrays of an array in quadratic time. Here is my code: ...
2 votes
1 answer
71 views

Storing (and retrieving) functions by indexing them by address

I want to implement a "service" of callbacks, where subscribers register or unregister a callback. I was thinking about indexing the callbacks by the function address, so that to unregister ...
  • 133
4 votes
1 answer
113 views

Vectorset, a faster std::set

I decided to implement a vectorset, which is intended to be faster than std::set for the 3 fundamental operations, namely insert,...
  • 41
3 votes
2 answers
99 views

Random dice class based off D&D

I am learning C++ and I took on this small project to get more familiar with OOP. The goal was to create a Die class that randomly rolls and returns a value based on the sides of the die, the number ...
5 votes
2 answers
66 views

Terminal calculator that saves and displays calculation history

I am self-learning C++ and this was my first smallish project. The goal was to create a working calculator that runs in the terminal, saves history of previous calculations, and has the ability to ...
9 votes
3 answers
760 views

Computing a simple moving average on an array in C++

I have just started to learn C++ and wanted to improve my function. I am making a basic statistical API and am calculating an SMA (simple moving average) for some data. This function provides the ...
  • 191
4 votes
1 answer
89 views

Ways to optimize my FFT impementation's performance

I cooked up a FFT code in c++ for calculating with arbitrary data size. The czt function is copied from GNU octave's czt.m. Here'...
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'...