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
5 votes
1 answer
402 views

Print abcabc... in three threads

I want to implement the following case Input - integer number n Start 3 threads. The first thread prints 'a', the second prints 'b', the third prints 'c', then the ...
mascai's user avatar
  • 397
3 votes
1 answer
193 views

C++ Readers-Writer Lock using Asio's Strands

The locking mechanism is implemented in the class RW_Lock. The saved_async_completion_handler structure is used in ...
DeltA's user avatar
  • 133
1 vote
1 answer
53 views

Counting number of time frames in a simulation trajectory file

I have written a function in c++, which accepts an "ifstream" object (file) to read from and a string to match a header token in the file. This way I am counting how many times a token ...
Syed Shuja Zaidi P19PH007's user avatar
3 votes
1 answer
990 views

Knock down tall buildings

I'm trying to solve the following problem: As you know Bob likes to destroy the buildings. There are N buildings in a city, ith building has ai floors. Bob can do the following operation. Choose a ...
driver's user avatar
  • 212
-2 votes
1 answer
60 views

C++ compile time polymorphism example [closed]

I found an example using std::variant to provide compile time polymorphism as a possible optimisation to runtime polymorphism in 'Software Architecture Using C++', https://github.com/PacktPublishing/...
arcomber's user avatar
  • 2,449
4 votes
1 answer
109 views

Packet generation and consumption

I have the following simplification of a program which consists of 2 threads. One thread pushes packets to the back of a deque while another waits for user input before performing a "heavy" ...
Bula's user avatar
  • 379
5 votes
1 answer
399 views

Noughts & Crosses (tic-tac-toe) revisited (using C++20 modules)

