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
1
vote
1answer
67 views

Enemy damaging with regen system

Small project i made to practice my c++, im a beginner and want to know all about optimizing code. Enemy starts off with 10 HP and we can damage them for 1 HP by pressing F1, If their HP is below ...
-1
votes
2answers
79 views

Finding all pairs of elements in an array that sum to a target value using multiple pointers

I was thinking about this problem where you should make a function that takes an array and a target value and then it will find all the pair values that sums up to that target value. Of course there ...
1
vote
1answer
43 views

Getting hard-drive serial number on Windows

The point is to get the serial number of one of the hard drives on Windows. My code is based on an example from MSDN. I tried to make it an exception-safe, self-contained function. It works, to the ...
0
votes
2answers
134 views

Count the number of arithmetic progressions within a sequence

I have some problems with code for my classes. Even though it works correctly, I run out of time for half of the examples. Here's the task (I really did my best trying to translate it): You have a ...
11
votes
3answers
1k views

A practice shared_ptr implementation

I am trying to build a class similar to std::shared_ptr just to learn and improve my way of thinking. I am hoping that you can tell me if this implementation is ...
8
votes
4answers
161 views

Interactive shell for Arduino

Goal I needed to interact with microcontrollers (ESP8266 & ESP32) via the Serial interface, so I wrote a small interactive shell with the command pattern. The defined commands can either accept no ...
1
vote
0answers
40 views

Use OpenSSL and Qt to build the correct X509 certificate chain based on a pool and a leaf

This is my solution to a question I asked on stackoverflow. The scenario is as follows: I got my X509 certificate and a pool of other X509 certificates. Now I want to calculate the chain of trust, ...
0
votes
2answers
108 views

C++ : Merging two convex hulls

I wrote a C++ program that merges two convex hulls in linear time. The algorithm is based on http://cgm.cs.mcgill.ca/~godfried/teaching/cg-projects/97/Plante/CompGeomProject-EPlante/algorithm.html ...
1
vote
3answers
146 views

Value store (“optional” type)

Create a class template named ValueStore that has a member variable, to store a value and a member variable, hasValue that holds ...
9
votes
4answers
2k views

C++20 : Simple Softmax classifier for MNIST dataset

I wrote a simple softmax classifier to classify MNIST digit handwriting data set. Feel free to comment anything! ...
3
votes
1answer
74 views

Poker Hand Evaluation (speed optimization)

Given a two-card poker hand and a board of 5 cards, I want to evaluate the player's hand strength as listed here. The evaluation of a poker hand was measured to be ~100 microseconds on average. ...
2
votes
0answers
83 views

Generic way to access private/protected members

Motivation I and the company is working on building C++ SDK automatically for several platforms, including Windows. In summary, I have to test somehow if the private member of function pointers' type ...
7
votes
1answer
267 views

Lock-free triple buffer

I have a single producer and single consumer, and the producer never stops, but the consumer might not keep up. There's no need to consume every item, as long as we always access the most-recently ...
0
votes
0answers
55 views

Is this a good way to construct the class for a C++ template partial specialisation of a member function?

I am teaching myself c++ by doing a series of exercises. I liked the idea of working out how hash tables could be done using just the language and no std calls. I discovered that you cant do "...
2
votes
1answer
55 views

splitting numbers in three factors

The purpose of this code is to use it to calculate some number theoretic function efficiently for the numbers from 1 to 1000000, but I am not sure if it will be really useful. The main purpose was to ...
6
votes
2answers
1k views

Income tax rate calculator in c++

I have been trying to learn c++ for the sake of being comfortable with a second language. I found a project that seemed relatively easy, although it may not be implemented perfectly, it was a simple ...
1
vote
2answers
64 views

Binary Search Tree without pass by reference

Here is a code for BST that I have written , that does not use pass by reference. Help me to find flaws in its design. Also I do not like the function getReqNodes, ...
0
votes
1answer
130 views

fast reciprocal (1/x)

I was seeing alot of machine learning applications calculate fitness via 1.0 / x. Division in computers is slow so I came up with a version that is about ~36% fast ...
13
votes
1answer
300 views

C++ class to create and evaluate Chebyshev approximations of arbitrary functions

I recently needed to create a function to approximate a complex trigonometric function on an embedded system without a floating point unit and without a fast trigonometric library. So I pulled out my ...
2
votes
1answer
136 views

Mockingbird c++ mocking framework

I have developed Mockingbird a mocking framework for c++, it depends on function injection, here is the code from the repository: ...
8
votes
2answers
166 views

Pokemon battle simulation

