Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

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.

1
vote
0answers
24 views

Binary Search Tree to store objects now with improvements

Objective: I'm trying to create a BST in order to insert Packet objects for search purposes. Packet holds information like partId, ...
4
votes
0answers
29 views

Sodoku solver with arrays of bitsets

I wrote a quick sodoku solver as an exercise and am curious how to make it faster. Parsing and printing is largely irrelevant only there for readability. How can I make the code cleaner and faster? <...
2
votes
0answers
24 views

EEPROM-based filesystem, aiming for Misra C++ 2008 compliance [on hold]

I'm writing code for embedded systems (IAR compiler) and it should adhere to Misra C++ 2008. This limits the available features of the language quite a bit (no C++1x features, use of the standard ...
4
votes
1answer
34 views

C++ wrapper around uniform mt19937 SequenceContainer [on hold]

With the following interface in mind EasyRandom<unsigned int> prng(a, b); auto x = prng(); // scalar auto v = prng(10); // vector I wrote the following ...
2
votes
2answers
64 views

Binary Search Tree to store objects by object ID

I'm trying to create a binary search tree that would be used to insert my Packet objects'. It holds information like partId, ...
2
votes
2answers
71 views

Loan repayment calculator

I am having some trouble figuring out how to modularize this code without rewriting it entirely. I know I should be able to break it up into modules for main, gathering info, doing calculation and the ...
-1
votes
0answers
25 views

Right thread implementation in frequently invoked method [on hold]

I am fresh in c++ But actually what I am interested in : I have such method ...
3
votes
1answer
106 views

A simple TCP command executer

In https://github.com/pc-magas/tcp_command as an attempt to learn C++ I made a simplistic TCP server in GNU/Linux that will receives simple "commands" in ASCII form. Each command ends with '\n' and a ...
11
votes
0answers
39 views

Continuous Fourier integrals by Ooura's method

I have a PR implementing Ooura and Mori's method for continuous Fourier integrals. I used it here to compute an oscillatory integral that Mathematica got completely wrong, and then I thought "well ...
4
votes
1answer
41 views

CUDA matrix class

I started to work on this CUDA C matrix class to learn both the object oriented programming in C++ and to learn CUDA. The initial goal of this project was to make a matrix class that can have almost ...
6
votes
0answers
33 views

Concurrent Queue Adapter

There's lots of code out there for basic adapters of std::deque to provide a thread-safe queue. I've adopted that, but wanted to provide a relatively full analog to ...
9
votes
1answer
36 views

Mixed-width operations for std::bitset

When I was looking to use std::bitset instead of GCC's __uint128 in my RDS error-corrector, I found that it was hard to use, ...
6
votes
1answer
50 views

Max function with variable number of arguments

I find it irritating that in standard C++ I can't do std::max(a, b) = x when it's possible and that it can't handle more than 2 arguments. For the second concern I ...
-1
votes
0answers
15 views

UVa Problem 10300(Getting Runtime Error SIGKILL) [closed]

I am solving UVa problem no 10300. But I am getting runtime error SIGKILL for the follwing code. ...
-2
votes
0answers
23 views

