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
61 views

Merge Sort using vector c++

I'm learning c++ and I know some algorithms and data structures. I was wondering what is the best way to do merge sort for a vector in c++. ...
1
vote
1answer
51 views

Optimization of General Purpose Makefile

I wrote a makefile that would generate a simple executable from the example directory structure. project/ source/ include/ makefile The makefile itself comes ...
1
vote
2answers
94 views

Calculating primes: Could this be any faster?

I've ported a prime-number calculation program from primes.pyx to C++ for benchmark purpose. Since I wrote it in C++, I thought that my program would be faster than the original. However, mine took 25....
2
votes
1answer
59 views

C++17 enum macro with to_string operator

I created a simple enum macro that creates a to_string method for the enum. This has been done before, but my version is designed to compile quickly. From what I ...
2
votes
1answer
73 views

The intersection of two polygons in C++

I implemented the intersection of two (convex) polygons in C++. It finds the polygon in the intersection like in this image. Looking for any and all feedback. I left the logic for line intersection ...
3
votes
1answer
78 views

Return whether the cards can be rearranged

I solved this question on LeetCode.com: Alice has a hand of cards, given as an array of integers. Now she wants to rearrange the cards into groups so that each group is size W, and consists of W ...
1
vote
1answer
52 views

Find-like script for windows

I always read questions about a Windows solution to find a file in a directory structure like find and grep. I created this working c++ program, where you give the program a path and a file name to ...
15
votes
4answers
2k views

Calculator in C++

I made a calculator in C++. I wanted to ask is this code well written, understandable, and alright. ...
2
votes
1answer
98 views

C++20 sort of infinite “Consumer-Producer”

I think I can summarize the idea to the Producer-Consumer problem, with some modifications. And I think i misused the term "Producer" (it depends from which point of view :)) An infinite ...
3
votes
1answer
58 views

JSON Data-structure in C++ and querying it

As a personal challenge I want to implement a C++ JSON Parser. As part of that I have implemented the following Types/Data-structures and a way of querying them. To represent the type of an individual ...
1
vote
1answer
44 views

Library Book Program For Reworking and Optimizing

Just a disclaimer this code was one of the last homework submission for my CSCI intro to C++ class and from my guess very rough around the edges. If any of you are bored during the quarantine and want ...
3
votes
0answers
74 views

Generic named functions arguments in C++17

It stretches a bit the scope of C++, but hey, they gave us the 17 standard, so why not? Some snippet were found all over the internet, but the whole implementation is original. Here is an example main:...
4
votes
1answer
51 views

Small program to convert multiple header files into one

UPDATE: I have changed some of the code from feedback provided on #cpp_review I created a little project that will basically move all header files into one (mostly for libs). The project is small, ...
3
votes
1answer
72 views

Tic-Tac-Toe implementation c++

I created this game just to practice my skills. I've been coding for a few years and I'm decent at data structures and algorithms. I want to know how to improve my implementation. ...
5
votes
1answer
65 views

Multithreaded console-based monster battle with earliest-deadline-first scheduler

In working on this answer it occurred to me that it might be interesting to further expand the idea. The game This is an extremely simple (and boring!) text-based game that creates a few monsters ...
1
vote
1answer
51 views

Improving performance of raycaster application

Bitbucket link to repo Tutorial I have been following I decided to make a raycaster app and try to understand how it really works. So far so good, I have it up and running. If you download the ...
1
vote
0answers
22 views

openMP implementation of loop until predicate met

I want to implement in openMP a loop that terminates when a certain condition holds. In serial code the function body would simply be ...
3
votes
1answer
91 views

C++ algorithm to implement multiple operators in one

I have a class called IntMatrix which has 2 fields: ...
4
votes
1answer
639 views

Barrier implementation in C++

I've implemented a barreir in C++ close to one showed here. In the project code it's used only with two threads and seems to work. A synthetic test didn't expose any flaws too. But I suspect that on ...
1
vote
2answers
58 views

Recursive brute-force approach to maximum points you can obtain from cards

I came across this question on Leetcode. The question description is as follows: There are several cards arranged in a row, and each card has an associated number of points. The points are given in ...
6
votes
2answers
105 views

JSON reader based on a pushdown automata

I haven't used C++ in over a decade, so to learn modern C++ (17) I built a JSON reader based on a pushdown automata (PDA). The general idea is this: A stream is passed to ...
4
votes
1answer
69 views

protein sequence translator using basic text manipulation

As an old COBOL coder, all this OOP stuff is foriegn. Would someone please take a look at this program? I'm looking for suggestions for ways to improve this program. While it works, I'm sure there's ...
3
votes
1answer
64 views

OpenGL Mesh Class

I've written a simple mesh class. The purpose of it is to build a mesh, draw it to the screen, and provide some means by which the mesh can be transformed/scaled, etc. This was done with GLAD, GLFW, ...
6
votes
1answer
127 views

Checking if a value is in a container

I quite often find myself checking whether a given value is present in a given, possibly nested, container. For example, is int val present in the nested container <...
2
votes
1answer
132 views

Count number of previous elements greater than its element at present index

Suppose I have a vector containing n elements. I want to find out the number of previous elements greater than its element at present index i. I want to find ...
4
votes
0answers
66 views

Integrator 2.0: A Simple Integrator in C++17

