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
3
votes
1answer
57 views

Real time histogram using multithreading (Qt + Qwt)

I'm writing a GUI for different VME modules (electronics). There are several of them which are used for the data acquisition. For example, an ADC produces the digitized maximum voltage on its input. ...
2
votes
4answers
114 views

Single-linked-list in C++ with iterators

I'm implementing a single linked list as close as it could be to std::forward_list. I would welcome a review and also more suggestions on what to test additionally. ...
1
vote
2answers
53 views

Implementing std::format - Part 3

This is a follow-up to this question. Here I’m trying to do something useful with the format specifier. I guess I should have started with width and ...
4
votes
1answer
73 views

C++ : Allocator for fixed size object

I'm reading "Modern C++ Design" (A. Alexandrescu, 2002). The author said "the standard memory allocator is awful for small objects", but it has been two decades after the book has ...
1
vote
2answers
40 views

RE: Find maximum value of recursively-defined "fusc" function

Continued from the previous post - a brute-force approach to calculating all the vectors from 0 to n. I've come up with yet another solution, after I've realized that the vector takes up too much ...
0
votes
2answers
95 views

Binary search with self-test

Here is an implementation of binary search. Please give feedback on any part but a few specific areas I was wondering about. Is size_t used appropriately or should ...
7
votes
4answers
1k views

C++ mkdir shell utility

Abstract The bash shell utility mkdir is a tool used to create directories in most POSIX environments. I thought it would be fun to implement such functionality ...
6
votes
2answers
776 views

Read and write triangulated surfaces

Recently, I wrote a class which can load an .obj file into vector array, and save the vector array as an .obj file. The .obj file looks something like this: ...
3
votes
3answers
446 views

Find maximum value of recursively-defined "fusc" function

I've been trying this question from SPOJ, which asks for the user to enter a number n, and they will receive a maximum fusc value that lies in between 0 to ...
4
votes
4answers
321 views

Portable and efficient Caesar cipher

