C++11 is the successor to the C++03 standard, adding various core language changes and fixes, and an improved and expanded standard library.

learn more… | top users | synonyms (1)

4
votes
2answers
51 views

begin() vs rbegin(): how can I avoid duplication?

Can the display function be re-written to avoid duplication of the std::for_each loop? ...
-1
votes
1answer
38 views

Multithreading - program with lots of parallel routines (C++) [on hold]

I'm coding a networking software, which has lots of functions (modules) which can be run in parallel. They share some resouces, like libnet_contexts of every type, ...
2
votes
2answers
97 views

STL List Implementation

I've implemented a simple C++ STL like list. It's pretty simple, all the constructors and methods haven't been implemented here, but majors are. ...
6
votes
3answers
326 views

Clean Code attempt of HOLES problem on codechef.com

The problem asks you to take read an integer (number of words to read) and then process words entered counting the number of "HOLES" exist. Letters with HOLES are ...
3
votes
2answers
36 views

Value Iteration Implementation for MDPs

I've been working for a while on a decision theory library, and since I've never really had any formal training in code best practices I'd love to hear your feedback. This particular class is one of ...
3
votes
2answers
64 views

Emulating __uint128_t

I developed a lot of code locally with __uint128_t only to find out that it is not available on the target platform. I am now trying to write my own struct that ...
6
votes
3answers
547 views

STL Queue Implementation

I've implemented a simple C++ STL like queue. (I've tried to follow @LokiAstari stack implementation code fashion) ...
1
vote
2answers
102 views

Binary search as a generic algorithm

I am upgrading my C++11 knowledge and repeating some essential algorithm. Here is binary search only in terms of iterators. ...
10
votes
2answers
90 views

Parsing of a (Linux) netlink hotplug uevent packet

The netlink service is used, among other things, to notify userspace about hotplug events (e.g. "a device has been connected"). These events come in the form of packets, which follow the following ...
10
votes
3answers
593 views

Clean code attempt at ATM problem on codechef.com

The problem asks you to take an integer (debit amount) and a double (credit or initial balance amount) and process the requested debit verifying that 1 it's a multiple of the minimum denomimation ...
13
votes
2answers
135 views

Thread pool worker implementation

As an exercise in using C++11 features I decided to make a thread pool class. I would like to have a review on the code with focus on: Standards compliance / Portability issues / Best practices ...
5
votes
3answers
174 views

Determine whether one vector is a prefix of the other

Exercise 5.17: Given two vectors of ints, write a program to determine whether one vector is a prefix of the other. For vectors of unequal length, ...
2
votes
0answers
50 views

CRTP object counter to track accidental singleton instantiation

I have used CRTP to implement an object counter for singleton classes. This way I can keep track of accidental attempts to instantiate more than one object. It is a header only class: ...
4
votes
2answers
134 views

Game framework using C++

I'm writing my own game framework and would like to get feedback on the API while I'm writing it. At the moment it's very simple, but I would like some guidance about where to take it. This is a ...
19
votes
5answers
2k views

Aliens at the train

I solved this problem on SPOJ: The aliens have arrived to Earth and everything is in harmony, the two races can live together. However, one specific Female Alien does not want to see humans ...
3
votes
2answers
196 views

Checking whether a given timestamp is more than two weeks old

I am trying to see whether a given timestamp is more than two weeks old or not. If it is two weeks old, then print out "Hello" and if it is not more than two weeks old then print out "World". I have ...
12
votes
2answers
383 views

Efficiency/design of trim() library code

I am working on some library code and I am trying to optimize my trim() functions. To that effect I am trying to figure out how best to deal with each kind of ...
6
votes
2answers
114 views

Layer Stack class to practice std::shared_ptr

The following three source files is to define and test a class StackLayer. While it was written in a need for scalable layer-based architecture design, it was also ...
2
votes
1answer
41 views

Parallel Reduction method with C++AMP

I am writing a C++AMP library, and as one of my utility methods I am implementing a parallel reduction algorithm based on the cascade method documented on this blog post with slight improvements by ...
4
votes
3answers
115 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 ...
11
votes
2answers
191 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
0answers
103 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 ...
12
votes
6answers
863 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
135 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 ...
5
votes
2answers
117 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
43 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: ...
11
votes
5answers
453 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
58 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. ...
-2
votes
1answer
97 views
7
votes
2answers
107 views

Better option than “errno” for file IO error handling

I have the following method for opening a file: ...
8
votes
3answers
99 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
118 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 ...
3
votes
1answer
63 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
103 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 ...
8
votes
3answers
66 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
3answers
319 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 ...
6
votes
2answers
110 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
1answer
55 views

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

In a header I have something like: ...
6
votes
3answers
204 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 ...
11
votes
2answers
118 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
111 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
68 views

Debug log wrapper

I will be adding functionality and most likely additional refactoring, however a stringent review would be welcome before I build it further. I know documentation is probably a bit sparse but, you ...
4
votes
1answer
95 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
141 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? ...
13
votes
1answer
277 views

Yet another FizzBuzz

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

Classes for sentence-like readability

If we have a set of classes or structs such as: ...
2
votes
1answer
55 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 ...
1
vote
1answer
54 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 ...
4
votes
1answer
78 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: ...
2
votes
1answer
50 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 ...