This is a follow up of A simple definite integrator class of a single variable in C++ I took most of the advice from the user: emma-x and some from user: sudo-rm-rf-slash Here is my fully revised ...
-1
votes
1answer
69 views

Push_back algorithm for Vector

Hello everyone! I wrote a class Vector.So, I want to find out how can i upgrade it for better performance of my vector. Here is the code: ...
2
votes
1answer
43 views

Is this good c++ code for a pin/socket for a node editor?

I'm trying to create a node editor "framework" (IDK what to call it, but essentially there is no GUI and should be implemented using these classes), similar to rete.js, blueprints(maybe an exception ...
9
votes
2answers
144 views

N-Body Optimization

I've created a serial C++ code for gravitational N-Body calculation. Because I expect to have upwards of 8-71 sparse bodies (ie, where Barnes-Hut is not necessarily practical) and running for long ...
2
votes
1answer
68 views

JSON Input validator and Parser

There are probably a lot better ways to do it, but take it as a learning exercise. Basically below is the JSON InputValidation and parsing using nlohmann::json ...
0
votes
1answer
68 views

Translating Dijkstra's Algorithm from Python to C++

I'm going through the book Grokking Algorithms which is in Python but wanted to write everything in C++. Up to this point everything's been pretty straightforward translation but the code for Dijkstra'...
5
votes
1answer
65 views

C++ SFML fonts loader

I am writing a game via SFML. In difference places I want to use loaded fonts. So I decided to write the fonts loader, so that load fonts only one time and use them in the future from class. My code: ...
4
votes
1answer
56 views

Job_Queue (Thread_Pool) Program

I'm new to std::atomic, std::mutex, std::unique_lock, ...
1
vote
1answer
33 views

Implementing boost::upgrade_mutex using only standard locks

Is this my_upgrade_mutex class a valid implementation of boost::upgrade_mutex semantics? (Ignoring the ...
4
votes
2answers
123 views

A simple definite integrator class of a single variable in C++

I have written a simple Integrator class in C++17 that can perform either a definite single integration of a single variable or a definite double integration of a ...
3
votes
0answers
33 views

Implementing a Hilbert-like space-filling-curve conversion in Rcpp

I have written a series of functions that are designed to create a space-filling curve (similar to a Hilbert Curve) that is intended for symmetric matrices (as opposed to a square region). I plan to ...
2
votes
1answer
131 views

Made a sudoku solver with basic GUI in C++

I've made a sudoku solver which solves a sudoku, given user input, and can also extract digits from a picture of a sudoku to solve it. I've used OpenCV and GTK+ 2.0 to achieve the above. I am very ...
0
votes
1answer
64 views

Implementing a binary search tree using std::unique_ptr

I have implemented a binary search tree with 2 operations to begin with. I have tried to implement it using the best practices I could think of. Overall, I am happy with the implementation. But, I ...
1
vote
2answers
109 views

Made an Object pool in C++

I'm making a Minecraft clone and have made an Object Pool. Looking for some advice on how I have implemented it. Uses m_availableObjects as a O(1) way of searching for the next available object. ...
0
votes
2answers
114 views

Union find using unordered map and templates in C++

I tried to implement union find (disjoint set data structure) algorithm in C++. There I used unordered_map data structure. Is there a better way of doing this using any other data structure. While ...
0
votes
1answer
61 views

Wrote My own data structure. Mixture of a doubly linked list & unordered map C++

I decided to make my own data structure. I did this because I wanted a data structure that is a queue but has o(1) time on lookup. ...
3
votes
0answers
64 views

Is this a topological sort? [closed]

I am trying to implement topological sort. The idea is that I have a vector of pairs in which the first element is indegree and the second is a linked list. I tried a bunch of tests, they seem to work,...
3
votes
1answer
70 views

Conway game of life implemented with C++/OpenCV

Here is an implementation of Conway's Game of Life. It is kind of a brute force but it works fine. I have a special question about the method cv::Mat render() const,...
2
votes
0answers
38 views

Doubly linked ring implementation

I was practicing C++ and data structures and wrote my own implementation of a doubly linked ring. I would love to improve my code a little bit more and would need help from the community. Here is the ...
4
votes
1answer
99 views

Resource management classes in C++ game

This is a part of simple sfml C++ game, but I think neither the library nor the language is that much crucial here. I am mainly worried about the design. I have a class template ...
6
votes
2answers
103 views

Simple C++ Test class with rule of 5

It has been a long time I used c++. So I brushing over concepts for interview preparation. Can you please help me with code review? If you have any observations/bugs/alternatives please point out. For ...
2
votes
0answers
33 views

Givens QR decomposition in R or C++: poor performance (or lack thereof) for rectangular matrices

My own Givens-based QR decomposition function in R (pseudocode from Politecnico of Turin's math department) is the following: ...
0
votes
1answer
47 views

C++ Random Tree Node

I've been trying to kind of teach myself "Modern C++" the last couple of months and I just finished this interview type problem and thought it would be a good one to get some feedback on. I not ...
-2
votes
1answer
65 views

How to work in linear time with DFS

I tried a Hackerrank problem and it gives me a successful message, it works fine for Hackerrank criteria. The member states of the UN are planning to send 2 people to the moon. They want them to be ...
1
vote
2answers
45 views

sleepless timer that does not lose time and handles spurious wakes

I have written a timer class. Here it is in all its "glory" with some functions around it to test it: https://rextester.com/LQSXUA43758 Below is the class on its own, note it also relies on ...