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
2answers
309 views

“observer pointer” meant to stay updated when the pointed object is moved in memory

I wasn't sure about how to name it, maybe "follow_ptr", "self_updating_ptr", or "stalking_ptr" or something on those lines. For now it's called Identifier. What I'm ...
1
vote
0answers
54 views

Skyscraper Solver for NxN Size Version 4

This is a follow up of Skyscraper Solver for NxN Size Version 3 I know its getting old... So I still have the same Issue the code is to slow to solve bigger skyscraper puzzles. Since the last Version ...
2
votes
2answers
106 views

Find neighbours of a vector

To find neighbors of a vector and return array of Vectors which are neighbors of a Vector: ...
2
votes
1answer
54 views

Inserting multiple elements at known locations in a vector

Goal In the vector x, I would like to insert the elements of the vector values at indices stored in vector ...
3
votes
3answers
81 views

Shortest path algorithm

I have a code that does applies Dijkstra's algorithm for an adjacency list. The data are taken from a file. In the file, the first line contains the number of vertices and edges, and the remaining ...
1
vote
1answer
51 views

Function measuring time of another function

I wanted to have a function called timeit which can measure the time of execution of n iterations of any other function. I still learning C++ but I come up with that : Any thought ? ...
5
votes
2answers
95 views

Compressing a vector into a specific range

I want to solve the following task --- I am given a vector of integers. I want to 'compress' this list, where the elements will be replaced with numbers 0 through <...
3
votes
0answers
40 views

A recursive_transform Template Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++ and A recursive_transform Template Function Implementation with ...
0
votes
0answers
56 views

Idea for writing asynchronous data processing chains easier (similar to `ReactiveX`) and its implementation

I'm writing my own library, that is for asynchronous network communication. and then, wanna write my own HTTP proxy server for load-balancing connections to backend servers with it. when I'm using <...
2
votes
2answers
106 views

Can I further optimize this solution for HackerRank's “Making Candies”?

My C++ solution for HackerRank's "Making Candies" problem, reproduced below, is as optimized as I can make it and appears similar to what others say are optimal solutions. However, six of ...
1
vote
1answer
70 views

Check if two types are the same without template instantiations

Below is my attempt to check if two types are the same without template instantiations. ...
7
votes
6answers
2k views

C++ implementation of depth-first search

I got the C++ implementation of depth-first search (DFS) from here and made slight modifications to it. The modified code is as follows: ...
5
votes
0answers
64 views

Emplace a lambda which captured a unique_ptr into container like queue

I'd like to emplace a lambda which captured a unique-pointer into a container, but it failed to compile under GCC 7.3.0 as C++17. From the error messages, it's calling the copy constructor of ...
0
votes
1answer
41 views

caesar cipher (rot<2-25>)

I'm a rookie in c++ programming. Recently, caesar ciphers caught my eye. I ended up making a rot<N> text converter, where N is any value between 2 and 25. Please keep in mind that I'm still new ...
2
votes
0answers
59 views

Algorithm for auto tiling of tiles in a 2D tile map

Introduction I have implemented an algorithm that applies auto tiling to a 2D tile map for a game, selecting the correct tiles according to their neighborhood. Given a string representation in a ...
4
votes
4answers
921 views

Given two vectors of ints, determine whether one vector is a prefix of the other

Given two vectors of ints, write a program to determine whether one vector is a prefix of the other. For vectors of unequal length, compare the number of elements of the smaller vector. For example, ...
2
votes
0answers
64 views

Reading stdout and stderr of a sub process using Win32, Overlapped I/O

I'm writing C++ Windows code that will start a process, then read its stdout and stderr, separately, into buffers. If I try to just read the streams one at a time it may hang if the child process is ...
0
votes
0answers
31 views

A batch_recursive_count_if Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count_if Function For Various Type Arbitrary Nested Iterable Implementation in C++ and A recursive_count_if Function with Unwrap Level for Various Type ...
2
votes
1answer
51 views

Multiply a square matrix with only the diagonal and antidiagonal elements different from zero in vector [closed]

So I have a square matrix with the diagonal and antidiagonal elements different from zero in a vector vector<int> matrix = {1,2,3,4,5,6,7,8}; The matrix: <...
1
vote
2answers
77 views

Read strings from a standard input, and find the most duplicated word

Write a program to read strings from standard input looking for duplicated words. The program should find places in the input where one word is followed immediately by itself. Keep track of the ...
3
votes
2answers
113 views

Pluralize a string

I find that a common pattern when outputting a message is the need to pluralize a word. For example, if I need to output a count of files found I would need to write something like ...
0
votes
2answers
65 views

Algorithm that creates in a systematic form, matrix with zero-one elements

I'm working on Rcpp and I wrote the following code ...
1
vote
0answers
67 views

“tuple with named fields” implementation

I'd like to show you a type I made while experimenting with literal, non-type template parameters in C++20. The idea is to provide a type that wraps up tuple-like types (std::tuple, std::pair, even ...
1
vote
1answer
55 views

Single player Rock Paper Scissors game

Here is the RPS game I made. I watched a 4 hour tutorial about C++ from freecodeacademy and produced this game right after it. If you have any feedback or suggestions please let me know. Or if there's ...
3
votes
1answer
73 views

Basic TicTacToe implementation in C++

Just created my first C++ project, and wondering if I could get some feedback on where to improve? I might swap from arrays to vectors and add alpha beta pruning later, but wanted to first see where I ...
0
votes
0answers
43 views

