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
4 votes
1 answer
134 views

A Maximum Function For Various Type Arbitrary Nested Iterable Implementation in C++

This is the follow-up question for A Summation Function For Various Type Arbitrary Nested Iterable Implementation in C++. Besides the summation case, I am trying to implement a ...
2 votes
1 answer
39 views

Binary file reader and writer

I want to write a simple binary file reader and writer class. The class below can read or write file. main.cpp read 500 bytes from tmp.bin and copy at the end of ...
1 vote
0 answers
20 views

A simple threadpool in C++17

Implemented a simple thread pool that executes task asyncly, and returns a simple future you can wait on. Can you please suggest improvements? ...
3 votes
1 answer
111 views

Re: C++ 4X Game

This post is regarding the revamp of this post/project I did about 8 months ago. I took a lot of the advice from the suggestions provided (thank you by the way), and fixed the project up, so I'm ...
1 vote
0 answers
23 views

Asynchronous OOP-based networking using the Epic EOS SDK

There is also a limitation from the Epic EOS SDK in the absence of thread safety, all "C" calls can only be made from one thread. And from the thread where the SDK was initialized. Based on ...
3 votes
1 answer
57 views

C++ printing library with templates

I was mad C++ did not have support for printing containers. I also could not find a header only library for printing containers so I decided to make my own. My goals were: 1) practicing templates 2) ...
0 votes
0 answers
38 views

Is this iterative inorder traversal algorithm well-known?

I was concerned about the approach in Morris traversal algorithm and came up with simpler solution that uses parent pointers in nodes. The constraints were following: Time Complexity: O(n) Space ...
4 votes
2 answers
262 views

Wildcard Matching: LeetCode 44

Follow up post Link to question: Given an input string (s) and a pattern (p), implement wildcard pattern matching with support for '?' and '*' where: '?' Matches any single character. '*' Matches ...
3 votes
2 answers
376 views

Find the UTF-8 Length of a given codepoint

A codepoint in UTF-8 can be represented by one to four bytes. Given a codepoint, I need to determine the length (in bytes) of the codepoint if it were represented in UTF-8. For this, I've written the ...
4 votes
2 answers
430 views

Spatial radius search in Boid simulation

I am working on a Boid simulation with 10,000 boids. I've successfully utilized geometry shaders and an array<GLfloat[3], MAX_BOIDS> for vertices to enhance ...
3 votes
1 answer
70 views

Implementing an Object type in C++

I'm currently working through the "Crafting Interpreters" book by Robert Nystrom. He uses Java to implement the visitor pattern in which the visitor functions return the Object type. C++ ...
3 votes
2 answers
89 views

Terminal Based Game [v2]

this is the second version of the Terminal Based Game I'm working on thanks to @user673679 for the suggestions, I did not implemented everything you said but it was really fun working on your ...
7 votes
2 answers
2k views

Gaussian elimination algorithm in C++

Given: j-g-h-i=0 a+b-c-j=0 c+i-d-e=0 e+g-f=0 And known: a=10 b=7 d=3 e=2 f=3 j=14 I want to solve this (or similar equations) ...
2 votes
1 answer
69 views

Casino Number Guessing Game

I have created a casino number guessing game in C++: ...
1 vote
1 answer
66 views

Lazy/deferred OOP-based networking using the Epic EOS SDK

For gaming applications, networking looks strange from the point of view of traditional approaches. Much of the game logic is based on "ticks"; Most often this is a mandatory item of ...
3 votes
1 answer
89 views

C++ implementation of a concurrent queue and of a thread pool

I am working on an implementation of a concurrent_queue<T> and pf a ThreadPool, see beneath. The objectives are CPU ...
2 votes
1 answer
47 views

ReadDirectoryChangesW Improvements

I'm currently using the ReadDirectoryChangesW Function from the Windows API to build a Directory Watcher. The Watcher should monitor a folder for newly added files. ...
2 votes
1 answer
78 views

How to interface a "pull" library with a "push" library using callbacks

I am using a driver that retrieves data from HW (Driver) and a display (Viewer) that will output data to the user. The user calls a trigger function to initiate the getting of data from the Driver. ...
3 votes
1 answer
696 views

Parser Composition - a parser directive for Boost Spirit X3

While exploring Boost Spirit X3 (documentation), I noticed that I couldn't find a parser directive that composed parsers. I dug through the source code to see how the existing directives were made, ...
3 votes
1 answer
101 views

Terminal based game - walking and collecting points

I create a game in the terminal the premise(for now) is walking around a field collecting points marked as $, and avoiding mines marked as !, the player is marked as @ and normal terrain marked as #. ...
5 votes
3 answers
2k views

"Rock Paper Scissors" game

I have created a rock paper scissors game in C++. ...
2 votes
2 answers
2k views

C++ ring buffer using some C++ 17 and coming C++ 20 std::span

When I heard about the new Linux I/O interface io_uring I searched about the ring buffer. I then thought I may replace my safe queue which is base on C++ 11 ...
3 votes
1 answer
85 views

Partial specialization of class template with minimal code duplication

I have a class template that stores an std::optional<T>. A very reduced version of the class template looks like this: ...
4 votes
2 answers
338 views

Class for locking shared disk directory

I'm writing an application to sync files between two directories. In order to prevent simultaneous access to the shared directory from several computers, I implemented blocking of the shared directory....
5 votes
2 answers
97 views

Integer endianness types for protocol structures, take 2

