C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language.

learn more… | top users | synonyms

2
votes
1answer
24 views

index into array as if it is circular

The problem: Treat an array as if it is circular; out-of-bounds indices "wrap around" the array to become in-bounds. Current solution: ...
2
votes
1answer
23 views

Optimizing nested loop in run length encoding function

I'm currently working on a tool that needs to decode, modify data, then re-encode that data using the Yaz0 format. Everything has been in a working state, but after running some code analysis on my ...
3
votes
0answers
28 views

Better option than “errno” for file IO error handling

I have the following method for opening a file: ...
0
votes
0answers
7 views

LL1 Parsing Table Output Not Showing [on hold]

I tried my best what I can do to show this output table, but having hard time showing it. the code runs fine but when i try to enter the following output of table for validation, a lot of errors ...
5
votes
3answers
130 views

Adding two sides of an array

The purpose of the program is to add 2 sides of an array starting from the bottom and top of both ends and to find the lowest difference at equal decrements of iteration. The program functions but ...
3
votes
0answers
41 views

Multi-user server connection handling

I'm writing a program and I have a server that needs to be able to handle multiple client connections at once doing many different things. I'm using the Qt library, so I handle new connections like ...
8
votes
3answers
85 views

Check if bit is only set once in a vector of int

I have a vector of uint16_t and I want to check if there is a bit which is only set in one vector. I then get its position within the vector as well as from the ...
5
votes
1answer
81 views

Iterable enum class in C++11

For a small project I'm working on, I've been looking for an iterable enum-like class in C++, since neither C-style nor scoped ...
2
votes
2answers
52 views

Generate the Norwegian equivalent to social security numbers - follow-up

First of, here is my previous post. That should explain a fair bit. The reason I'm posting one more time, is I have changed a lot. Using more classes, let them do all the work, and the overall ...
6
votes
3answers
115 views

Pattern tokenization program

I am writing this program to try and get some practice at C++ and correct and proper styling. This code is meant to take user input from a pip and then run it through the program. The user enters a ...
3
votes
1answer
48 views

Perfect-forwarding while implementing emplace

I am trying to write a class similar to std::set, and I was wondering if I handled the perfect forwarding right in implementing the ...
5
votes
3answers
89 views

Simplifying logic of overlapping predicates

I have 3 simple predicates and 3 simple actions to be taken based on those predicates. In my actual application they are not based on integer arithmetic, and in fact are rather expensive to compute ...
6
votes
4answers
241 views

Counting the number of words in a string

I have written this program to count the number of words in a string. I have checked my program for the worst-case scenario. If any of you can find any cases for which this program doesn't work, ...
6
votes
2answers
112 views

Infix to postfix conversion

I have written a C++ program to convert an infix expression to postfix expression using recursion. I would like to know if it can be improved if possible. Can we improve it by not using a stack? I am ...
8
votes
3answers
55 views

Validation/error handling of user input values

This is a tiny learning program that lead to an interesting question: how can I best/most elegantly handle user entered numbers? This method works, fails cleanly, and reads well. It doesn't apply to ...
10
votes
2answers
52 views

Citadel's VisualEncrypt and VisualDecrypt

I was skimming through this paper out of boredom. On pages 5 and 6, the paper shows a simple encryption/decryption scheme that Citadel uses to obfuscate data. The algorithm basically XORs the next ...
10
votes
3answers
297 views

Implementation of binary min-heap data structure

What do you think is wrong with this code, and how can it be improved? What corner case have I overlooked, if any? Note: I do not want to use any STL features here, but I'm okay with anything else ...
7
votes
0answers
45 views
+50

Custom iterator implementation returning OpenCV Mat

I have written an adapter class that allows iteration over the rows of a Mat object from OpenCV. For those interested, here is the Mat documentation, but the ...
0
votes
0answers
20 views

Spoj Prime Generator WA [closed]

Problem Statement I've been trying to implement my own Segmented Sieve in C++ . But I am unable to get a AC in this problem. The only thing I'm doing its using a binarysearch algorithm to find the ...
1
vote
1answer
38 views

A class for simple and efficient operations on boost::unordered_set

I wrote this class to perform simple template-set operations on boost::unordered_set. These operations are part of a larger code base. Calling them will be explicit ...
5
votes
0answers
63 views

Interface-based polymorphic collection

Here is a small C++11 utility collection to store any object that satisfies a given interface. Only the basic concepts are provided, I did not try to create a full collection: ...
4
votes
3answers
136 views

Modified Sieve of Eratosthenes has very long runtime

I am slowly moving through Project Euler, and have reached problem #10: The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all the primes below two million. I did a naive ...
9
votes
2answers
279 views

Four-function expression evaluator

I've been making an interpreter for my own programming language that I've been working on as a hobby. I made an expression evaluator that can evaluate simple mathematical expressions. It understands ...
3
votes
0answers
77 views

Game Engine :: Entity Component Design - Handling Input

I am currently creating a game engine for educational purposes. ECS Design Pattern The first design pattern I've included is the Entity/Component/System pattern. Therefore I've got a base singleton ...
5
votes
0answers
190 views

Portable C++ boost::iterprocess::mutex

