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
votes
0answers
11 views

Boolean expression order [on hold]

I have a simple question about how I should be ordering the elements in a boolean expression. Imagine I have an equality operation, should the expected value be in front or the actual value? ...
8
votes
1answer
256 views

Detecting existence of a class member

I wanted to detect if I have a member in a simple POD struct and after some searching and merging some methods I found on the web I've come up with this solution: ...
2
votes
1answer
67 views

generic flyweighting function

I made this little function for flyweighting any type that has operator<. I followed the convention of make_unique and ...
-1
votes
0answers
26 views

Return as refernce or Return void , which particise is better? [on hold]

void func1(std::string& input , std::string& output) std::string& func2(std::string& input) { return output; } Which approach is good ...
1
vote
0answers
14 views

Implementing a thread pool for task execution

I wanted to experiment with a reusable thread pool that allows to add tasks and execute them repetitively. After going through, https://github.com/progschj/ThreadPool and another Stack Overflow post ...
6
votes
1answer
40 views

Basic Reinforcement learning in a grid environment

I am implementing the Bellman equation for utilities, in a grid environment as follow. It is an example on Chapter 17 of Artificial Intelligence: A Modern Approach 3rd Edition. There are some math ...
4
votes
0answers
56 views

Type & Thread-safe Logger Implementation

So I had previously posted this question and asked for some feedback regarding my (now) header-only logging system and figured it would be a good time to go back to the changes I made it and see if it ...
1
vote
0answers
46 views

Managing millions of objects in a MMO game server [on hold]

A litle context: This game server is coded entirely on C-with-classes (plain C code using basic C++ features like classes, templates and such, to avoid any possible overhead). At startup the server ...
-2
votes
0answers
26 views

Making a function for a tie game in Tic Tac Toe [on hold]

I am making a tic tac toe game, and so far there is complete functionality except for a tie game instance. The program doesnt end when there isnt a winner. I am not sure how to approach this, maybe I ...
5
votes
0answers
58 views

A straightforward method for computing the Binomial probability mass function

I've been writing up code to test an alternate way of calculating the Binomial probability mass function. The Binomial random variable is the number of heads out of N coin tosses with coins that have ...
1
vote
1answer
56 views

A minimalistic kind of read-copy-update class

This is a very simple read-copy-update (RCU)-inspired synchronization class: ...
7
votes
1answer
131 views

alternative to std::vector<std::function<…>> which uses tail recursion

An alternative to std::vector<std::function< >> which uses tail recursion to optimize calling the functions sequentially. I'm using this on a real-time ...
10
votes
6answers
4k views

Animal Shelter Management C++

I am working my way through "Cracking the Coding Interview" and I came up the question(3.6) to design a data structure to manage an Animal shelter with 2 animals, Cats, and Dogs such that when we ...
1
vote
1answer
58 views

Boolean class using shared referenced memory

To improve my knowledge I am trying to make a bool class from scratch, or derivative of. I am using MinGW g++11 compiler on a Windows 7 laptop. ...
2
votes
3answers
121 views

Modeling, view and projection transformation using vector and point in homogenous form

I know this is horrible code. This program is for performing modeling, view and projection transformation. The program reads input from scene.txt and outputs the <...
5
votes
4answers
204 views

Reverse the word order in string, without reversing the words

I was tasked with using C++ to turn this "Hello Jarryd, do you like socks?" into: "socks? like you do Jarryd, Hello"; Edit: The condition was to reverse this in place. Here's what I came up with, ...
2
votes
1answer
56 views

Simple Console Maze Game

I am fairly new to C++ and programmed a maze game as an exercise. However, looking at it I can see it can be improved a lot. These are my requests if you don't mind: I do not want to use the library <...
2
votes
1answer
37 views

Prime number sieve using ranges::view::ints

I wrote a simple prime number generator in C++17. The function generate_primes(max) generates all prime numbers up to max. I ...
3
votes
0answers
32 views

SHA256 directory hash

I'm pretty new and I posted on SO earlier because I wanted to make sure my code was right and all that and I got redirected here. So I have this code that I put together (using Example C Program: ...
2
votes
1answer
32 views

Qt / C++/ Warehouse Club Management System

I am building a primitive Store Management System based on Qt and would appreciate some feedback. Classes: ManagementSystem - the logic unit of the system ...
-5
votes
0answers
29 views

How to set up a file pointer that pointing to the file inside of a file in C# [closed]

What I mean is there is a collection.txt file and inside of this file there are some other files. Now I have already open the collection.txt file and I want to set a pointer which can point to each of ...
1
vote
3answers
67 views

Optimizing primes generating program in C++

I am writing a program to generate primes in range 1 upto 10^9 but it seems to be timing out. It implements the Sieve of Atkin I have tried optimizing my code using bitsets and pragmas. Please are ...
1
vote
0answers
25 views

shared_ptr alternative with no dependencies