Optimizing matrix vector multiplication with keyword “register” and unsafe pointer arithmetic

I know this piece of code is quite strange, but it does its job very well performance-wise , reducing the running time of a very computation intensive operation by 3 - 5 times without using a better ...
1
vote
1answer
50 views

Skyscraper Solver for NxN Size Version 3 (Using Bitmasks)

This is a follow up of Skyscraper Solver for NxN Size Version 2 (Using Backtracking) I followed the advice in the last Codereview and did the following optimizations: Implementation of the class <...
1
vote
0answers
34 views

Indicating a lost signal when streaming live video with GStreamer and Qt

The goal of the code is to display a live camera feed sent by GStreamer over UDP, and to give an indication of when the signal is lost by displaying a static blue screen instead of the last frozen ...
1
vote
1answer
53 views

Abstracting device IO / glue logic in a CPU emulator

In my Motorola 6809 CPU emulator (written in C++14) I'm working on an abstraction to represent the wiring between emulated devices, such as the ports on a 6522 VIA, or the interrupt lines connecting a ...
3
votes
3answers
104 views

Add 10000 days to a date

I'm currently doing old exams from my course to train for my upcoming exam. What I'm wondering is about a code block which I will specify after I've presented the different files with code. //...
2
votes
1answer
61 views

Traverse directory using multithreading

I have written program which following purpose Traverse directory in multi threading environment First determine all top level directory and store into vector which have following result: /home/dir1 ...
1
vote
1answer
154 views

Insert an array[4] to an array[8] (C++, SSE)

I have this code to get audio output levels in dB to an array (peak_dB[8]) to be used in real time peakmeter: ...
18
votes
6answers
4k views

A C++ program to check if a string is a pangram

I'm new to C++ and decided to implement a simple program that checks if a string is a pangram (i.e. the string contains all the English alphabet letters). It's my first program in C++ and I have some ...
0
votes
0answers
24 views

Boost.MultiArray Based Two Dimensional Array to Markdown Table Converter Implementation in C++

I am attempting to implement a converter which can convert two dimensional array (using Boost.MultiArray library) into markdown table. The experimental implementation ...
-1
votes
1answer
57 views

Optimizing a bit manipulation formula [closed]

I previously posted this question in Stack Overflow, but I was told to post it here as my code is already working and I'm just trying to optimize it. Background: I'm developing a Game Boy emulator, ...
9
votes
5answers
2k views

Unit test for a maximum-finding function

A while ago, I got this question as a part of an interview test which asked to write a function to find the biggest number in a vector and write all the unit tests required to show that the code works ...
1
vote
1answer
121 views

Skyscraper Solver for NxN Size Version 2 (Using Backtracking)

This is a follow up of Skyscraper Solver for NxN Size I followed the advice in the last question and changed my approach from generating Permutations to use Backtracking to solve the puzzle. ...
3
votes
1answer
74 views

lazy_map implementation in C++ | Similar to unordered_map but O(1) copyable

I implemented lazy_map - https://github.com/tinytrashbin/lazy_map. Can someone help with reviews ? lazy_map is an implementation of unordered_map that has O(1) cost of copying irrespective of the ...
6
votes
1answer
30 views

Insert into any sorted container

The following is my attempt to implement a insert_sorted() C++ function that accepts any sorted STL container and item and inserts it at the right position in the ...
0
votes
2answers
97 views

C# to C++: Basic Console Replication

I'm working on converting my basic cryptocurrency miner from C# to C++ for performance reasons (I've been told that C++ is faster in many aspects). However, that aside, the focus of this post is to ...
8
votes
2answers
145 views

re-implementation of std::vector

I've implemented a simple vector-like structure. I would appreciate all criticism relevant to code. I have also published code under github. Here is the link to source code + unit test for most ...
4
votes
1answer
158 views

Stop Watch class in C++ using chrono

I have written a class that acts like a stopwatch using C++11's std::chrono library. I wrote this because I find it difficult to benchmark my cpp code properly, ...
0
votes
1answer
69 views

dlinfo(… SERPATH …) C++ wrapper

dlfcn.h is a library of C functions to work with dynamic dependencies (shared objects). I've been experimenting with wrapping them in a C++ API, mostly as practice in making a C++ wrapper. This is an ...
4
votes
2answers
937 views

Securing my password wallet

I am currently learning C++, so I made this basic password wallet for Ubuntu. Its source code is in the /opt directory and it has a symlink so i can launch it from ...
6
votes
1answer
105 views

C++20 generic math vector implementation

I wrote a math vector implementation using expression templates to add a little boost to "chain operations" like: ...
0
votes
0answers
51 views

Performance discrepancy between Windows and Ubuntu for a video-memory-based virtual array implementation

I implemented virtual array using OpenCL and graphics cards as backing store, with caching some of data on RAM using a LRU algorithm and accessing data through some simple setters/getters. Accession ...
2
votes
1answer
127 views

C++ generic, multi-dimensional linear interpolation template

Use-case in a nutshell: Interpolate fixed-sized data (a lookup table) that provides output values for combinations of a (fixed) number of inputs. The appropriate scaling is done externally, each axis ...
1
vote
1answer
43 views

OpenGL Shader Loader in C++

I made my own custom OpenGL shader loader for C++. Please tell me is I'm doing anything incorrectly or anything to improve on. I've tested this and it works perfectly fine. main.cc ...
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
138 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 ...