I was looking for long time around to have a portable robust solution for multiprocessing synchronization. Who touche this things know that good solution are boost::iterprocess named sync objects. ...
4
votes
1answer
48 views

Better way to un-define a set of defines based on version numbers in C++?

In a header I have something like: ...
6
votes
3answers
194 views

Inner product of random floats written to file

My goals are to make this code: faster more idiomatic C++ What the code does: take an integer command-line argument N make a vector of ...
3
votes
3answers
75 views

Looping over files in C++ and changing their names to store data into a single file

I have a lot of data in separate files generated from a simulation program. All data is clear and formatted via a single space to read in 4 columns. I can open and store data from each file one at a ...
11
votes
2answers
96 views

Encapsulated text-based RPG using a randomized combat system

For my rags-to-riches submission, I've decided to improve this code: Text-based RPG game using classes However, I've decided to start off with something different. The original code is more ...
5
votes
1answer
85 views

Simple parsing for string formatting (version 2)

This is my second attempt (version 1) at writing a string formatting utility which uses parsing. This time I more explicitly designed it as a finite state machine. I have very little experience with ...
3
votes
0answers
49 views

Debug log wrapper

Please review code correctness, best practices, design and code formatting. I will be adding functionality and most likely additional refactoring, however a stringent review would be welcome before I ...
2
votes
2answers
45 views

Getting correct English grammar

Does someone know of a better way to get proper grammar in sentences than this method of mine? I don't want to continue with this for my entire huge program if there is a much more elegant way. ...
2
votes
0answers
16 views

How can I expand this C++11 event system to handle multiple arguments? [migrated]

I've written a simple subscriber event system taking advantage of std::function. It works great! (and I can do some big enhancements later with thread-pooling for ...
4
votes
2answers
198 views

Factory design pattern example in C++

I found a definition of the factory design pattern as: "Define an interface for creating an object, but let the subclasses decide which class to instantiate." I understood the first part "defining ...
4
votes
1answer
81 views

Simple parsing for string formatting

Recently I submitted some string formatting and printing code (found here) that I wrote as an small exercise. It was implemented naively using string replacement. This time around I wanted to actually ...
7
votes
3answers
120 views

Enterprise FizzBuzz in C++11

I've decided to write a C++ FizzBuzz with the focus on some new C++11 features, ridiculous optimizations and unit-testability. Are there improvement possibilities in those regards? ...
12
votes
1answer
259 views

Yet another FizzBuzz

Since today is apparently a good day for...unlikely FizzBuzz implementations, I decided to contribute another, this one in C++: ...
5
votes
2answers
57 views

Scoring matches of a game - reducing duplicated code

I'm writing a small application to score matches of a game. (There are two "teams" on each "alliance", and two alliances play each other in a match.) I have a "logic" class that handles the values of ...
13
votes
6answers
561 views

Classes for sentence-like readability

If we have a set of classes or structs such as: ...
6
votes
1answer
104 views

Creating C++ classes and objects

I'm brand new to programming (in general) and C++ (in particular). I'm learning the basics of classes and objects. I'm trying to do the following: Create a class called ...
10
votes
1answer
138 views

Kahan summation

Inspired by another question, I decided to implement Kahan summation in C++ (though that question implemented a different summation algorithm). Since I was writing C++, I decided to make the code ...
2
votes
1answer
44 views

Best way of assigning an array of different (but convertible) type to concurrency::array in C++AMP

I am creating a vector class which can be manipulated on the GPU and I am using C++AMP for the GPU accelerated code. I am wondering the most efficient way of assigning elements of a different type ...
4
votes
2answers
76 views

Implementing write sphere of values to 3D array

The code below is sort of complicated to explain... It writes a "sphere" of data to a 3D array from the given 3D-Position outwards in a spherical shape based on the given radius and value to write. A ...
1
vote
1answer
51 views

Will this act like a ThreadPool? [closed]

I know that until the n threads will not complete their jobs, the new jobs will not be assigned, but will this code be thread-safe and execute ...
6
votes
5answers
170 views

Casting base to derived class according to a type flag

I have been writing an event class for my game engine and I came across to the following problem: Is casting a base class object to a derived class object given a type flag a good programming design? ...
4
votes
1answer
57 views

Builder/named argument/fluent interface pattern with unique_ptr

I'm trying to figure out the cleanest way to implement a fluent interface with unique_ptr and other "modern" C++ language constructs. Here's my first attempt: ...
9
votes
3answers
358 views

How many semi magic squares are there?

I want to write a program to work out how many semi-magic squares there are. Here is the definition of semi-magic squares If we define \$H_n(t)\$ is the number of semi magic squares which ...
2
votes
1answer
37 views

PPL and AMP performing worse than sequential transform

I wrote the following short test code to test the performance of C++AMP and the PPL libraries against the sequential STL implementation of std::transform. To my ...
6
votes
2answers
243 views

Binary Search Tree implementation using templates

I wrote this implementation using templates. It works fine and as expected. Just want to know if this can be improved. I have some specific questions too at the end. Please feel free to critique to ...
4
votes
2answers
105 views

Optimizing object-returning functions in a Contours class [closed]

I have an class Contours that contains a vector of contours. I use OpenCV to store the contours, and I have another class ...