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
1answer
55 views

Single Producer - Multiple Consumers in C++11 using Linux Threads

Hey everyone I was redirected here from Stack Overflow for this question. I am completely new to thread synchronization using condition variables and pthreads in Linux. Here is the code I wrote and I ...
1
vote
0answers
50 views

C++ exception class for error reporting, compatible with C++98 through C++20 (ver 2)

This question contains revised code from the question What should a C++ error reporting exception class have to be portable across language versions?. I summarize what is different from that code at ...
8
votes
2answers
98 views

What should a C++ error reporting exception class have to be portable across language versions? (ver 1)

Link to revised (ver 2) question This question contains the first version of the code for the task explained below. The revised version is at C++ exception class for error reporting, compatible with ...
3
votes
2answers
73 views

Custom Error Handler Library in C++

Is this code clean and optimized? When taking memory snapshots, it seems a bit high. Anything I have done wrong or can do to optimize it? ...
1
vote
3answers
84 views

Hackerrank: Fraudulent Activity Notifications

I'm having trouble on a question from Hackerrank, this solution works for smaller lists but seems to collapse when the list grows to 200,000 where I get the error "Wrong Solution". The ...
3
votes
3answers
64 views

Trying for an efficient and readable merge-sort implementation

My first implementation of merge sort in C++. I'm looking for any sort of optimization and/or conventional practice tips, such as using the appropriate data types and naming my variables appropriately....
5
votes
2answers
766 views

Hashmap implementation in C++

I have been asked to implement a HASHMAP in C++ in a job interview (home assignment). I'm a bit unsure about exception safety, but this is what I came up with: Block.h ...
12
votes
1answer
1k views

Simple NAPI wrapper around self written C++ msgpack, horrible performance

I have written a relatively small msgpack implementation in C++, with performance that is not too bad, so I decided to write a NAPI wrapper around it, but the performance is just horrible. I am ...
0
votes
2answers
70 views

IKM C++ assessment asks about std::unordered_set, part #1 [closed]

Recently I had to do an IKM C++ assessment to qualify for a job. Some of the questions seemed strange to me, so I'll be doing a few posts here to discuss. The first one is related to use of std::...
2
votes
2answers
114 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 ...
6
votes
0answers
67 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
45 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
vote
1answer
44 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
63 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
32 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
32 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: ...
5
votes
0answers
41 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
37 views

convert ID3DXMatrixStack to DirectXMath

Is it right it convert ID3DXMatrixStack to DirectXMath like that: ...
2
votes
1answer
32 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
891 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
104 views

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

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
116 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
38 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
54 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
37 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
34 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
84 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
51 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
30 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
75 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 ...
4
votes
4answers
149 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
55 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
216 views

Implementing range from_to with step

...
0
votes
2answers
167 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
56 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
155 views

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
26 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
182 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
158 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
76 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
54 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
71 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
34 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
77 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
841 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
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 ...