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
votes
0answers
5 views

how to make the array output step by step?

I do so, but something displays already slightly rearranged array I do not understand why or so it should be? is it still possible to implement this idea? The essence of quicksort is to shuffle the ...
1
vote
1answer
49 views

Function to use projections in legacy algorithms

I love the "projections" introduced by the ranges library, and I would like to use them in algorithms that haven't been rangeyfied yet. I had the idea of using them through a function like ...
4
votes
1answer
370 views

Work-In-Progress RPG

Here's an RPG I'm working on that uses only standard C++ libraries. I'm having trouble conceptualizing a coordinate system for characters spawned in a map, and the inventory/item system is only a ...
0
votes
0answers
20 views

merge sort function in linked list [closed]

I am trying to implement merge sort in a linked list in c++. When I execute my code, it runs infinitely no. of time. When I debug it, I found that my mergesort function runs only for the left half ...
3
votes
2answers
55 views

Simple pet caring game - console

I'm a beginner programmer and i'm looking for interesting projects to improve my low skills. I tried one day to improve my skills by trying to create a small game in which a user owns a cat, and has ...
0
votes
1answer
49 views

getint-like function

You probably know the following problem: You have written a small program that runs in your console and want the user to enter something. of course, it is very inconvenient when the user types the ...
2
votes
1answer
52 views

Pairwise summation