An alternative to shared_ptr to minimize compile time. Intrusive. Reference count changes are not thread safe. (...
-3
votes
0answers
43 views

What are the key issues with this implementation of generating nth term of a fibonacci sequence? [closed]

This function generates the nth fibonacci number. An exam recently asked me this question: What are some issues of this implementation (Asks for 4 issues!) I'm thinking maybe a potential issue is ...
3
votes
2answers
53 views

A polymorphic union in C++

Sometimes I use std::unique_ptr<BaseClass> when all I really want is polymorphism. For fun, I made this container that skips the heap allocation. The ...
4
votes
3answers
84 views

Functional CSV Parser

I've been starting to migrate some C++ code from imperative to more of a functional style. I'm new to functional programming so I'm trying to get a sense of how well this code fits into the functional ...
3
votes
1answer
57 views

std::function alternative with no dependencies

An alternative to std::function for when compile time is more important than runtime performance. Doesn't pull in any headers. (...
4
votes
1answer
95 views

STL-like vector implemention in C++

I attempt to write a STL-like vector, mostly to figure out how it works. I wonder which parts look weird or what I made stupid. Any kind of comment is appreciated: alloc.hpp ...
2
votes
2answers
50 views

“When to take medicine” CodeChef Challenge MEDIC

I just submitted this code to solve the "When to take medicine" challenge on CodeChef: ...
4
votes
0answers
45 views

C++ simple inter-process notification system

I needed to synchronise several processes, so I developed this ipn::Notifier class that uses a mutex+condition variable stored in shared memory to notify all ...
2
votes
2answers
120 views

Tetris game for Windows improved version

About a month ago I made a Tetris game for Windows. After a helpful review, I improved the code. I want to hear again an opinion about the implementation, how readable the code is, new mistakes or ...
6
votes
2answers
107 views

String manipulation with std::adjacent_find

For the given strings (not containing numbers), print their shortened versions, where each adjacent sequence of the same characters longer than 2, change to an expression consisting of a sign and ...
4
votes
2answers
86 views

Min Heap implementation [C++]

I've never had my C++ code reviewed before so I'd appreciate any feedback. Although my main focus was not on the implementation of the algorithm itself, any suggestions regarding improving it would be ...
4
votes
3answers
2k views

Palindrome test

This is some code that determines if a string of characters is a palindrome or not. My professor says that there is a performance issue with the program, but I can't quite put my finger on it. Can ...
3
votes
3answers
85 views

Fast-resizing uint8 buffer

I wanted a buffer like std::vector<uint8_t> which is very fast at resizing, and it does not require byte initialization (it resizes to 16K, then to 2-4 bytes, ...
-4
votes
1answer
54 views

Is it a proper implementation strategy pattern? what's better to use enum or define? [closed]

The idea is that when we want to create an object of some type, we will only use a robotcreator and enum from the interface. the goal is to decides what type of robot to use internally, based on a ...
4
votes
2answers
105 views

Determining the maximum value that can be obtained from a loot

A thief finds much more loot than his bag can fit. We have to find the most valuable combination of items assuming that any fraction of a loot item can be put into his bag. For example has a bag ...
1
vote
1answer
51 views

Inventory system codebase

I'm here looking for a review over my current code-base. Please: Ignore using namespace std; this is for educational purposes mostly so the usage of using namespace std; does not matter for this ...
2
votes
1answer
61 views

A heap-allocated texture class for a console renderer

I am working on a console renderer and I want a heap-allocated dynamic texture class. Since I am quite new to C++, I just want to check the memory management, if I destroy all pointers correctly etc. ...
1
vote
1answer
40 views

Moving an element from one unordered_map to another

This code moves one element from one unordered_map to another. I would like to ask if my code below can be improved. ...
3
votes
2answers
46 views

Finding paths between triangles efficiently in 3D geometry #2

This post is an update of the one from here. I've updated the code and a couple pieces of the post itself. I've been writing some functions used to find paths between two types of triangles - alphas ...
3
votes
1answer
69 views

Pre-calculate the winning combinations for an n-sized tic tac toe board using C++ functional programming

This code pre-calculates the winning combinations for an n-sized tic tac toe board. I first created my function using an imperative approach. This is just how I naturally write code most of the time....
5
votes
0answers
33 views

Interfaces and OOP Design for Image Editor software

I'm new to C++ programming, and I'm building an Image Editor software like Lightroom/CameraRaw from scratch. Apart from procedural code (actually seems that all the functions works correctly) my goal ...
0
votes
0answers
46 views

Helper to convert arbitrary function into a custom deleter

If you want to use a custom deleter in unique_ptr you either have to pass a functor or the signature of a delete function as template argument. If you have a ...
0
votes
1answer
75 views

Simple “Connect 4” game

I made this easy game to improve my C++. The functions like NoFlicker and ShowCursor are copied from the Internet, but I made <...
1
vote
0answers
43 views

C++ - simulating Windows' IO completion ports in Linux

This is a simple implementation of IO completion ports in user mode for Linux. In Windows IO completion ports work like this: There is a global queue for issuing IO requests. Some worker kernel ...
3
votes
3answers
104 views

Finding paths between triangles efficiently in 3D geometry

An update to this post can be found here I've been writing some functions used to find paths between two types of triangles - alphas and betas. Alphas are triangles that have been in a zone we ...
4
votes
3answers
77 views

Encapsulating snprintf to simplify usage: sbprintf & swnprintf

After writing swnprintfand sbprintf in C (Encapsulating snprintf to avoid repetition of sizeof), I've written a C++ version of ...
5
votes
1answer
63 views

Finding sum of divisors of numbers between the range (1 to 1e16)

The exact link to the question : https://www.spoj.com/problems/DIVSUM2/ Input: An integer stating the number of test cases (equal to 500), and that many lines follow, each containing one integer ...
3
votes
1answer
50 views

Implementing PLC “Timer Pulse” function block in C++

I have been implementing a library of the PLC function blocks. One of the function blocks is the "Timer Pulse" function block which behavior is following: I have implemented this function block in ...