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
4 votes
3 answers
150 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
3 answers
259 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
71 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
66 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
121 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
106 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
638 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
60 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
29 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
58 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 ...
2 votes
2 answers
392 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
5 votes
3 answers
308 views

Templatizing a Timer class

I'm making a timer class in C++. This is the overview: ...
  • 75
1 vote
3 answers
246 views

Any bettter way to achieve this lookup table?

What I need: I need a lookup table. Once the keywords are all found, then the value of the std::unordered_map is returned.And I don't care about the sequence of the ...
  • 29
2 votes
1 answer
56 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
3 votes
2 answers
677 views

Rendering primitive 2D shapes

I am currently creating my own 3D renderer (think something like OpenGL). As a first step, I created a mini program below to render primitive 2D shapes essential to 3D graphics: points, lines, and ...
1 vote
2 answers
92 views

Basic OpenGL application that renders multiple cubes on a textured plane, setup for a 3D game

I'm learning OpenGL and started work on a small 3D game (like Sokoban) for practice. I want to know if the design of my OpenGL code reflects a good understanding of the technology. For example, one ...
  • 11
0 votes
2 answers
394 views

AES GCM C++ implementation

I have written a C++ program that uses the Crypto++ library to encrypt files using AES-256Bit (in GCM mode). I am planning to eventually have the program store the keys for the files in a file e.g. ...
  • 11
7 votes
7 answers
1k views

A probability distribution function, to be called repeatedly during numerical integration

I am trying to speed up as much a possible this function in C++. As I explained in another post, Implementing multidimensional integral for a custom function in C++, this function will be used inside ...
1 vote
2 answers
111 views

Minesweeper implementation in C++

I have implemented minesweeper in C++. You can get a box by entering the coordinates -row number, then column; starting from 0- of said box (eg: "0 0"); you can mark a box as a bomb by ...
6 votes
2 answers
407 views

std::array based push-only circular buffer

Minimal implementation of a circular buffer based on std::array, where elements can only be pushed and iterated. I'm interested on potential failures and very trivial optimizations, as I'd like to ...
  • 163
1 vote
1 answer
53 views

Binary Search Tree implementation in C++ with templates

Im implementing a BST using templates and dynamic memory, here is my attempt: This is the BSTNode.hh ...
  • 269
1 vote
1 answer
45 views

Asking for C++ advice based on a radix sort function

Can someone point out what possible edge cases/leaks/inefficiencies my code has and how they could be avoided/fixed. Basically, I want to know what mistakes I make so I can avoid making them in the ...
2 votes
2 answers
41 views

Simple non balancing indexed binary search tree

The following code represents a simple indexed binary search tree of integers. The insert method inserts an int. The indexed lookup looks up the ith smallest element (0 indexed). I'm trying to write C+...
  • 21
1 vote
1 answer
71 views

Adapter pattern in C++ via Inheritance and Composition

Any suggestions on how the implementation of the C++ Adapter pattern could be improved here? Implemented via: Composition Inheritance What needed to be adapted was the ...
2 votes
2 answers
173 views

Implementing multidimensional integral for a custom function in C++

I am not an expert with C++, but I am trying to implement a 4-dimensional integral using GSL numerical integration approach. The code below shows the whole algorithm. Although it seems correct what I ...
4 votes
1 answer
187 views

Blackjack game in C++

I developed a blackjack game. I am relatively new to c++ and OOP, so I am asking for feedback on what could be improved. This game features betting, taking a card, standing, and splitting a hand. ...
2 votes
1 answer
73 views

C++17 view over the Ith elements of tuples in containers of tuples

For mainly didactic reasons, I have designed my ElementsView<I, T> class template, which provides a view over the I th ...
  • 123
0 votes
1 answer
45 views

How do I increase the memory efficiency of this longest substring implementation? (C++)

I'm practicing my coding on leetcode. I implemented the following algorithm to solve the longest substring problem: ...
2 votes
1 answer
334 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 ...
4 votes
1 answer
623 views

Create and view a family tree

I have an assignment due Friday to make a family tree. Started to code in January. My reviews from the teacher for this code was that the use of pointers was horrendous and it wasn't OOP enough. This ...
  • 43