UVa Problem no. 10038.(Can't get correct output for some cases) [closed]

I am currently solving the UVa Problem no. 10038. So, to debug my code I went to uDebug. And found that my code was almost complete but with some exceptions. I want the following code to reviewed. ...
2
votes
0answers
90 views

Event management system in C++

I have this question asked as home assignment for an interview. I submitted my solution and did not get selected. Wanted to know your feedback for the solution. Question: Write a very simple ...
5
votes
0answers
60 views

Neural Network with Template Metaprogramming

I was implementing a simple neural network, and I noticed that, if I ever wanted to change the layers' activation functions, i would have had to completely rewrite some parts of the code, so I tried ...
8
votes
2answers
98 views

Read file into vector<byte>

I need to read a range of bytes from a file and return it as a std::vector<std::byte>. My current code looks like this: ...
3
votes
0answers
37 views

Simple and safe C++ pool allocator

I have written a simple pool allocator for C++ and I'm looking for ways to improve it, in speed, usability or safety. For example, I don't know how to allocate a buffer larger than the pool size. <...
-1
votes
0answers
23 views

C++ program about dates and times [closed]

so, I have this much of the program done I still have to determine leap years: A leap year is one whose number is exactly divisible by four. Century years, however, are only leap years if they are ...
3
votes
0answers
58 views

Simple C++ Console Snake Game

I'm a beginner programmer and i'm looking for interesting projects to improve my low skills. I decided to spend one evening on simple snake game in console. I made it with the help of YouTube tutorial....
27
votes
5answers
3k views

C++ logging library

I am creating a logging library in C++, and I wanted your opinion on code quality and performance within some methods. You may ask why yet another logger - the answer is simple. This logging library ...
3
votes
0answers
24 views

A C++17 std::function implementation

Some time ago I implemented dynamic_array and posted it on Code Review. It used std::function internally for type erasure. This ...
5
votes
1answer
82 views

C++ practice project: Blackjack

For the longest time I always felt lost designing a robust OOP program, especially in C++. I felt like I didn't know enough theory or algorithms so I would study and never write code, not to mention I ...
5
votes
0answers
95 views

Yet another multi-producer single consumer queue in C++17

Here's an implementation of a multi-producer single consumer queue that I wanted to use with tasks such as logging from multiple points in a program to a single sink. The implementation is inspired ...
3
votes
1answer
118 views

Determine concurrent access to a function

Someone asked here how to determine a function is being called from multiple threads. My take on this is that they are asking about concurrent access not sequential access. The accepted answer ...
4
votes
0answers
37 views

C++17 implementation of std::invoke

C++17 introduces std::invoke which calls the exposition-only INVOKE. Here is an implementation. This isn't a large amount of ...
5
votes
1answer
48 views

Prime Sieve and brute force #2

Based on my previous attempt. Prime Sieve and brute force Trying to make the interface simpler I have moved all the code into a class. This way I can keep track of the ...
7
votes
1answer
63 views

Parallel Ramanujan's formula for 1/π calculation

I finished my university project for calculating \$1/\pi\$ and I would love to get some feedback. Before you guys jump into this code please keep in mind newcomer to C++ just decided to use it for ...
3
votes
0answers
68 views

A fixed-size dynamic array

Background I implemented the historic std::dynarray according to the specification under the name dynamic_array in C++17. ...
9
votes
2answers
1k views

Implement Own Vector Class in C++

I am preparing for an interview and came to know about this question: implement a vector class in C++. I thought of how I would write it an interview and included the code below. The things I know I ...
6
votes
2answers
89 views

Program for activity selection exceeds time limit

I've been trying to solve this problem for some while and the solution I have come up with exceeds the lime limit by 1-3 ms and 2 out of 10 tests get a memory issue error. Why is that? This is the ...
4
votes
1answer
35 views

Generic calendar which can hold Mayan, Babylonian, Fantasy, Gregorian calendars

I have created this generic calendar class which I call a TimePeriodGrouping. It can contain a series of interlocking time periods (i.e. years, months, days, hours...). When time is added to one of ...
14
votes
3answers
1k views

Prime Sieve and brute force

Got caught up with this morning's C++ question. So I thought I would have a go. SO here is my attempt at printing the first 1001 primes. ...
7
votes
1answer
58 views

C++ Windows Directory Watcher

This was a small project I did the other day because I wanted to explore a solution to hot-reload some files in another project. My requirements were: Act in it's own thread Be able to watch ...
8
votes
2answers
2k views

Project Euler #7 10001st prime in C++

By listing the first six prime numbers: 2, 3, 5, 7, 11, and 13, we can see that the 6th prime is 13. What is the 10 001st prime number? How can I optimize this code? ...
8
votes
2answers
181 views

C++17 thread pool

I've implemented a thread pool in C++17. This is not backwards compatible with C++14, due to the usage of std::invoke_result, which is new to C++17. The focus of ...
32
votes
8answers
5k views

Thread Pool C++ Implementation

I have been working on this thread pool for awhile to make it as simple to use as possible. I need some tips on improving performance, and some good ways to test its performance. I was wondering if ...
4
votes
1answer
66 views

Lexer using C++ and Regex

I'm trying to create a very basic compiler, and I'm working on the lexer. I decided to store keywords and operators in an unordered_set, and use regex to match identifiers and literals (no comments ...
3
votes
0answers
40 views

Graph Search in C++17

Overview I am constructing a Graph with randomly generated nodes called Positions. The Graph has a width and a height and is represented using an adjacency list <...
5
votes
1answer
69 views

Classic Tetris implementation for Windows console (Follow up)

This is a follow up question of Classic Tetris implementation for Windows console - Initial Version Review Since the changes this small project of mine suffered after applying all the excellent ...
4
votes
1answer
64 views

Non-recursive version of Trie deletion [closed]

So,I was looking for the non-recursive version of Trie data structures deletion in the internet. I couldn't find one. The best I could manage to find was a recursive implementation of trie in this ...
6
votes
1answer
131 views

OOP demonstration in C++17 using a Pokémon

I want to showcase with as minimal code as possible the basic Object-oriented programming (OOP) principles of Polymorphism, Inheritance, and Encapsulation. I know there are many more principles than ...
-1
votes
1answer
58 views

Determine if matrix exists or not [closed]

any help with optimizing following code to make it run faster. Tried making function inline, tried cin.TIE(NULL), tried ios_base::sync_with_stdio(false); ...
9
votes
3answers
81 views

Console Blackjack game, without split or betting system for now

I never programmed in my life, and I am currently self teaching myself some C++ by reading books, online free classes and googling. After beginning to read about OOP and classes, and after seeing that ...
4
votes
0answers
34 views

Generalizing std::shared_ptr for all handle-types, even non-pointers

I created this shared pointer mainly to use it as RAII for handles that have to be shared between classes or threads. For pointers: It supports raw pointers and pointer to classes and arrays and also ...
1
vote
1answer
42 views

AVL tree implementation using shared_ptr/unique_ptr

I have implemented an AVL tree using shared_ptr. I know that there is an overhead regarding using shared_ptr and instead a unique_ptr could be used. But the thing is that my node contains also a ...
2
votes
0answers
65 views

Coding Challenge Solution - Find Number of Elements in a range in \$O(1)\$ with preprocessing

Overview This is my solution to the following Coding Challenge - Find Num of Elements in a Range in \$O(1)\$ with Preprocessing - Given an array and max element in the array, find the number of ...
5
votes
1answer
155 views

C++ Implementation of Linked List

I have been trying to teach myself C++ recently and would like to have some general feedback and comments on how to improve my code so far. Furthermore, since I am more experienced with other (garbage-...
5
votes
2answers
278 views

Coding Challenge Solution - Good Range

This my solution to this Good Range Coding Challenge There is a number space given from 1 to N. And there are M queries followed by that. In each query, we were given a number between 1 to N (both ...