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
0
votes
2answers
115 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
48 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 ...
3
votes
1answer
65 views

Signature scanner (aka. pattern matcher), is there are more beautiful way to write this?

I'm still new to C++ and I am very open to any kind of suggestion on how write proper and understandable C++ code. I decided to create a class for the code to have everything closely tided together. ...
4
votes
1answer
78 views

Animated progress bar in C++ | How to simplify or alternatives using strings

i'm a beginner in C++ i decided to learn the Scary C++ Programing Language i am a slow learner and after 2 Months learning C++ i saw the need to have a Nice and Tidy progress bar for my programs. ...
1
vote
1answer
31 views

Bill shortage: Basic Coding

I am a beginner in coding. I was doing this question today. A new movie has been released. Many people are buying tickets which costs 25 dollars. There are many people wanting a ticket but each ...
1
vote
1answer
63 views

C++ Code structure & Optimization: LR1Item

I've been working on an LR(1) parser, and I've just finished making the LR(1) item. I'm very rusty with C++, so any pointers (especially optimization and code structure) would be appreciated. Here are ...
1
vote
1answer
40 views

How effective is it to default to user input in C++ function parameters? [closed]

This defaults to user input if the arguments are not passed at compile time.. How effective is this technique and where can it be applied? ...
2
votes
0answers
69 views

Text-Based Pokemon Battling Simulator

How can I improve the visual appeal Of My text-based Pokemon battling simulator? I created a Pokemon battling simulator in C++. I showed it to my mom, dad, and brother, and they didn't say anything ...
-2
votes
1answer
49 views

emplace_back is faster than allocate once + move in c++11? [closed]

I have two fuctions: f2 - first allocate memory , then move data. f - deallocate + move = emplace_back. I am trying to understand what is faster and better to use in terms of performance and code ...
2
votes
3answers
118 views

Logger which writes asynchronously to file from multiple threads

