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
2 answers
101 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.6k
4 votes
1 answer
184 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.6k
1 vote
1 answer
59 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
176 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
54 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
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
87 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,683
4 votes
2 answers
93 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
161 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
259 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
239 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
161 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,683
3 votes
1 answer
74 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
192 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
90 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
83 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
83 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
121 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
90 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
297 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
65 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,311
1 vote
1 answer
105 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
111 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 ...
2 votes
1 answer
98 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
2k 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
143 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
85 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
48 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
136 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 ...
  • 269
11 votes
4 answers
3k 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,691
1 vote
1 answer
240 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
85 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
165 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
179 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
234 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
1k 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
97 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'...
4 votes
3 answers
158 views

Introsort implementation

I recently decided to make my own implementation of the Introsort sorting algorithm for educational purposes. Here's what I ended up with (apologies for the lack of comments): ...
  • 196
2 votes
2 answers
365 views

Subarrays with length

You are given an array A of length N (where N is as large as 2×105). All elements of the array are positive integers less than or equal to N. Determine the count of subarrays (contiguous subsequences) ...
2 votes
1 answer
100 views

Heston model implementation in C++

I have implemented an option pricing algorithm following the Heston model. The simulation involves specifying the number of simulations, then generating a discretized path for each simulation (code ...
  • 23
1 vote
3 answers
76 views

Binary Search Tree that allows for duplicate elements - C++

I've recently made an attempt at creating a binary search tree class that allows for duplicate elements. I've included as many functions as I can think of so that I can use it later on. I've tested ...
0 votes
1 answer
151 views

Parallelise numerical integration with OpenMP in C++

I would like to parallelise with OpenMP a one-dimensional integral using the integrate() function implemented in the Boost library. I found a rather obscure ...
2 votes
1 answer
164 views

Electronic circuit logic gates simulator

I've seen a lot of C++ simulators implementing logic gates, but absolutely all of them use the wrapped bitwise operations of the programming language itself. I have tried to omit the use of a bitwise ...
  • 155
4 votes
3 answers
944 views

Infix to Postfix Converter in C++

I have written a program to convert an infix expression to postfix with the help of infix2postfix() function. Please review my code and suggest ways to make it ...
2 votes
1 answer
74 views

Connect4 game multiplayer

I made a connect4 game in c++ please tell my how I can make the code better, thanks. I already asked some people and they told me i should be using fixed witdh ints and [[nodiscard]] on functions that ...
-4 votes
0 answers
30 views

Connect4 game board class [duplicate]

I'm making a connect4 game in c++ and so far i have almost got the board class done before I continue coding i want your thoughts on what I should improve because i definently feel like this could be ...
2 votes
2 answers
59 views

Accept an array, erase some elements and print the array

I'm trying to learn about OOP, specifically encapsulation, and use of static. My goal is to improve my coding skills, I am just looking for feedback specific to encapsulation, the use of static, and ...
3 votes
2 answers
499 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,683
5 votes
3 answers
322 views

Templatizing a Timer class

I'm making a timer class in C++. This is the overview: ...
  • 75

1
4 5
6
7 8
183