This function adds up an array pairwise. It runs fast enough and appears cache-friendly; I've tested it for correct output. It's in C++ (farther down in the file there's a function that takes a vector)...
0
votes
0answers
29 views

Grid Dynamic Programming

atcoder.jp Problem Statement: There is a grid with H horizontal rows and W vertical columns. Let (i,j) denote the square at the ...
2
votes
2answers
108 views

Partial function composability in C++

Similar to Partial Function composability in Haskell, I've attempted to implement partial function composability in C++20 via C++ concepts. More details about the problem(for which my solution is ...
0
votes
2answers
82 views

std::sort custom compare function

I'm trying to solve the problem given here. Arrange given numbers to form the biggest number | Set 1 Given an array of numbers, arrange them in a way that yields the largest value. For example, if ...
3
votes
1answer
77 views

Optimizing a diagonal matrix-vector multiplication (?diamv) kernel

For an (completely optional) assignment for an introductory course to programming with C++, I am trying to implement a diagonal matrix-vector multiplication (?diamv)...
1
vote
1answer
50 views

Binary-Decimal-Hexadecimal converter

I'm a fairly new programmer and have been learning c++ for about 8 months now. I've written a program that can take either binary, hexadecimal, and decimal inputs and convert them to the other two ...
3
votes
0answers
21 views

Arduino Code for Juggling Machine (Stepper Motors)

I have built a machine that juggles. An Arduino sends signals to stepper motor drivers that drive NEMA 23 size stepper motors. Video of the machine: https://youtu.be/-9zD_8erkck Currently, each arm ...
-1
votes
1answer
95 views

Generating permutations fast

I run into a performance bottleneck in a program. I have to generate all permutations for a given sequence with size up to n=11. My code: ...
3
votes
1answer
67 views

Strlen function optimization

So I'm making a strlen function and I thought I would use SIMD instructions for it. It runs fine but when comparing it to std::strlen(), it falls a lot behind. Any ideas on how to make it faster would ...
-1
votes
0answers
20 views

Store Memory Resource from which an object was created to the object itself to be able to call delete as usual? [closed]

When a memory resource (or allocator) is used to create an object, one needs to remember at deletion by which memory resource it was created. Is it a good pattern to store the memory resource to the ...
2
votes
1answer
51 views

C++17 Recursive Fibonacci calculation with memoization

Compiler is g++ 4.2. I'm new to C++, but I've done a lot of data science, web scraping, and some socketing stuff in Python. This code generates the nth Fibonacci number, either with a naive ...
10
votes
3answers
782 views

C++20 Vector2D Template

Pretty simple 2-Dimensional Vector template with operators and two utility functions making use of C++20 concepts. Header-only templates, function inlining and operator overloading, etc. is not ...
0
votes
1answer
33 views

Converting from `std::array<std::variant<>>` to `void*` [closed]

I'm doing some work with Vulkan, in this I need to pass a set of values of various types. Currently I'm using std::array<std::variant<>> in my interface,...
2
votes
1answer
76 views

Dialog that controls external USB device that tests the latency of gaming computers - SysLat Cleanup #4

I have several static variables in my dialog class that I'm declaring in the header and then defining immediately in the cpp file. They are being used in an application with 2 threads, and these ...
2
votes
0answers
29 views

USB implementation of device that tests system latency on gaming computers - SysLat Cleanup #3

Here's my open source project: https://github.com/Skewjo/SysLat_Software. The hardware controlled by this software can be found at https://syslat.com/. This is the 3rd question in a series of ...
1
vote
1answer
45 views

Simple multithreaded FileLogger in C++

I'm new to C++ and am following up on: A simple multithreaded FileLogger in C++ I am curious to know if I implemented his ideas correctly, if there are further improvements to the code and whether it'...
0
votes
0answers
23 views

Common named constants for shared use across project [closed]

I want to keep some common default values in a header file to be shared across a project. I've come up with 2 approaches: Global constexpr expressions wrapped in a ...
4
votes
1answer
84 views
+50

Efficient vector-like polymorphic container which retains type information

This is my attempt of implementing an efficient, cache-friendly, vector for polymorphic objects. From now on I will refer to "virtual functions" as functions which are dependent on an object'...
1
vote
1answer
55 views

Snake game in C++17 with SDL2

I implemented a simple snake clone in C++, using SDL2 for the graphics part. Gameplay-wise, its pretty much classic snake: The player is able to control the snake with "WASD", food gets ...
0
votes
1answer
29 views

Simple read/write lock implementation without starvation

I've built a read/write lock and have been testing it without encountering any problems. It was made to avoid writer starvation, but I believe it works against reader starvation as well. I've seen ...
1
vote
1answer
33 views

Turning a data class with too much functionality into a POD - SysLat Cleanup #2

This is a follow up question to Tuning the data class for the SysLat System Latency Testing hardware for gaming computers - SysLat Cleanup #1. Since the program is too large and complex to put into ...
2
votes
1answer
48 views

Tuning the data class for the SysLat System Latency Testing hardware for gaming computers - SysLat Cleanup #1

Here's my open source project for testing the latency of gaming computers : https://github.com/Skewjo/SysLat_Software This software controls the hardware that tests the latency of a gaming computer ...
4
votes
2answers
338 views

Single Producer Single Consumer lockless ring buffer implementation

I am writing a simple ring buffer for my own education. Below is a crack at a strategy described in http://www.cse.cuhk.edu.hk/~pclee/www/pubs/ancs09poster.pdf : Producer and Consumer keep local ...
6
votes
2answers
83 views

C++ Implementation of a Python-like memoization decorator

Coming from a Python background, one thing I really miss in C++ is a memoization decorator (like functools.lru_cache. As I sometimes compete on Codeforces, I found ...
1
vote
1answer
53 views

my implementation of conway's game of life in C++

I found Conway's game of life. I had heard of it, of course, but didn't think it would be so easy and fun to implement. Anyway, here's my code which I know needs a lot of polish: ...
-1
votes
2answers
84 views

C++17 multi threaded thread “pauser”

I needed a way to pause multiple threads from a single parent thread, this was my solution for the general case. I would like advice on code quality and enhancements. I'm particularly interested if ...
7
votes
3answers
896 views

C++ Creating custom vector

I am new to C++ and Data structures, so I have started writing a custom vector as a practice. Please provide critique and advice. I know it is quite long, so thank you very much in advance. I just ...
2
votes
2answers
94 views

Classic games selection

It is an extremely basic mini-game menu. Link to my game. I know there are more experienced C++ programmers than me, so it would be a great help if you help make my code better. Thank you. PS: First ...
3
votes
1answer
80 views

Tic-tac-toe Game Optimization (C++)

I made a Tic-tac-toe game where you can play against the program or with another player in C++ and I know the code is far too long for what it is. I've tried to optimize it using non-void functions (...
4
votes
1answer
108 views

C++ Hangman with a class

Well, hang-bar but same deal. Any things I could've improved? (I'm starting to get into c++, so chose this as a basic project) Actually, one question I had: I'm using code::blocks, which generates ...
1
vote
0answers
42 views

Reduction on the gpu

This program adds together all elements in an array with the function parallelReduce. Includes testing on an initialization with all 1's and a calculation of the ...
4
votes
1answer
53 views

Binary guess game in C++

This is a program in C++ that guesses a number given by the user. I have to do homework and there's my attempt to solve an exercise from the programming book. If you know what can be done better and ...
3
votes
1answer
71 views

benchmarking sorting algorithms: std::sort vs my naive radix

I'm comparing performance of two sorting algorithms applied to sort integers using google benchmark. I'm quite surprised by the results so wanted to ask if you see some mistakes in the way I measure ...
-2
votes
1answer
47 views

Time Conversion Problem. What am I doing wrong? [closed]

I was trying to solve this time conversion problem on hackerrank but couldn't get the right output on test cases. I have given my best try along with the expected and my output below. Any optimisation ...
9
votes
1answer
1k views

Brainfuck interpreter in C++ with namespaces

I wrote this small Brainfuck interpreter in C++ where the different op codes are handled in one big switch-case statement instead of something like a tokenizer as Brainfuck is very simple in that ...
4
votes
1answer
89 views

Forward List Implementation

NB: There's a bug with my iterator, apparently. I can't use const_iterator because I get some compiler errors. I know using const...
2
votes
1answer
67 views

Ultimate functor class which can read/write to l-values/r-values

The aim is to provide a generic functor class which makes references able to bind to r-values. The trick is to trick the compiler into thinking that the r-value is an l-value by using a forwarding ...
-1
votes
2answers
74 views

Using a lambda to generically create an arbitrary class wrapper around some object of type T [closed]

While experimenting with some of C++'s language features, I was able to successfully design an invokable nameless function call through the use of a lambda that generically creates an arbitrary class ...
3
votes
0answers
62 views

Memcpy function optimzation

Here is my memcpy algorithm I've been working on: ...
2
votes
3answers
94 views

LRU Cache Implementation in C++

I am learning C++ by implementing small design problems. I have tried to implement LRU cache and the implementation that I have attached here works fine. However, I am not sure whether my code is in ...
1
vote
1answer
34 views

Optimize narrow phase contact detection for phyiscs simulation code

I'm trying to optimize the narrow phase of the contact detection in my code. I'm using OpenMP for multithreading. That is the starting code: ...
1
vote
1answer
67 views

Watermarking an image

I have a small bit of code and I wonder if I can make it more readable. I would appreciate it if some people could take a look at it and give me some feedback. I especially wonder if there is a beter ...
1
vote
1answer
129 views

MSD Quick Radix Sort in Place in C++, Object/Pointer Oriented

Memory: O(log2(max)*2)~O(1) Speed: O(log2(max)*n)~O(n) so i did before a MSD Radix Sort in place but i wanted to do one, with out the count, So i join together the quick sort and radix sort. Think as ...
2
votes
1answer
87 views

C++ wrapper for font opaque pointer

I'm creating a class which has a raw pointer member which comes from a C function. In order to make it RAII approved, I just created a method free() that is called ...

1
2 3 4 5
164