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

minmax evaluation with alpha beta pruning [closed]

I'm making some small board game and wanted to code a very simple greed AI with this algorithm. It turns out it doesn't play the most greedy moves, it is simply not working. I'd appreciate any ...
0
votes
3answers
140 views

sorting vector of pair in efficient way

I'm trying to solve the sorting problem but I always get TLE(Time Limit Exceeded/ 1s) so... can you guys suggest a more efficient way to solve this problem? (i can't link the exercise because it is on ...
13
votes
3answers
2k views

Count word frequencies, and print them most-frequent first

I'm writing a comparison of a simple word-counting program in various languages. The task is to count the frequencies of unique, space-separated words in the input, and output the results most ...
4
votes
2answers
111 views

C++ TcpServer class

I have a class Tcp_Server that implements a TCP server. This is the base class for the other types of servers available in my program. For example ...
1
vote
1answer
67 views
3
votes
1answer
65 views

AI for OpenTTD - A* Path Finder: Follow-up and unique_ptr slow performance

Original review here: AI for OpenTTD - A* Path Finder If you'd like to run the code yourself: https://github.com/marlonsmith10/empire_ai (use_smart_pointers branch) Changes have been made based on the ...
3
votes
1answer
42 views

Windows high resolution timing class

I'm attempting to implement a high resolution class used to time the execution time of functions in Windows. After using this documentation, I have come up with the following: ...
2
votes
2answers
160 views

Simple command line parser

So here's a simple command line parser. Is it safe? I can't use anything but C++14 and standard library. ...
0
votes
2answers
178 views

dynamic queue implementation in C++

I've implemented a dynamic queue with a random-access iterator. iterator: ...
2
votes
0answers
67 views

A C++ iterator that adds an extra layer of indirection

This iterator is designed with one purpose in mind. If before you had an iterator where you could do int x = *it; now you do ...
1
vote
1answer
104 views

C++ Fast Fourier transform attempt 2

This is a follow up for C++ Fast Fourier transform . I did end up changing the algorithm slightly to reduce the memory usage. ...
3
votes
1answer
430 views

Skyscraper Solver for NxN Size

I try to solve a kata on codewars which let you write a skyscraper solver for skyscrapers up to size 11x11. Basic Example what is a skyscraper puzzle (here with 4by4 but the principle stays the same): ...
3
votes
2answers
129 views

Multithreaded logger

I made a multithreaded logger years ago when I was still a total newbie. It "worked" (when it didn't deadlock). Now that I'm slightly less newbie I'd like to get some criticism on this new ...
15
votes
3answers
5k views

C++ Fast Fourier transform

This is a very simple FFT, I am wondering what I can do to make this faster and more memory efficient from the programming side (better data types, and maybe some tricks like unrolling loops or using ...
0
votes
1answer
38 views

2D array zeroing C++ style [closed]

I have a valid code in C-style int arr[10][10] = {0}; // all elements of array are 0 What is the optimal way to do the same for C++ style array? My idea is ...
0
votes
2answers
84 views

Inventory system/management

Just wondering how my code looks, consider it a "professors input" since I'm not taking classes this semester. Also I'd like to note that this will soon be transitioning to a database ...
3
votes
1answer
171 views

How can I make this C++ code to obtain passwords more efficient?

The comments in the code kind of explain it. Backspace characters only move cursor back and don't erase output so I need to overwrite them with ' ' to delete them. <...
5
votes
1answer
370 views

Connect 4 Game Design in C++

I am working on designing a simple version of a Connect 4 game. Here is my first draft code. I would like some feedback on it, and also required modification for these follow up questions: Add some ...
3
votes
2answers
57 views

An expirable LRU cache implementation

I implemented an ExpireLRUCache class, which will clear the data when it times out. There are two ways to achieve this: Use a timer to clear the expire data Call ...
3
votes
1answer
64 views

Assignment function as alternative to std::tie

What do you think about this assignment "idiom"? ...
3
votes
1answer
79 views

Function to use projections in legacy algorithms [closed]

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 ...
6
votes
1answer
427 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 ...
3
votes
2answers
81 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
2answers
82 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
93 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)...
-1
votes
1answer
64 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
144 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
145 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
88 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
69 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 ...
4
votes
1answer
47 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
131 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
102 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 ...
2
votes
1answer
104 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
821 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
57 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
90 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
32 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
54 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'...
4
votes
1answer
123 views

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
99 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
39 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
41 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
50 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
369 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
111 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
58 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
107 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 ...
8
votes
3answers
965 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
106 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 ...

1
3 4
5
6 7
169