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
vote
1answer
86 views

Generic decorator inspired by functional programming

I made a generic decorator in C++20 with concept for specialization. The idea is to be able to define only one function in the decorator to decorate all functions in a class. You may try it (it's a ...
4
votes
1answer
90 views

Gear Shift Indicator using Hall Effect Sensors & 8x8 LED Display

I wired up a Gear Shift Indicator for my dad's car to display what gear it is currently in, and showing changes with animations (sliding up and down as appropriate, with a few bonus ones for fun at ...
4
votes
2answers
54 views

program that takes string and outputs number of scrabble words and the score for each scrabble word

I wrote a program that takes a string as standard input and checks if the words in the string are in the scrabble dictionary, then checks each letter of the words and gives back the the score of the ...
7
votes
3answers
664 views

Measuring execution time of a function

I was trying to emulate python's timeit in C++. My main aim for this is to measure the performance of small functions of C++ code that I write and print some basic ...
2
votes
1answer
47 views

C++ allocator for std::wstring_convert

In my application, I'm using std::wstring_convert to convert std::string into std::u32string....
9
votes
2answers
674 views

Yet another minesweeper field calculator

The task is to read in a data file containing a representation of a rectangular array with '*' signifying a mine and '.' signifying the absence of one. Each such array is preceded by a row and column ...
5
votes
1answer
99 views

C++ Mine Sweeper Attempt

Saw this question and though I wanted to try. So my version of reading Mine Sweeper: For the Online Judge Some Utilities Classes ...
2
votes
2answers
151 views

C++ - Tic Tac Toe AI powered by minmax algorithm

This was my previous post on Tic Tac Toe in C++. I received very good feedback and tried to implement all of the improvements. I could not implement some due to the AI needed functions or complexity. ...
2
votes
4answers
935 views

Fantasy Character Creation Tool (early prototype)

I recently started studying C++ programming; while attending the course I'm writing a program on the side as a personal project to familiarize with what I'm learning. It is still very basic and I'm ...
2
votes
2answers
79 views
5
votes
4answers
382 views

Disjoint-set data structure (C++)

I'm an intermediate-level C++ programmer aiming to write reference-quality code. I hope to learn about any mistakes in this piece of code and blind spots in my understanding of concepts. Notes: The ...
1
vote
1answer
45 views

Data processing with the CERN ROOT framework

Problem. I have a directory of .root files (the proprietary format of CERN's ROOT framework). These files contain so-called <...
3
votes
2answers
138 views

Online Judge 10189: Minesweeper (C++)

I'm new to C++ (not to programming in general), which I want to learn to participate in some programming contests. I solved the Online Judge Minesweeper Challange. Since I'm not familiar with C++, any ...
2
votes
2answers
474 views

C++ Minimal CSV parser

I wrote a minimal CSV parser for my machine learning toy project. ...
4
votes
2answers
133 views

Prioritise injured cats for treatment (dictionary/map search optimization Python and C++)

I am once again attempting another CP problem, and I have ONCE AGAIN run into an optimization issue because of the time limit of one second: https://open.kattis.com/problems/doctorkattis It is common ...
1
vote
2answers
56 views

Comparison of 2 different ways of writing Merge Sort Algorithm

I have recently learned Merge Sort algorithm in C++ with 2 ways of writing it. 1st Way: ...
5
votes
6answers
6k views

Adding Odd numbers in C++

I have written following code for the this C++ Problem: Write a program to add only odd numbers between one to ten. ...
6
votes
2answers
263 views

Time duration conversion with units

I recently was asked to upgrade some C++11 code to add a feature by which the user can set a time duration from the command line of the program. The requirement was to have a default time of 1500 ms ...
1
vote
1answer
45 views

template function for conditional dereference

I don't know why there's no such function in std (at least I didn't find one). I need a conditional template function to return a reference to an object of T. ...
4
votes
4answers
646 views

Tic Tac Toe in C++ with classes

My first language is Python and I learned considerably a good amount of it. So now I started learning C++. I know the basics of C++ and about classes and inheritance. This is my first serious project ...
4
votes
5answers
1k views

C++11 Custom Vector Implementation

This was my solution to an interview question: Q: Implement an std::vector style container (does not have to be exactly compatible) with a fixed buffer and the following requirements and restrictions: ...
3
votes
1answer
125 views

Object to ignore unused function output parameters

In our software we have some functions that return information through lvalue reference parameters, which, in some cases, are irrelevant for the calling code. For that reason, I tried to come up with ...
2
votes
1answer
77 views

Coding a magic square using 1d or 2d arrays using static allocation

I wanted to know if someone can find a better way to code this in C++ using 1 or 2 dimensional arrays instead of int tables. It has to be a static 7x7 array where ...
5
votes
2answers
134 views
2
votes
3answers
107 views

Optimize lexer/parser bottleneck in C++

I am writing a parser for a custom mesh format for fluid dynamics simulation library, the mesh file contains 3D points (vertices) for the simulation mesh, for example: ...
1
vote
1answer
51 views

Handle C++ templates in Qt5

Searching for a solution to my problem I've read many posts regarding templates in Qt (including those on SE) and didn't find a complete solution (or I should say a complete example of a solution) so ...
10
votes
5answers
3k views

C++ code for calculating the cost of carpet

I have written the following code for the question (from Problem Solving With C++): A store sells carpet for $2.75 per meter. If a customer buys more than 10m of carpet, they get a discount of 15% on ...
2
votes
2answers
92 views

Game States / Pong: SFML Box2D EnTT

Trying to make a little 2D engine I can play with. The end goal is a simple multiplayer PVP game just using shapes. I will make one version using ECS and one using OOP for learning. This is the shell ...
2
votes
1answer
68 views

Simple lightweight CSV reader in C++

My coding background is mostly from C and I've noticed that I tend to "use C++ as it was C" quite a lot. So this is a very small project I've written to improve my understanding of best ...
6
votes
3answers
2k views

Dynamic array implementation using C++

I implemented a basic dynamic array using C++. When deleting an element and shifting the others, the last element will be twice repeated (the original still exists after copying). I want to avoid ...
4
votes
3answers
505 views

Clean up Knight Movement method in a chess project with duplicate code

I am writing a chess project using C++ and SDL. In this method I calculate all available moves a Knight can make and I want to refactor it. I basically move the knight Up/Down 2 squares and then Left/...
5
votes
3answers
366 views

C++20 python-like "range" class

This is a range class, similar in functionality to the range function in python. It was originally made to work with just range-based for loops, like so: ...
4
votes
2answers
79 views

Python's enumerate for C++

I implemented an enumerate() method for C++ containers similar to Python's enumerate to iterate through a range with an index and the actual value. I have the following questions: Does the usage of ...
2
votes
1answer
66 views

GCD of n numbers

According to an online judge, the limit has been exceeded. Could someone help me optimize my solution for the Greatest Common Divisor of n numbers: ...
3
votes
4answers
125 views

Improving my implementation of a unique_ptr - PPP Stroustrup book

This question is an improvement of this one here: Implementing a unique_ptr - PPP Stroustrup exercise Here's my new code, following the suggestions by @JDługosz. I agree with the fact that T* ...
0
votes
2answers
58 views

Implementing a unique_ptr - PPP Stroustrup exercise

I'm doing the following exercise from PPP - Bjarne Stroustrup, Chapter 19, ex.10. Implement a simple unique_ptr supporting only a constructor, destructor,...
2
votes
4answers
90 views

Improving speed and simplify code of "leetcode" Roman Numbers converter

I just have the free account at leetcode. I've been practicing some coding there in preparation for interviews. But I can't see the solution logic behind the ...
2
votes
4answers
109 views

My tic tac toe minimax implementation

This is my first time using StackExchange. I did not have any idea what this website for, but I guess is a place to review the code? So, I'm just going to give it a shot. ...
4
votes
1answer
111 views

Nullable array wrapper class with small size optimization

I have an array wrapper class that I'd like to get reviewed. There are two differences with other common questions on this site. First, my class needs to be "nullable", where a "null ...
3
votes
2answers
116 views

Binary Search Tree in C++ without parent pointers

This is one more implementation of Binary Search Tree in C++. There are many such implementations, however they are typically long and complex, and also many of them rely on pointers to parent nodes ...
6
votes
1answer
206 views

Enabling bitset-like behavior for enum classes (C++20)

I want to enable bitmask-like behavior (ie. overloaded operator|, operator& and operator^...
4
votes
2answers
321 views

War card game with random play

I'm trying to learn C++ with a background in python. This is my first program besides general practice. I wanted to remake the war game. I'm looking to get feedback on the C++ equivalent of its ...
5
votes
1answer
553 views

Thread-safe message queue

In my learning course, I've implemented a message queue to which data gets pushed by some thread and later gets processed by some other thread. My implementation isn't that efficient as it involves ...
5
votes
2answers
169 views

C++ template class to calculate CRC

Here is a template class to calculate various CRC checksums. I go out my way to achieve a good C++ encapsulation for a C style code . Any advice or suggestion is welcome. ...
4
votes
2answers
208 views

Clock display controlled by esp32

I recently got fascinated by the world of micro controllers, and chose to do a simple clock project to see what is what. First attempt I used .Net nanoframework since I'm a C# coder by day, but I ...
2
votes
1answer
70 views

Polling FDs in a helper thread, dynamically adding/removing the descriptors

As I was writing, I realized I have multiple classes polling for file descriptors in its own thread - lots of duplicate code like, synchronization, creating array of pollfds etc. I've decided to ...
1
vote
1answer
50 views

Blocking until one or multiple signals is emitted

I've written this little helper function, that will block the current thread until any of a given list of signals is emitted by an object or until an optional timeout is reached. It can be used to ...
8
votes
2answers
134 views

Simple debug logging

I'm new to C++, and I wanted to add a way to log in a fancy way. As such, I created a small bit of code to do so, but I'm wondering how I can improve my code, especially the fact that ...
2
votes
2answers
61 views

ds4mac - directory switcher for macOS/Linux: the tag engine

I have this program in GitHub. It is used for switching to directories via custom tags. Here is the tag engine: com::github::coderodde::ds4mac::DirectoryTagEntry.h: ...
1
vote
1answer
59 views

Improving poor man's translations mechanism in c++98 program (follow-up)

As a follow-up to this question that was an attempt to add basic translation capabilities in an old c++98 program for the sake of the community, I'm posting here the first iteration of my code after ...