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

learn more… | top users | synonyms

-1
votes
0answers
18 views

Cache with a Mutable? [on hold]

I'm wondering if I can get an opinion on this paradigm. It seems functional but the mutable feels redundant. ...
0
votes
1answer
37 views

Multiple assignment operations in one statement [on hold]

As I was writing a pretty straightforward loop to map the boundaries of a box, I found that I was doing this a lot: ...
3
votes
3answers
103 views

Another permutator

This is a solution to this problem. The problem statement: write a program to display all possible permutations of a given input string--if the string contains duplicate characters, you may have ...
-3
votes
0answers
17 views

Linked List pointer [on hold]

I know this is a simple doubt but can anyone explain me how does this line works? Node* newNode = new Node();
-2
votes
0answers
43 views

what are the possible problems in the code ? [on hold]

I was asked in an interview test to highlight the problems to rewrite the new code given below. need comments and suggestions. ...
10
votes
2answers
148 views

Function wrapper like std::function that uses “small buffer” allocation

My Function class is similar to std::function with the small-buffer optimization. However, it always uses a small buffer and ...
4
votes
4answers
502 views

Temperature conversion table

This is another solution for this challenge. Problem statement: In this challenge, write a program that takes in three arguments, a start temperature (in Celsius), an end temperature (in ...
6
votes
1answer
49 views

C++ Wrapper for SAFEARRAY

Here is a C++ wrapper for SAFEARRAY, including the ability to expose it as a VARIANT, and to create one out of VARIANT. I am aware of CComSafeArray, however i don't use VC++ so I do not have ...
4
votes
0answers
61 views

Testing a lock-free job queue

I've created a lock-free job queue and with the tests I've written, which is also very fast. That makes me doubt my benchmark procedure, so I'm hoping the collective knowledge will shed some light on ...
5
votes
2answers
81 views

Binomial coefficient

I wrote a C++ function to calculate the binomial coefficient, trying to avoid overflows as much as possible. ...
12
votes
6answers
827 views

Using a static variable inside a lambda

Is using a static variable in a lambda function ok, or considered a bad practice? The code below works as intended (fills a vector with consecutive numbers). ...
10
votes
2answers
104 views

String concatenation utility in C++11

I published a concatenation utility lastly and I feel it could be very good help for many people, but before I promote it, I would like to polish the details as much as I can. So I'll like to ask you ...
-1
votes
0answers
18 views

Red Book (8th edition) Fur Example, not rendering fur (Linux/Nvidia 340.24/GTX675MX) [closed]

I trying to get the Red Book (8th edition) chapter 10 Fur example to work on my Ubuntu 14.04 laptop with Nvidia GTX675MX I've changed the code to use SDL2 and glm but everything else is as it is in ...
5
votes
2answers
100 views

Singleton Typed Memory Manager

For my resources management, I wanted the objects allocated on the heap to be in a contiguous block of memory. Obviously, each data type then has to have their own chunk of memory. I could have used a ...
3
votes
1answer
25 views

Wrapping std::bind call in a function returning std::function

Is this code correct? It appears to work in g++ 4.8.3 and clang (bcc64), however appearing to work is no guarantee of correctness :) The aim is to be able to replace a call to a member function: ...
10
votes
5answers
434 views

Stopwatch template

It's often useful to be able to time code, for instance, to evaluate alternative approaches to the same problem. Because this is a thing I use frequently, I have created this Stopwatch templated ...
0
votes
1answer
44 views

Bignum library with arbitrary bases

I just started development on a new bignum library that can operate on numbers of any arbitrary base (up to 232). I want to get a good idea of where I can improve before taking things any further. ...
-3
votes
1answer
82 views
6
votes
1answer
49 views

Predictive recursive descent parser for math expressions

I've been learning about language theory and parsing, and decided to write my first parser: a LL(1) recursive descent parser. But actually, it does a little more than just expressions; it can also ...
7
votes
3answers
226 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: ...
5
votes
4answers
72 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 ...
7
votes
2answers
91 views

Better option than “errno” for file IO error handling

I have the following method for opening a file: ...
-1
votes
0answers
10 views

LL1 Parsing Table Output Not Showing [closed]

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 ...
8
votes
4answers
170 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
53 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
94 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
95 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
59 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
119 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
53 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
95 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
254 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
121 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
55 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
306 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 ...
10
votes
1answer
87 views

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 ...
1
vote
1answer
40 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 ...
6
votes
0answers
72 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
137 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
284 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
96 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 ...
7
votes
1answer
213 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
52 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
197 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
79 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
108 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
92 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
53 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
50 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. ...