I have written a simple logger, AsyncFile, which asynchronously writes data to a file. Since data is going to be written very often (E.g. 10 writes per 30 milliseconds from different threads, my ...
0
votes
0answers
25 views

Getting rectangle (on screen) around points in world C++

I am curious is the code I have written can be optimized or simplified. The code successfully gets the bounds, as in min and max (think: opposing corners in a rectangular prism) and from there gets ...
2
votes
1answer
136 views

BST implementation using smart pointers in C++

This BST implementation seems to work, I would appreciate an advice on how to improve the code. I am also interested in the following: rule-of-5 methods, are all of them necessary (e.g. is ...
0
votes
1answer
41 views

Implementation of a vector of pairs

In a personal project I was working on, I had a vector of std::vector< std::pair<unsigned,char>>'s that represented a character and its position in the ...
1
vote
0answers
50 views

Own implementation of C++ std::string_view

In order to improve my C++ skills I started doing some toy projects, one of them being my own std::string_view implementation. This was my first time implementing a std library. I'm pasting the code ...
1
vote
0answers
170 views

c++ fixed size multidimensional array

I first thought of the idea when looking at c style multidimensional arrays and realized that there is not really a modern c++ version of that.other than having an std::array of std::array which is ...
3
votes
2answers
99 views

Benchmarking insertion sort

More than once I claimed that using binary search doesn't improve performance of the insertion sort. For example, see answer here and comments here). Now I have time to substantiate my claim. The ...
3
votes
1answer
63 views

Timeout thrower using multithreading

I designed a simple timeout thrower for a bluetooth protocol I am writing. If the packet is not received in a certain amount of time, then timeout is thrown. I made it to be as plug and play as ...
-3
votes
1answer
45 views

What's wrong with this stack implementation? [closed]

My CS teacher sent me the following code for implementing the stack. I've been programming for a few years in higher-level languages, but have rather weak experience with C++. I mean, this code just ...
4
votes
1answer
61 views

C++ - a header only library for CSV

I started to learn C++ after programming for some years in Java, and this is my first (header-only) library. When switching from another language, it is always difficult not to project the old habits ...
8
votes
4answers
2k views

Simple Stack implementation in C++

I've recently started teaching myself basic C++ and decided to implement a simple stack with pointers. ...
1
vote
0answers
39 views

How can I make my LZ77 algorithm to compress faster or to compress more?

So, I am trying to create a PNG compression library, and to do that I need to use the DEFLATE algorithm; DEFLATE consists of two parts, the LZ77 compression, and the Huffman Compression. Currently, my ...
4
votes
1answer
77 views

Is there a better solution to get RTTI info about a polymorphic type?

I made some code to get RTTI information of a polymorphic object, it works both if you pass it directly or a pointer to it(the pointer will get dereferenced until null or the object is found), it's ...
3
votes
0answers
91 views

Linux System Monitor

I made a system monitor on Linux which gives you all this information: The full project can be found in my repo: https://github.com/sandro4912/System-Monitor In short it works as following: I read ...
2
votes
1answer
48 views

Large-scale pairwise similarity calculations of vectors

I am a C++ beginner and am working on a bit of code which calculates the pairwise cosine similarities between vectors. The vectors are TF-IDF vectors and the similarities are used to determine ...
2
votes
0answers
19 views

JDS - Cuda implementation

I am trying to implement the Jagged Diagonal Storage code in Cuda for Sparse Matrix - Vector multiplication. The code I wrote is as follows but I'm not sure about it: ...
2
votes
0answers
17 views

Remap input matrix into matrix with narrower range

When writing image processing/computer vision algorithms, I usually use double in computations and then I have to remap the values back into ...
5
votes
1answer
59 views

C++ simple dictionary match and insert, unique_ptr, operator<

I'm learning C++ and did some reading here and elsewhere on trie structures. I've written a simple class that performs insert and match using a sorted vector as the underlying container. I used ...
1
vote
1answer
72 views

C++ Beginner. Project Euler 14: Longest Collatz sequence under one million [closed]

Hello, I'm a C++ beginner, learning the language while trying to code Project Euler problems. I'm having trouble coding problem 14, which I'll copy here: The following iterative sequence is defined ...
1
vote
3answers
61 views

high card game implementation

I wanted to write a simple implementation for a high card game. Basically two cards are drawn and the higher one wins. Additional rules: support for multiple decks, if same suits drawn then the ...
2
votes
1answer
101 views

Is this C++11 seqlock implementation correct?

My code: https://ideone.com/DZeIZv ...
6
votes
3answers
679 views

Conversion into hexadecimal using C++

I want to read a vector of eight bytes, convert them into hexadecimal, store them in a std::string and finally write them into a binary file. I am looking for ...
3
votes
1answer
40 views

Simple pair/vector2 utility class for c++20

I have rewritten the Vector2 class that I usually use in my projects. The code looks as follows: ...
3
votes
1answer
67 views

Linear Interpolation for sorted arrays

I have made a linear interpolation functions as a side project of mine. It assumes everything is sorted before hand - x and f(x) are the same length. I would like to ask for: general recommendations ...
2
votes
0answers
35 views

Division safe from overflow for fixedpoint

So I was investigating overflow safe division for a class that uses an int64 member with a given RESOLUTION ( 10000 ) for the fractional part. To preserve precision in the fractional part during an ...
2
votes
1answer
53 views

c++ new-handler

I had just put together my first public project: simple(sane) new-handler for c++. It allocates some reserved memory on start up, then releases it piece by piece. It may also raise a signal when each ...
1
vote
1answer
32 views

Socket library base on winsock

I've decided to make a socket library in C++. To be honest i found it a bit tiring using winsock2 - I'd say it's a bit complex, comparing to for instance Python socket lib. My code, header file: <...
6
votes
0answers
180 views

Buddhabrot made in CUDA

In the past I have made programs that have generate a buddhabrot with mostly success however all of them were on the CPU and single threaded. As a result they were all slow so I wanted to remake the ...
2
votes
1answer
38 views

Efficient Implementation of functional and Lazy evaluation in C++

I am creating a c++ library implementing Java Functional Programming alike interface. In short, the code will look like this: ...
1
vote
2answers
56 views

RFC: Lightweight C++ 2D array template with runtime dinemsions

Any comments, critiques or questions about this? I'm using this as the base for a few rectangular board based toy programs like Conway's life and snake. Usage includes configuration of board size at ...
1
vote
2answers
59 views

Leetcode: Cousins in Binary Tree

Mu solution to Leetcode problem Cousins in Binary Tree works, but the code feels bulky. Is there a better way to solve this problem, particularly to use less additional variables? I will appreciate ...
2
votes
0answers
16 views

Using Boost's Runge-Kutta integration capability in a templated mathematical model

This is my first time using Boost and templates in general, so I'm mostly looking for a style critique on my C++. In particular, I'd like feedback on: state_type, ...

1
3 4
5
6 7
155