This is a development of Nought and Crosses (tic-tac-toe) in C++ a learning project in C++. This time using C++20 modules. As before, any suggestions on improvements in style, clarity (or anything ...
scripta's user avatar
  • 501
2 votes
2 answers
76 views

Binary search tree with Iterators

One more BST implementation with iterators added. Did not manage to find another implementation with iterators and it is my first attempt at implementing them so thought to check on your opinion: <...
acd's user avatar
  • 107
2 votes
1 answer
81 views

A recursive_foreach_all Template Function Implementation in C++

This is a follow-up question for A recursive_fold_left_all Template Function Implementation in C++. As mentioned in G. Sliepen's answer, I am trying to implement <...
JimmyHu's user avatar
  • 3,996
1 vote
2 answers
262 views

Multi-Client Socket Communication with Thread Pool in C++

I've been working on implementing a multi-client socket communication system with a thread pool in C++. The system comprises three main components: logger.h, socket.h, and thread.h, which handle ...
user avatar
1 vote
1 answer
91 views

C++ System data transfer design - Following 1

Based on the previous question regarding Data transfer design, here's a major updated code per G. Sliepen's Answer recommendation per std::variant: ...
Hamza Hajeir's user avatar
2 votes
1 answer
55 views

A recursive_fold_left_all Template Function Implementation in C++

This is a follow-up question for A recursive_sum Template Function Implementation with Unwrap Level in C++. I am trying to implement a recursive version fold_left ...
JimmyHu's user avatar
  • 3,996
3 votes
1 answer
249 views

Parallel Accumulate

...
acd's user avatar
  • 107
1 vote
1 answer
131 views

C++ arbitrary base convertor

This is my second C++ program. Again, I wrote it all by myself. I only started learning C++ yesterday. The concept of the program is simple; it should read input from ...
Ξένη Γήινος's user avatar
3 votes
1 answer
140 views

Custom single-header C++ logging library

I started learning C++ recently for game development, and decided to write my own little library for debugging. Here is the library (snoop.hpp) ...
Marc's user avatar
  • 33
2 votes
1 answer
76 views

Yet another std::unique_ptr implementation

I know I haven't implemented many methods, and haven't specialized it for T[], but I just want to see if what I coded is good or bad. ...
jamesee's user avatar
  • 21
8 votes
3 answers
2k views

Sieve of Eratosthenes in C++ with wheel factorization

I have written a completely working C++ program for the first time, and I have managed to compile it. I have decided to learn C++ and I have written a C++ program to familiarize myself with C++, this ...
Ξένη Γήινος's user avatar
4 votes
1 answer
142 views

C++ System data transfer design

I'm designing a data transferring that supports an IoT framework I'm developing, which targets embedded systems. A unified communication core is built, wherein each entity of the code can hook its ...
Hamza Hajeir's user avatar
4 votes
3 answers
1k views

C++ Binary Search

Could you advise on this binary search implementation? ...
acd's user avatar
  • 107
2 votes
1 answer
82 views

Object pooling class BubbleList

Please review C++ class BubbleList design with performance in mind. Named BubbleList as pooled (unused) objects bubble to the ...
Blindman67's user avatar
  • 21.6k
4 votes
1 answer
120 views

A slightly unconventional CMake project

Introduction This is my first CMake project. I had a bit of help with the initial setup but I have since made a lot of changes myself. It's working well but I think I am doing things in a slightly ...
Dan's user avatar
  • 341
1 vote
1 answer
188 views

Mouse and keyboard event system

I wrote a mouse and keyboard event system in C++, using the GLFW library to get mouse and keyboard states. I've been working on a 3D game engine of my own for a long time (about 9 months) and wanted ...
Tristen Woodruff's user avatar
2 votes
0 answers
52 views

A recursive_depth Function Implementation with Target Type Parameter in C++

This is a follow-up question for A recursive_depth function for calculating depth of nested types implementation in C++. I am rethinking about the proposed ...
JimmyHu's user avatar
  • 3,996
5 votes
2 answers
179 views

C++ UniquePtr Implementation

Took a shot at implementing std::unique_ptr. Code: ...
jdav22's user avatar
  • 319
6 votes
2 answers
1k views

Avoiding memory leaks and using pointers the right way in my binary search tree implementation - C++

I'm learning C++ and I wanted to test my knowledge by implementing a Binary Search Tree using struct (I know, I’m using C++ I should use classes but I want to keep ...
Neptune Luke's user avatar
1 vote
0 answers
90 views

A CUDA kernel for a matrix product as outer product vectors

To multiply the matrices A and B using the outer product of vectors, we can express each row of matrix A as a row vector and each column of matrix B as a column vector. Then, we can take the outer ...
user366312's user avatar
8 votes
2 answers
260 views

C++ std::vector Implementation

Implementation of the vector class in C++ for learning purposes. Tried to implement interesting parts from the API shown on cppreference.com, but some elements like ...
jdav22's user avatar
  • 319
7 votes
2 answers
167 views

shared_ptr implementation code - first cut

I've written an implementation of shared_ptr. It doesn't support weak_ptr (yet) but below is the code. I'd appreciate any feedback, comments. ...
Greg's user avatar
  • 71
1 vote
1 answer
143 views

Vulkan application to draw a triangle

I've been following the ever popular 'vulkan-tutorial.com' guide on Vulkan and the result is this program which draws a multicolored triangle. I'm interested in finding out how to make my code more ...
Red's user avatar
  • 171
1 vote
1 answer
119 views

HTTP routing with Mongoose

I'm trying to extend the Mongoose RESTful server example with URL routing. This code relies on the Mongoose library available here. This is heavily inspired by the routes class from this question but ...
S Meredith's user avatar
2 votes
1 answer
100 views

C++: algorithm that uses fixed-size buffer of data that are produced in stream, faster than the algorithm speed; modified version

This is a, I hope, an improved version of this code, limiting atomic usage (following @GSliepen, @G.Sliepen advice) (NB I'm limited to, at most C++17): ...
Oersted's user avatar
  • 299
7 votes
1 answer
1k views

C++: algorithm that uses fixed-size buffer of data that are produced in stream, faster than the algorithm speed

I try to implement this scenario with a producer/consumer multithread pattern and I'd like to optimize synchronization and memory model directive used. This code originates from a SO question and its ...
Oersted's user avatar
  • 299
-2 votes
2 answers
120 views

Lower-Bound algorithm getting Time Limit Exceeded

...
Shakhawat Hossain SHIHAB's user avatar
5 votes
3 answers
2k views

An exercise in Data Oriented Design & Multi Threading in C++

Been working in games development professionally now for about ~5 years, but have only been doing OOP & haven't worked with multi threading before as I'm mostly a gameplay programmer, I've also ...
larssonmartin's user avatar
1 vote
1 answer
85 views

A Model View Controller Pattern implementation. Do I get it right?

I know there has been many questions on the Model-View-Controller pattern, but this question is a follow up on a previous question I asked regarding the implementation of a download manager: Get files ...
M. Saintourens's user avatar
1 vote
4 answers
254 views

Suggestions on performance

I have following piece of code that is called by a program many thousands of times as part of Monte-Carlo simulation. using gprof, I see that 38% of the time was spent on this function. Are there any ...
Yoshiro's user avatar
  • 29
4 votes
2 answers
307 views

fast convert string_view to floating point

The code makes following assumptions: std::string_view is not null-terminated there are no exponents, all floating point inputs are in the way 123.123 limiting ...
Nick's user avatar
  • 1,480
2 votes
1 answer
62 views

API Implementation guidance and improvement

I have recently made significant progress in overcoming beginner barriers related to using Git, CMake, libraries, and successfully implementing an API in C++. Despite my achievements, I acknowledge ...
user avatar
0 votes
1 answer
125 views

C++ slim condition notifier

When writing multi-threading code, one often need the thread to wait for some condition being met. A naive approach would look like this: ...
zwhconst's user avatar
  • 137
5 votes
2 answers
127 views

Get files downloaded asynchronously after double clicking on list item (C++)

The problem I am trying to solve as an exercise is as follows: I have a UI running in the main thread, specifically a list view with many items. Each item represents a file that the user can download....
M. Saintourens's user avatar
1 vote
2 answers
83 views

An arithmeticable Concept Implementation in C++

This is a follow-up question for A recursive_reduce_all Template Function Implementation in C++. As G. Sliepen's answer mentioned: ...
JimmyHu's user avatar
  • 3,996
2 votes
1 answer
72 views

Outcome error handler, inspired by boost's outcome namespace

I'm creating a little library for my pet project that is inspired by Boost's outcome namespace. The main reason why I didn't want to use the Boost version is that I don't like the overhead of ...
Goubermouche's user avatar
2 votes
1 answer
84 views

Better JVM Bytecode Struct with Serialiser & Parser Without #MACROS

Preamble I was inspired by this review request to create my own quasi JVM Byte Code Struct, Parser and to top it a bit I also wrote two a quasi executors. Currently, they just print the instructions ...
Ajinkya Kamat's user avatar
2 votes
1 answer
117 views

Command-line parser with built-in error checking

Simple command-line option parser with automatic setting of variables and built-in error checking. The story is I was working on another new project that had a lot of configurable options, as they ...
Mode77's user avatar
  • 641
6 votes
3 answers
743 views

C++ Bitwise adjacency matrix implementation

I have tried to implement a bitwise adjacency matrix to represent a graph with a fixed number of vertices. Instead of wastefully representing each connection with an integer, 64 connections are ...
Paradox's user avatar
  • 163
8 votes
2 answers
955 views

JVM bytecode instruction struct with serializer & parser

I am writing a java class file parsing & serialization library. As part of that i needed to implement a structure for the JVM bytecode instructions as well as come up with a way to parse & ...
p0sa's user avatar
  • 81
3 votes
1 answer
85 views

Parallel semi-sequential bottom-up tree traversal algorithm

I'm trying to traverse a tree-like structure from the bottom-up, and in parallel. Due to some other constraints I also have to allow for thread counts that may be lower than the width of a given set ...
Goubermouche's user avatar
1 vote
1 answer
85 views

Improved Component-Entity-System Using C++

Introduction I am a newbie, so please take me easy :). I am writing a low-level game engine using C++, GLFW and also OpenGL. This is a continuation of Entity Component System Using C++ I've ...
Andrei Rost's user avatar
9 votes
1 answer
957 views

Geohash library in C++17

GeoHash library in C++17 no allocations and no std::strings. It uses fixed buffer GeoHash::buffer_t. optimized nearby search, if possible, it search 2x2 or 2x3 ...
Nick's user avatar
  • 1,480
2 votes
1 answer
174 views

Entity Component System Using C++

Introduction I'm a new to C++ so please take me easy :) I am currently working on a low-level game engine using C++, OpenGL, and GLFW; I've implemented the Event System and the Input Manager, which ...
Andrei Rost's user avatar