0 votes
1 answer
54 views

Excessive space C++ string [closed]

Extra gaps A string is given. Write an application that will remove all extra spaces from this string. A space will be considered superfluous if: it is at the beginning of the line, before the first ...
  • 1
1 vote
1 answer
116 views

"Fast Pimpl": aligned storage instead of the pointer, special member functions

I have attempted to implement a "fast Pimpl" idiom based on the talk slides and further sources, which is essentially an aligned storage of some size that can be used as a drop-in ...
  • 113
2 votes
1 answer
117 views

Map: Group Tuple keys Together with Empty Elements

Introduction We have std::map<key,std::vector<std::string>> m; where the key is represented by ...
  • 191
1 vote
1 answer
48 views

Number of paths in a randomly labeled complete graph

I have a complete graph with n vertices, set W (let's say W = {1,2,3}) and a path ...
  • 13
1 vote
1 answer
62 views

Passwords with C++ Console

I am really, really new to coding in general and especially c++. To get more familiar with c++ I am trying to do a series of projects with c++ console apps. One of my projects is with a database that ...
2 votes
1 answer
175 views

Sum two vectors in x86 assembly

I recently made a program with C++ and ASM. Can anyone help me make this code a more efficient one, in the ASM part or both. I would really appreciate it because I don't know every ASM instruction and ...
2 votes
1 answer
113 views

Chess game setup: Initial board state

This app only creates a chess board set to the start-of-game state. It does nothing else. I'd appreciate feedback on the files that are relevant to this board setup (all shown below: board.cpp, pieces....
1 vote
1 answer
79 views

Linked list implementation in cpp

I need some review for this CPP Linked list implementation. This is my first time implementing such a data structure in CPP. Thanks in advance. ...
4 votes
2 answers
128 views

Multi-threaded Mandelbrot set generator slower than single thread

I am new to parallel programming. I have been playing around with multi-threading and for some reason, multi-threading the Mandelbrot set is slower than running a single thread. I have been trying to ...
2 votes
1 answer
54 views

Event callbacks library

This is a small library I wrote to make event callbacks with variadic templates work like C#'s event system (placeholder template by "dyp" at http://stackoverflow.com/a/21664270). Just like ...
1 vote
2 answers
66 views

Requests and handling requests

For this task, I don't think that the Observer Pattern can be used in its classic form. Those who have received the requests and those who choose to accept the request are not the same group. Those ...
  • 1,109
1 vote
1 answer
67 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
-2 votes
1 answer
74 views

Could someone tell me how good/bad this code is and why, thanks [closed]

I am doing a coding exercise on leetcode, but wondering, is this a good coding? Please help check https://leetcode.com/problems/text-justification/discuss/2017233 Here is the code copy: ...
2 votes
1 answer
48 views

Modify a string by identifying a substring, and replace it and the characters following it with a newly computed substring

I'm working on a string manipulation code in C++ for my internship project, where I have to find a substring within a string and essentially replace it and some characters following it with a newly ...
  • 29
2 votes
1 answer
63 views

Reading a list of names, counting them and ordering them

I would like to know does this code follow common best practices in C++ using STL. Goal of the code: There are 10 players that were playing a game 1000 times. Each time someone has won they have put ...
3 votes
1 answer
87 views

Topological Sort C++

Comments on optimizing the code or improving the code are requested. The input parameters to the class constructor are a one dimensional array of job ID's and the second argument is a list of vectors ...
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
5 votes
1 answer
102 views

С++: Find max element from section in matrix

I'm a newbie in programming. Could you please check my code and give any refactoring ideas, tips, etc... how it can be improved. I wrote a code to perform the following task: Find in randomly filled ...
2 votes
1 answer
78 views

Program to check if a window is opened or not during some time interval

I'm trying to write a program that will check if a window is opened or not, during a given time. I was able to do that, but now I'm trying to make my code look cleaner. I don't like how I implement ...
1 vote
1 answer
52 views

Sort and search vectors by different criteria

Class class Player { std::string name; int score; int id; }; I thought about how to write a code to sort and search vector ...
  • 11