Skip to main content

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
10 votes
8 answers
966 views

Print all correct parenthesis sequences of () and [] of length n in lexicographical order

Given a number n, print all correct parenthesis sequences of parentheses and square brackets of length \$n\$ in lexicographical order. You must enter an integer \$n\$ from 0 to 16 inclusive. The ...
-1 votes
0 answers
33 views

Reads in 2 ints and prints them, terminates if '|' is entered [closed]

Background: I'm learning C++ from Programming, Principles and Practice using C++by Bjarne Stroustrup. This is from Chapter 4, Drills, the first Drill. The exercise: Write a program that consists of a ...
8 votes
3 answers
1k views

is_decimal Function Implementation in C++

This is a follow-up question for is_number Function Implementation in C++. Considering G. Sliepen's answer and Harith's answer, I want to focus on decimal number here, therefore, ...
3 votes
0 answers
81 views

Toom-3 big-integer multiplication algorithm

I am developing a C++ big integer library for C++11, 14, 17, 20, etc., as an exercise. The Toom-3 algorithm is resisting me a little bit. AFAICT, it does produce the right results but not as fast as I ...
0 votes
0 answers
37 views

Parser for a static interpreted programming language

...
5 votes
1 answer
218 views

C++ static vector revised implementation

This is a revised and expanded implementation of the original static_vector implementation based on the various suggestions and corrections from the kind people who reviewed the original version.The ...
0 votes
0 answers
21 views

using of boost::asio::placeholders::error [closed]

The code snippet below is seen at this page. ...
2 votes
1 answer
66 views

Calculating array segment uniformity using a segment tree

You have to analyze some array of \$n\$ numbers. In particular, you are interested in the so-called array uniformity. Suppose that in the array the number \$b_1\$ appears \$k_1\$ times, \$b_2\$ \$k_2\$...
3 votes
2 answers
87 views

Minimum length of specific substrings

Given the string \$s\$. It is required to answer n queries. The \$i\$th query consists of an integer \$k_i\$ and a string \$m_i\$, the answer is the minimum length of the string \$t\$ such that \$t\$ ...
6 votes
3 answers
173 views

Find the number of cycles of length 3

Given the count. Find the number of cycles of length 3. Input format: The first line contains two integers n and m (1 < n, m ≤ 3✕10⁵) — the number of vertices and edges, respectively. Each of the ...
2 votes
2 answers
58 views

Implementation of an Ordered Character Class

Overview The code below is my attempt a solving a problem that came up in one of my projects. I needed a type that could be constrained to a defined list of characters, be set to a specific character, ...
14 votes
4 answers
11k views

BigInt class in C++

I made a BigInt class that supports almost all functions an int would. The code seems too bulky and there might be a few bugs lurking here and there. I would like ...
7 votes
3 answers
404 views

conv2 Template Function Implementation for Image in C++

This is a follow-up question for An Updated Multi-dimensional Image Data Structure with Variadic Template Functions in C++. I am trying to implement conv2 template ...
8 votes
3 answers
2k views

Why/How is Matlab's circshift function so efficient?

I have the following function in Matlab: ...
5 votes
1 answer
99 views

Program to output Low and High pass filter impulse response coefficients for signal processing

My issue that I was trying to solve was constructing a vector where the values were mirrored around the central element. The problem is here: https://stackoverflow.com/questions/58876916/construct-...
5 votes
1 answer
100 views

Fibonacci and Lucas sequence generator using Boost and GMP

I implemented this console application that generates Fibonacci and Lucas sequence numbers using boost and GMP for multiprecision. There is an iterator-like class which can do any sequence based on ...
5 votes
1 answer
83 views

Unrendering a Component of an embedded C++ Graphics Library

This is an extra short one, since I need some guidance on best practice for C++. It's been a while since I did some C++ in general, and its the first time for me developing on a microcontroller. I am ...
12 votes
4 answers
2k views

C++ static vector implementation

This is my custom static vector implementation similar to Boost’s StaticVector. Basically the idea is that the container should have a fixed compile time capacity, ...
8 votes
2 answers
822 views

Efficient file-copying utility using threads

The task is to implement simple 2 threaded "copy" tool. Tool should accept 2 parameters: source filename and target filename. Copying logic should be organized with help of 2 threads. First ...
13 votes
1 answer
4k views

Container with sorted by multiple keys

From this question: Sorted vector (aka flat_set) for objects (pointers) with custom embedded key (functor used) This is an example of a multi-index container. Note: this is not a container as ...
5 votes
1 answer
169 views

Implementation of a `shared_any`

Below is an implementation of a shared_any: ...
3 votes
1 answer
102 views

A Windows localhost key logger in C++ with WinAPI

Now I have this repository. It's a key logger logging all the keyboard events possible. Note that some programs do not "leak" the keyboard events outside of their GUI. For example, Notepad++ ...
1 vote
0 answers
39 views

Two Dimensional Discrete Fourier Transform Template Function Implementation for Image in C++

This is a follow-up question for An Updated Multi-dimensional Image Data Structure with Variadic Template Functions in C++. For learning purpose, I am trying to implement two dimensional discrete ...
4 votes
4 answers
1k views

A thread-safe simple logger

Since the vprintf is not thread-safe, so I use a std::mutex. It's a pity that there are a lot similar macros(both name and ...
7 votes
2 answers
191 views

Function composition in the context of data processing pipelines