Started learning C++ a few weeks ago, tried to accurately simulate a Pokemon battle. Not too optimistic how it turned out, please tell me how I could improve it. Only the bare minimum(damage, accuracy,...
2
votes
0answers
51 views

Rcpp sparse CSC matrix class

This is a sparse matrix (dgCMatrix) class that extends Rcpp. WHAT: This class includes Rcpp::NumericVector and ...
4
votes
3answers
137 views

First C++ calculator

This is my first C++ program. It would be nice if you can tell me anything I could add or do differently. I am new to C++ programming and I hope to learn more. ...
1
vote
1answer
59 views

OpenGL mesh class and derived primitive class

Introduction After finishing most of the tutorials on https://learnopengl.com/ I started to encapsulate code in their respective classes and started to write a mesh class and a polygon class as my ...
4
votes
2answers
117 views

C++ Generic Callback class with removable listeners by unique id

I'm quite new to the STL. Does this make sense? Is there a better way of removing the listeners instead of using shared_ptr while keeping the code short and simple? Is there something in the STL to ...
3
votes
1answer
64 views

Implementation of the basic matrix operations for embedded application in C++

I have been developing a control software in C++ and for implementation of the control algorithms I need basic matrix operations like addition, subtraction, multiplication and multiplication by scalar....
0
votes
1answer
30 views

Deduplicate << operator implementation on inheritance

I have the following working code: person.h ...
0
votes
1answer
58 views

Unix timestamp to days, months, years

Imagine you can't use the standard functions for time calculation or anything alike. You have to start from scratch as it is the case on embedded systems. Thus I came with the following code to ...
0
votes
2answers
200 views

C++ Simple Shared Pointer Implementaion

I wrote an implementation of a shared pointer. I would like a review of it. It seems to work, but running it through Valgrind shows that that it leaks memory somewhere in my tests, but I don't know ...
2
votes
1answer
68 views
3
votes
1answer
182 views

C++ event loop and thread signaling

Use case This is an event loop and signaling system I created for a piece of software which will have multiple asynchronous server/clients/event-emitters/ui, some of those components will have their ...
0
votes
0answers
81 views

Replace while(true); with std::condition_variable

I am trying to replace in an adapted code from internet, a tread pooling class, named ThreadPool: ...
8
votes
3answers
2k views

Checking if a username is valid

I'm learning about how to create a good and clean code. I just need to review something like that, and I really not sure how can I fix this code into a clean code. ...
5
votes
1answer
45 views

huffman archiver in the moder c++ + good architecture

I've written my Huffman archiver in modern c++ (at the moment of writing), could you review it, please? this is the main routine: ...
0
votes
1answer
35 views

extents_to_array and array_to_extents functions for Boost.MultiArray in C++

This is a follow-up question for A get_extents helper function for Boost.MultiArray in C++. In order to retrieve, manipulate and calculate size information in each dimension from Boost.MultiArray in ...
3
votes
1answer
94 views

Snake game built from scratch

I have decided to make snake game as my first project with C++ (using OOP) and I didn't follow any tutorial while doing it, now I am frustrated and need to know if it the code is good or not and what ...
2
votes
2answers
166 views

C++: Event system for game engine

Since writing your own C++ game engine seems to be really popular these days (seriously just look at the amount of people presenting their WIPs on YouTube) I figured I'd try it myself. My mental model ...
1
vote
0answers
101 views

Improving constexpr invoke function C++17, alternative to std::invoke

I've learned that in C++17, std::invoke isn't constexpr. To make a constexpr version, I could copy the implementation provided here: https://en.cppreference.com/w/cpp/utility/functional/invoke , OR I ...
15
votes
4answers
3k views

Chess engine for chess without checks in C++

Project Description: Chess without checks: A chess variant where you can take the enemy king. This engine implementation is for chess without checks. Since checks don't exist, expect the code to not ...
3
votes
2answers
98 views

Small library for SFML to streamline program flow

For the past week or two I have been working on a small library that aims to ease development of SFML games, and after finishing it I would love to get some feedback on it. I don't have access to any ...
2
votes
1answer
84 views

C++ UTF-8 decoder

While writing simple text rendering I found a lack of utf-8 decoders. Most decoders I found required allocating enough space for decoded string. In worse case that would mean that the decoded string ...
0
votes
2answers
78 views

Rock-Paper-Scissors-Lizard-Spock C++ Pogram [closed]

I'm writing the C++ program that involves a twist on Rock, Paper, Scissors. How the added Lizard and Spock affect the game is very simple and you could look it up if you want, but its not needed as I'...
2
votes
2answers
149 views

C++ overloading += operator in custom string class better implementation

I am trying to learn C++, so I started coding a custom string class (using only c-style strings) to get familiar with concepts like operator overloading etc. in the case we have a pointer attribute. I ...
4
votes
1answer
39 views

C++, SDL, and RAII

Learning Modern C++ patterns and this ended up being the direction I went to to create an encapsulation of SDL's window management, while trying to stay with RAII practices. This is meant to be a ...
6
votes
1answer
79 views

Writing a thread-safe ring queue in C++17

I tried implementing a thread-safe ring queue in C++. I'm totally new to move semantics and C++11/14/17 in general. ...
4
votes
1answer
116 views

Contacts programming challenge

I successfully solved a problem on Hackerrank called Contacts, but I'm curious if my code in C++ looks good to C++ developers. If not, how it should be improved. Below is the short description of the ...
2
votes
1answer
139 views

Simple Rock Paper Scissors

I made a Rock Paper Scissors game. It works fine but I would like to know how can I improve it further. ...
25
votes
4answers
4k views

Poor man's JIT using nested lambdas

While answering this code review question, I came up with a way to convert an equation given at runtime to a std::function<double(double)> that would evaluate ...
5
votes
1answer
64 views

Compile-time Matrix Class

Intended as a small project to test out various C++20 features, as well as learn a little bit more about matrices and their uses, I decided to implement a relatively simple matrix class. After ...
5
votes
2answers
281 views

A C++ Program to Plot An Equation

I am fairly new to C++ and I was wondering if there is anything I can improve in this code(perf, readability)? Thanks. This is the full code: Github Link I will post the parser that creates a rpn ...