Motivation When working with storage or wire protocols, we often read or write structures containing integers with specific byte-ordering (e.g. big-endian for Internet Protocol, or little-endian for ...
3 votes
1 answer
87 views

BF Interpreter in C++

Need to clear my brain. BF interpretor in C++. bf.h ...
4 votes
2 answers
119 views

C++ heap allocator using an explicit free list

Description I've written a heap allocator in C++ using an explicit free list for organization. I've also written a series of unit tests and a microbenchmark using Catch2. At time of writing I've ...
2 votes
0 answers
28 views

A recursive_fold_right_all Template Function Implementation in C++

This is a follow-up question for A recursive_fold_left_all Template Function Implementation in C++. Besides recursive_fold_left_all function, I am trying to ...
8 votes
1 answer
5k views

Yet another multi-producer single consumer queue in C++17

Here's an implementation of a multi-producer single consumer queue that I wanted to use with tasks such as logging from multiple points in a program to a single sink. The implementation is inspired ...
3 votes
1 answer
63 views

Multi producer/consumer lock-free queue

I would be grateful if you could review my code for a multi producer/consumer lock-free queue in C++. I am mainly after performance improvements, but all input is welcome. ...
1 vote
2 answers
1k views

Calling fgets() twice

I am a beginner. I have really struggled with fgets() when using the function twice. I am on Windows with VS Code and C++ extension. My test program is working, but it is IMHO lengthy and complicated ...
5 votes
1 answer
313 views

C++20 Coroutine Task

This project is the natural extension to my attempt to make a templatedgenerator coroutine. This time, I tried what I called a "...
2 votes
1 answer
90 views

Codeforces: Dasha & Nightmares

so I got started with competitive programming about a day ago and I got stuck on the first random question I tried on codeforces. It's called Dasha and Nightmares. Problem Description: The problem ...
10 votes
3 answers
2k views

Cumulative grade-point-average calculator in C++

I wrote a simple Cumulative grade-point-average calculator in C++, and would like to ask for advices to improve the code in terms of best practices (efficiency, reliability) in the language. Here's my ...
2 votes
1 answer
275 views

Printing the elements of a forward linked list

I'm a sophomore in computer science who's working on a linked list class for his DSA class. I believe this code can be improved, but I'm not sure how because everything got really messy really fast. ...
-2 votes
1 answer
65 views

Double set to -1 from function does not equal to -1 in comparison [closed]

I use the function trace() to calculate the trace of a matrix. This is not important. But for this specific matrix this value is -1. My variable "trace" is set to this from the function. ...
1 vote
1 answer
49 views

Template for making distinct numeric type aliases

I've tried to make a small template for the creation of distinct (incompatible) numerical types. For example both row and column indices are usually represented as the same underlying type. However it ...
2 votes
1 answer
134 views

Alarm - Timer - Stopwatch with <chrono>

Alarm, timer and stopwatch in the style of the standard library. Important design notes: The accessors do not update internal state, the user is responsible to call ...
3 votes
2 answers
159 views

String partial implementation using a vector

I saw few similar solutions, but they all relied on C-style arrays and str utils, so I thought I would write a higher level C++ only implementation with a vector as an exercise. I have not implemented ...
2 votes
1 answer
117 views

OrderBook Implementation - Follow up

This is a follow up to my previous implementation: The input is of the format ...
2 votes
1 answer
49 views

Shared_ptr Implementation with Derived class Awareness

Another shared_ptr implementation. My main idea was to write it in a way you could do: ...
1 vote
0 answers
53 views

Basic base for Phys engine. with SFML and ImGui

I want to create very basic physics engine in SFML. And i also want to be able to control objects using ImGui. So i created this basic foundation. My main problem with it is how i handle rendering gui,...
2 votes
2 answers
165 views

Design decisions for an efficient OrderBook

I am designing code for OrderBook based in C++, based on STL library. Note that there is a related question here, however it is more simple - it does not support deletion of orders, and I intend to ...
1 vote
1 answer
74 views

An Updated recursive_reduce_string Template Function Implementation in C++

This is a follow-up question for A recursive_reduce Template Function with Unwrap Level Implementation in C++ and A recursive_reduce_string Template Function Implementation in C++. Considering the ...
3 votes
2 answers
443 views

Fixed Point Type

I am implementing a fixed point type, which mostly is used to be able store numbers as multiples of some base (power of 2). Apart from that, the type should be able to replace double/float values ...
1 vote
1 answer
241 views

Factory pattern with variadic constructor

I have this code for a factory design pattern that will take into account any number of arguments in the constructor. Through a static boolean in the class a ...
3 votes
1 answer
247 views

Single threaded epoll based coroutine library for C++, Linux

I've implemented a small single-header library over the C++20 coroutines. This library only works on a single thread and it is limited to Linux because it is also based on epoll. The library does not ...
9 votes
3 answers
3k views

Recreating Minesweeper

First, I have to say that this game lacks 5 features that I don't care: Flags Chording Timer Actual mouse movement Good graphics When starting the program, the player is meeted with a "Choose ...
3 votes
1 answer
102 views

IMAP client impementation on State Machine boost-ext/sml

I made IMAP(IMAPS) notifier on boost-ext/sml state machine. There is an opinion that networking is best done on machines. Compile in C++20. Tested on GMail server. Uses karastojko/mailio (and ...
0 votes
1 answer
68 views

Temperature of a Lennard-Jones system

Are the formulas used in getTemperature() and setTemperature() correct? ...

1
2 3 4 5
188