Prior Notification This follows a previous review of mine that addressed the core helper function named make_skippable. The composition implementation presented ...
8 votes
3 answers
114 views

Generic overloading bitwise functions to manipulate the enum type

Thanks to G. Sliepen, who gave me a lot very meaningful & useful advice on my implementation about overloading bit operators for a special scoped enum. Now I have modified the code snippet to ...
6 votes
3 answers
499 views

locale-aware trim functions for std::string

I have written the below two trim functions for std::string and std::basic_string that are locale-aware. Both trim all white ...
6 votes
2 answers
353 views

To markup a C++ std::ostream and delegate formatting of markuped text

I want to create a system that marks up text with tags inserted into a stream. Each tag frames a part of the text, creating a tree-like structure, just as in classic markup languages (HTML, XML...). I ...
6 votes
2 answers
768 views

Querying and executing actions on the result C++

I was challenging myself to make a way to easily perform actions on a list of objects. The idea is to prevent the copying of the list. I came up with the following, what I think is quite elegant. But ...
6 votes
1 answer
381 views

C++ program to format byte sequences into Python like string representations

This is a C++ program I wrote, that includes functions to convert integers to byte sequences in little endian or big endian order, and functions to convert a byte sequence to a string representation. ...
2 votes
1 answer
704 views

Applying Dijkstra's algorithm on a graph of five nodes [closed]

Last week I posted a piece of code to apply Dijkstra's algorithm to calculate the shortest path between two nodes in a graph. Now, I've made some improvements, but I am still having difficulties. I ...
8 votes
3 answers
2k views

fmap for containers in c++

I implemented a simple fmap for containers. However containers don't have a unified function to add elements. So I wrote different concepts for different containers. Is there a better way to implement ...
4 votes
2 answers
384 views

Compile time string manipulation in C++

I recently had to work on some conversion of literal strings and wondered if that could be done at compile time using template meta programming. I couldn't find many examples online, so I started ...
26 votes
5 answers
2k views

Inventorizing the universe

I recently started re-factoring a project I hadn't touched in many months. The original purpose was to be an inventory management system for a game I played, Ogame. In this game you play inside a ...
13 votes
10 answers
8k views

Tests for palindromes in C and C++

A question I've been asked on interactive phone screens is to code a test to determine whether a string is a palindrome or not. I am providing two examples here: one in C and one in C++. They both ...
4 votes
1 answer
682 views

Using builder pattern and facade pattern in real project

The code below is used to upgrade the firmware of three different types of cameras. I am not good at design patterns. I wonder if it is suitable to use builder pattern and facade pattern here. Since ...
5 votes
2 answers
247 views

ostream that counts and discards the characters written to it

The code below implements a class, CountingOStream, whose job is to count the number of characters written to it while also discarding those characters and ...
18 votes
2 answers
2k views

C-style language lexer for a syntax highlighter

I'm working on implementing a syntax highlighter for a simple text editor I've been working on. To do this, I need a simple lexer for various languages (I don't need a full one - I'm only interested ...
9 votes
1 answer
395 views

sha1sum implementation in C++

I rarely program C++ in anger, and considered myself somewhat rusty, and certainly not up to speed on C++11. For a bit of exercise, I thought I'd try implementing sha1sum, as wasn't really up to speed ...
2 votes
1 answer
52 views

Overloading bit operators for scoped enum

The code snippet is used to record the status of several cameras. Since the enum class MODULE_ENABLED should not be used by the customers directly, I marked it as <...
4 votes
5 answers
800 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 ...
5 votes
2 answers
948 views

An Implementation of UNIX wc shell utility

The implementation doesn't support the "-m" flag, and only works with ASCII, and has rather terrible output formatting in comparison with GNU's implementation of wc. Code: ...
3 votes
1 answer
49 views

Advanced String Calculator with asin, acos, atan Functions in C++

This is a follow-up question for Advanced String Calculator in C++. Considering the suggestions mentioned in MrBean Bremen's answer, I am trying to update the implementation as below. The experimental ...
3 votes
1 answer
153 views

Advanced String Calculator in C++

This is a follow-up question for String Calculator in C++. Considering the suggestions mentioned in MrBean Bremen's answer and Martin York's answer. I am trying to modify the code and trying to ...
10 votes
6 answers
2k views

Efficient C Tokenizer/Lexer in C++

I wanted to create my own compiler for C and it's the first prototype of the Lexer. Any thoughts on improvements? Note: I forgot to add comment lines in header files while I was coding, but I assure ...
5 votes
1 answer
366 views

Fast and precise summation of random numbers

I'm trying to first formulate this challenge. In short, we want to sum up an stream of random numbers with the following objective: The objective is "simply" to sum up as many sequences as ...
5 votes
1 answer
552 views

The Wu line drawing algorithm for anti-aliased lines optimization

I need to optimize the following function with low-level optimizations (No SIMD, Multithreading). I already applied a lot of optimizations and got it ~65% faster, but it is possible to get it 200% ...
2 votes
3 answers
106 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 ...
5 votes
1 answer
185 views

Parsing command-line arguments with getopt in C++

I did not find anything to parse command-line arguments in C++ (which was surprising), so I fell back to getopt() which has served me well in C (I am currently not ...
4 votes
2 answers
894 views

OpenGL: Freeing allocated memory

Here's a snippet of my code. I have a Button structure made up by 2 Figure structures, which contains vertices, colors and the relative VBOs and VAO. I have a function to allocate the memory and one ...

1
2 3 4 5
191