Implementation of a Caesar cipher is a popular exercise and there are many implementations posted here on Code Review. My version is intended to be efficient and portable (subject to some limitations, ...
4
votes
2answers
338 views

C++: Linear Regression and Polynomial Regression

I wrote a simple linear/polynomial regressor based on my previous matrix project (https://github.com/frozenca/Ndim-Matrix). ...
2
votes
1answer
443 views

Generic Event class

C++ Event class From the desire of having a callback function which includes a void* userdata argument, I've made this generic event class. It is tested and working, but some desired features are ...
3
votes
1answer
60 views

Implementing std::format - Part 2

This is following up on this question In this part, I wanted to be able to choose arguments by index and have a placeholder for the format of the argument. As usually happens, my initial ...
3
votes
1answer
84 views

Compute 1 + a + a² + … + aⁿ

Given a real number a and a natural n, calculate the sum 1 + a + a² + … + aⁿ, without using the formula for the sum of a geometric progression. The running time of the program must be proportional to ...
2
votes
1answer
75 views

Reading lines from a non-blocking reader

I want to read \n terminated, UTF-8 encoded lines from a network connection and process each full line. I cannot use fgets, ...
1
vote
2answers
34 views

A recursive_count function with recursive_depth for unwrap_level checking in C++

This is a follow-up question for A recursive_depth function for calculating depth of nested types implementation in C++ and A recursive_count Function with Unwrap Level for Various Type Arbitrary ...
3
votes
2answers
98 views

C++11(14/17/20) Thread Management

I'm implementing something of a thread janitor in modern C++. What I've got works, and while it's not organized in the way I'd like yet, I'd like some feedback on the fundamentals. Thank you in ...
2
votes
1answer
55 views

Implementation of an entity component system in c++

I tried to write a simple entity component system for my game engine. Each scene will have an EntityManager. It will create entities and add or remove components from them. An entity will be destroyed ...
7
votes
2answers
517 views

Implementing std::format

One of the most exciting new functions in C++20 is std::format. I have never liked the ways that strings are formatted in C++ and have been guilty many times of ...
1
vote
1answer
43 views

K largest elements in an array

I solve problems to prepare for interviews. Now I have written the algorithm of finding K largest numbers in array. Various solutions are described here: https://www.geeksforgeeks.org/k-largestor-...
-1
votes
1answer
40 views

What changes are required to this function to suppress C26430 code analysis warnings?

See this method: ...
3
votes
2answers
51 views

Testing MRU-list vs. standard list

The task is to test the the benefits of a Move-To-Front Linked List vs. a standard Linked List. It was also meant to practice inheritance and pointers. The standard functionality is in ...
2
votes
1answer
50 views

A recursive_depth function for calculating depth of nested types implementation in C++

This is a follow-up question for A recursive_count Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++. A function ...
4
votes
3answers
761 views

SDL2 engine base implementation

I would like a little help with the implementation of my SDL2 engine. It's actually not a real engine nor does it strive to be but I don't have a better word to describe it. The purpose of this ...
3
votes
2answers
78 views

C++11 revised `std::latch` implementation

This question follows up on this question. After turning the while-loop into a conditional wait using std::condition_variable, I ...
1
vote
1answer
56 views

Implementation of a latch

As an exercise to learn more about multi-threading and atomic operations work in C++, I decided to implement a latch class in C++11 loosely based off of std::latch ...
2
votes
3answers
69 views

Abstraction for CSV files

I made a CSV class which manages CSV files. Is this good?, I'm beginner btw. It's probably bad but can you give me some tips! Header file: ...
8
votes
3answers
1k views

C++17 : Typelist manipulation

I'm reading "Modern C++ Design"(A. Alexandrescu, 2002) and practicing basic TMP in chapter 3. Typelists. Since the book is quite dated, I revised example codes in C++17-esque manner. Feel ...
1
vote
1answer
76 views

Printing odd and even numbers in separate threads C++

I recently saw a youtube video on printing even and odd numbers from 0 to 100 in Java. https://www.youtube.com/watch?v=eRNTx8k5cmA Thread 1 prints even numbers and thread 2 prints odd numbers. Both ...
2
votes
2answers
390 views

How to avoid excessive for loops in C++ [closed]

I have been trying to write a small test program and I was trying to think of any potential optimization I could do, especially if there is any chance to avoid some of the for loops. The program has ...
0
votes
2answers
86 views

C++ Observer Pattern with std::function

I am/we are using the observer pattern for many things in our application. I think it's time to create a reusable base class for these situations. Most implementations I could find only do something ...
0
votes
2answers
95 views

Little program to measure the 'cost' of CPU-operations

This is a follow-up on my first question, Little program to measure costly operations, thanks for all answers and comments, esp. @JDługosz. I made a second attempt adapting a teaching program I found ...
1
vote
3answers
121 views

Count how many iterations of deletion until array is ordered

I'm trying to write a program whose input is an array of integers, and its size. This code has to delete each element which is smaller than the element to the left. We want to find number of times ...
1
vote
2answers
65 views

Little program to measure costly operations

I want to learn about performance impact of different calculations and influences/optimizations like compiler flags, use of SSE, AVX etc. I'm going to code some small subroutines which will take place ...
7
votes
4answers
1k views

Benchmarking data copying

I got inspired by a recent question to do some benchmarking on the different methods to copy data and this is what I have come up with: ...
0
votes
2answers
76 views

Separating odd numbers and even numbers into two vectors in C++

I'm learning C++, and would like some guidance. I'm pretty sure I'm doing something wrong. This algorithm runs in O(n) time and uses O(n) external space. Could I make a more efficient algorithm for ...
5
votes
1answer
316 views

C++20 std::array implementation

I'd like to have a review on my C-style array wrapper. I based this on std::array implementation. I hope you can leave some feedback! array.ixx ...
3
votes
1answer
54 views

A predicated version of std::for_each

For reasons, I want to implement a predicated version of std::for_each. I know that, in C++20, this is made somewhat redundant or less useful, as we can use ...
6
votes
6answers
2k views

Left Shift/ Right Shift an array in C

I am trying to implement a Left shift/ Right Shift on arrays. I was able to accomplish this using double loops. Can the efficiency be improved? This is the working code for LeftShift/RightShift which ...
0
votes
1answer
114 views

Codeforces - problem: (A) Mike and palindrome

While on SO someone posted this question and I gave it a quick try. My solution passed all the testcases. Link to the problem: Problem: (A) Mike and palindrome Question: Mike has a string s ...
2
votes
1answer
40 views

Implementing a News Ticker

I implemented a console version of a news ticker and I will be glad for a code review. It takes a text from the user and displays it for a given period. How may I get it better? ...
1
vote
1answer
116 views

Win32 UI with tabs and buttons

I am making a UI library for the fun of it, and decided to use move semantics instead of pointers with new/delete. Everything is working, but I am not satisfied. Given this code: ...
1
vote
1answer
69 views

Target Sum array using Dynamic Programming

I'm learning Dynamic Programming and trying to solve this Target Sum array problem. I've to find an array of integers that sums to a given target sum using the integers of given input array. I've used ...
3
votes
1answer
56 views

View of submatrix, in const and non-const form, preserving const-correctness

Here are implementations of both non-const and const view of submatrices, which is a subclass of my toy C++ matrix project: (C++20 : N-dimensional minimal Matrix class) MatrixView.h ...
-1
votes
2answers
41 views

Refactoring class member initialization C++ [closed]

Have this code do what I want: If there is argument pass to constructor, initialize; otherwise, set it to default value? ...
3
votes
3answers
93 views

Convert program arguments to std::wstring

Due to recent need I wrote a simple main function that has the goal to convert the C-style strings and arrays into a more STL-style. Then because I also had a need ...
2
votes
2answers
89 views

C++ Splay Tree implementation

I am coding a Splay Tree class in C++. I am looking for code review. Currently, my Splay Tree class has search and rotate function. I feel that I'm doing things overcomplicated. ...
2
votes
3answers
249 views

tic-tac-toe game with a vector

This is my first game ever. I' learning C++ now and I decided to make a game. I saw a snake game that works with the draw-input-logic system and I really liked it. I tried to make a tic tac toe game. ...
5
votes
2answers
607 views

Hangman game coded in C++

I have completed my hangman project in C++. I would like your thoughts and improvements on my implementation. Here is the code: ...
0
votes
2answers
82 views

Year/month difference calculator

My program calculates the user's age in years and months. It takes the user's birth year and month and then the current year and month as input. ...