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
0answers
24 views

Storing a copy of unique_ptr

When one writes c++ code to manipulate LinkedLists, Trees, etc. one creates a tmp pointer that points to the start/root and changes that pointer as one traverses along. What would be the equivalent ...
2
votes
0answers
22 views

Create 'classical' visitor from lambdas

I've watched a talk by Fedor Pikus on design patterns held at CppCon 2019. Motivated by this, I wrote my own visitor implementation and some helpers which allow me to create a visitor from a couple of ...
0
votes
2answers
33 views

Made a monster array for a text based game with a class constructor C++ [closed]

I created a class in a separate .h and .cpp file with the idea of having an array of 3 monsters with each monster having different stats( name; health; damage). The problem is that the constructor ...
-1
votes
0answers
24 views

Why my code is not working [closed]

I had written a code for testing the winner of Tic-Tac-Toe game, if game has drawn or it is invalid. My code is passing all the testcases that came in my mind but online judge is not accepting it . ...
1
vote
1answer
35 views

(FOLLOW-UP) Header-only bigint library written in c++20

This question is a follow up of Header only bigint library written in c++20. I've made all (or almost all) the corrections suggested in the answers, plus some minor change here and there and a ...
1
vote
1answer
33 views

Console Game “Epic Dungeon”

Made a console game in C++ called "Epic dungeon", which my friend did a year ago in JS. I decided to do it in order to gain experience (in fact, I did it because I would have stopped ...
1
vote
0answers
24 views

Access object initialized within try block afterwards if no exception occured

I have a use case where I try to initialize a Player object within a try block. The relevant excerpt of the current, working ...
0
votes
1answer
26 views

Inquiring possible alternatives to custom hierarchy-aware smart pointer

I have a medium sized project that uses a class hierarchy that essentially boils down to: ...
3
votes
0answers
19 views

Implementation of std::atomic<std::shared_ptr<T>> for C++20

As you may know, C++20 has added std::atomic<std::shared_ptr<T>> specialization to the standard, but sadly, most compilers have not implemented it yet. ...
0
votes
0answers
13 views

convert ID3DXMatrixStack to DirectXMath

Is it right it convert ID3DXMatrixStack to DirectXMath like that: ...
2
votes
1answer
22 views

convert GCCRandom(Mersenne Twister by Takuji Nishimura and Makoto Matsumoto) to stl random

I am trying to translate the book Game Coding Complete by Mike McShaffry 4E to modern C++17 standard and faced with the code of Mersenne Twister by Takuji Nishimura and Makoto Matsumoto. Is it right ...
4
votes
3answers
831 views

De-/Serialization of structs representing TCP messages

I wrote two template functions to serialize and deserialize structs representing messages to be sent and received via a TCP socket: ...
-3
votes
3answers
92 views

Is there any way to use a single for Loop for this code?

I want to use only one for Loop for this code. Is this possible? If not then how can I optimise my code further? It works well for the constraint 1 ≤ T ≤ 10, 2 ≤ N ≤ 10^3, 1 ≤ M ≤ 10^5, but I am ...
3
votes
1answer
109 views

Remove indicies from vector

I am trying to optimise my remove-erase functions by using some attributes of C++ containers. This function should delete all indices defined in std::set form given vector. I am pretty sure that ...
0
votes
0answers
36 views

How can I make my resource mapping faster?

I have a Direct3D 11 application and recently I've started to implement a new feature on it, the UI(User Interface). It seems to work well, but I'm having one problem with optimization when it comes ...
2
votes
1answer
45 views

Is this thread pool implementation OK?

There are things that I am not 100% sure. Is it possible that dangling references can be create in add_task method? Is it possible that this implementation will deadlock? I had to use shared_ptr in ...
2
votes
0answers
32 views

Dynamic heterogeneous container

I want to have dynamic continuous block of memory for different types, that inherit from single base class. I've written structure for that purpose. I know I play with a fire here, but I would like to ...
2
votes
1answer
31 views

Adding iterators to C++ sqlite wrapper class

I recently put up my C++ class to wrap the sqlite3 c library here: Thin C++ wrapper for sqlite3 C library One of the suggestions was rather than to specify a vector for arguments to functions instead ...
3
votes
1answer
73 views

Image (Const) Iterator using C++17

I am trying to learn how to correctly implement an iterator (and its corresponding const variant) using a single template, so I would appreciate any criticism to the following code. It's an forward ...
1
vote
1answer
47 views

Structuring the program that demonstrates collision detection within a field of view

I recently needed to detect agents within a certain-field of view and came across this question in gamedev stack exchange. To learn how it works, I followed the first answer's guidance and decided to ...
0
votes
0answers
27 views

C++20 Ndim matrix, computing eigenvalues and eigenvectors

My C++20 N-dimensional matrix project now supports basic linear algebra operations: https://github.com/frozenca/Ndim-Matrix Today I want to get some reviews on computing eigenvalues and eigenvectors. ...
2
votes
1answer
69 views

Safe runtime numeric casts

The rationale behind this code is to implement a runtime-safe number conversions in situations when precision loss is possible, but is not expected. Example: passing a ...
-1
votes
0answers
13 views

Algorithm for finding a fractional palindrome not working as expected [closed]

Guidelines: I am not allowed to use any external library classes except for "cin" and "cout". I must follow the odd syntactic conventions, such as naming and programmer classes. ...
4
votes
4answers
108 views

Efficiently splitting a string in C++

I've made a splitString() function which receives a character and a string and returns a vector<string> containing all the ...
2
votes
1answer
44 views

Thin C++ wrapper for sqlite3 C library

I originally wrote a rough C++ wrapper of the sqlite3 c library which did not use prepared statements. This code is my attempt at using prepared statements. I have attempted to make the wrapper as ...
2
votes
4answers
1k views

Return correct subclass instance, identified by string

I have made a function which takes a string which can be any of "triangle", "square" or ...
5
votes
3answers
191 views

Implementing range from_to with step

...
-2
votes
0answers
106 views

Extremely inefficient code written in C++ [closed]

I am moving this question from stackoverflow https://stackoverflow.com/questions/67407274/extremely-inefficient-code-written-in-c?noredirect=1#comment119145723_67407274 . The computation time for the ...
0
votes
2answers
80 views

InterviewBit Problem: Stringoholics

I am trying to solve https://www.interviewbit.com/problems/stringoholics/ InterviewBit problem. Problem Statement: You are given an array A consisting of strings made up of the letters ‘a’ and ‘b’ ...
3
votes
0answers
46 views

Num++: A numpy implementation written in C++

I've recently found myself in need of several numpy functions in C++. I've decided to write my own header-only implementation of the ...
2
votes
3answers
122 views
+50

Efficiently read a file into a (C) string using POSIX APIs

Exactly what the title says, this is a C++ class that attempts to read a file into a null-terminated string as efficiently as possible, using POSIX APIs. Obviously this is not intended to be portable ...
1
vote
0answers
24 views

C++20 : Ndim Matrix, broadcasting, np.dot() and np.matmul()

I've improved my N-dimensional C++20 matrix project (C++20 : N-dimensional minimal Matrix class). Implemented general matrix addition/subtraction, elementwise multiplication/division, dot product, ...
6
votes
2answers
163 views

Header only bigint library written in c++20

I made this over the course of a week and a half, to use it for some Project Euler problems. My goal was to make something relatively efficient that could be used as easily as a builtin type. I also ...
4
votes
3answers
144 views

Custom Vector Implementation in C++

I am relearning data structures while trying to implement them on my own while also trying to get better at C++ as although I have knowledge of C, OOP is still non-inituitive to me. In this simple ...
3
votes
1answer
73 views

Asynchronous dispatch queue

Background: This is supposed to be the sole worker thread to carry out long-lasting jobs in a GUI application. The GUI thread should be able to schedule tasks in a non-blocking manner and the tasks ...
0
votes
1answer
53 views

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

The previous question was not clear enough so I will try to clarify it more in this follow-up question. I tried the multiple pointers technique to solve the problem that find pair of values that sums ...
0
votes
2answers
70 views

Is my Insertion Sort optimal?

I'm learning sorting algorithms and wrote my own implementation of Insertion Sort. Is it optimal? Is there anything that can be done better? ...
2
votes
1answer
81 views

C++ Incredibly Precise Sorter | Efficiency and speed of sorting algorithms

Hey Guys, I'm in the process of building a console program in C ++ that allows users to: sort a sequence of numbers loaded from a TXT file save sorted sequence in a new TXT file measure the sorting ...
8
votes
4answers
1k views

Simulation of a falling ball

I made a simple simulation of a falling ball. Is it possible to somehow improve or optimize this code? What tips can you give for development? ...
1
vote
0answers
30 views

brute force algorithm keys with 32bit block and 64bit key using OpenCL

I wrote a brute-force attack on passwords using video cards for any algorithms with a 32-bit block and a 64-bit key, the password is only in BCD format, in the kernel source code the TEA algorithm, ...
4
votes
2answers
76 views

ZX80 game in C++

In order to help with learning C++, I have been re-implementing games from old ZX80 books in C++. Here' the description of one I'm currently working on: You are a starship captain. You have crashed ...
7
votes
2answers
827 views

C++20 : N-dimensional minimal Matrix class

I wrote a N-dim matrix (tensor) class, based on my previous 2D matrix implementation(2D Matrix in C++20 and Strassen's algorithm), accepting many helpful reviews from here. MatrixBase.h ...
1
vote
1answer
50 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
77 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
41 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
132 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
147 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
35 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
101 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
2 3 4 5
168