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)

8
votes
5answers
393 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). ...
8
votes
2answers
56 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
62 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 ...
2
votes
1answer
21 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
415 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
41 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
70 views
7
votes
2answers
86 views

Better option than “errno” for file IO error handling

I have the following method for opening a file: ...
8
votes
3answers
92 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
90 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
50 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
93 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
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
3answers
303 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
0answers
71 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
49 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
196 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
102 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
87 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
52 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
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
1answer
83 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
126 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
260 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
561 views

Classes for sentence-like readability

If we have a set of classes or structs such as: ...
2
votes
1answer
46 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
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 ...
4
votes
1answer
59 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
39 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
246 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 ...
9
votes
1answer
146 views

Did I implement my string formatting code correctly?

As a small exercise I have written some string formatting and printing functions in C++11. I would like a bit of code review, not so much on the merits of using this over something like ...
6
votes
2answers
79 views

Time Limit Exceeded with Segment Tree data structure

I am trying to solve this problem Chef Ceil has some matchsticks in his kitchen. Detail of matchsticks: There are N matchsticks in total. They are numbered from to 0 to N-1 inclusive. ...
5
votes
3answers
132 views

Linked list with iterators

This is my second linked list implementation for review. I rewritten pretty much all of this and have added iterators, sentinels and The Rule of Five. Please let me know what's wrong with it; I am ...
5
votes
3answers
136 views

Reading and writing binary data in C++

I have written a small container class which groups a 3D position, a normal vector and a texture coordinate into one object. It uses the glm library for the actual data types (vec2 and vec3). This ...
14
votes
2answers
235 views

Sudoku solver in C++

Some time ago, this question was posed, asking for help in optimizing a Sudoku solver implemented in C++. I decided to reimplement the code using C++11, but without guessing. That is, this Sudoku ...
11
votes
3answers
546 views

Linked list implementation correctness

I've started learning C++ and I wanted to ask you to take a look at my linked list implementation and give comments what's wrong with. It compiles and runs fine, but I am curious about const ...
4
votes
0answers
96 views

Is this pass-by-reference of a shared_ptr correct?

I'm writing a scene graph library in C++ and I'm currently designing the parent-child relations. I decided to use shared pointers for parent-to-child-relations and weak pointers for child-to-parent ...
5
votes
1answer
56 views

Generic Graph Library Part 2 : Algorithms

(This is a follow on to this question). Having given an implementation for some of the graph structures, here is a portion of the algorithms that are defined to work over them: graph_degree.hpp ...
9
votes
1answer
83 views

Generic Graph Library

I've been working on a generic graph library for a while now, in a bit of an off and on fashion. I realise that boost::graph exists, but it is a complex library ...
4
votes
2answers
241 views

Creating a cache manager

I am purely new to C++ memory management. Am I on the right path, or should I employ a different design strategy or a different memory manager policy (such as ...
5
votes
0answers
95 views

String matching algorithm

I have been going through algorithms and data structures and recently came across string matching algorithms. I have not yet wrapped my head around the significance KMP algorithm so I came up with ...
8
votes
2answers
169 views

C++(11/14) intercalate implementation

I wrote a simple generic intercalate function (that should be semantically equivalent to the Haskell intercalate). ...
3
votes
2answers
210 views

Function for splitting an integer into smaller values

This is the function I've implemented in an answer to this question. I've tried to make this as simple and idiomatic as possible, using C++11. Could this still be improved in any way? ...
10
votes
3answers
138 views

Code for sums in a vector

I posted this code in an answer earlier today, but thought it was worth seeing if somebody could suggest further improvements: ...
8
votes
2answers
56 views

Using inputted data from vector to create two outputs

I'm trying to figure out a way to do the exercise 3.20 in the C++ primer book I have to create a program that reads input into a vector then use that data to create 2 outputs: one is the sum of ...
3
votes
2answers
88 views

Memoization helper

Please review: ...
5
votes
1answer
190 views

Polymorphic (owned) reference wrapper for class hierarchies

Rationale: I often have the requirement to own object instances, while preserving polymorphic behavior (i.e. own the object and hold it by pointer, or reference). This is usually expressed as a ...
3
votes
2answers
376 views

Prevent re-entrant function call in C++

The purpose of this is to prevent a re-entrant function call in a single thread, e.g. prevent the situation where func() calls ...
5
votes
2answers
82 views

Using includes() vs. hash function to check if an unordered_set is a subset of another unordered_set

I did two methods to determine if an unordered_set is a subset of another unordered_set, using hashing, and the built-in ...
2
votes
1answer
73 views

Is this a meaningful Intrusive Pointer Class?

Is this intrusive pointer implementation correct? I tried to use the CRTP Pattern to avoid a virtual destructor in my class ReferenceCounting which provides the ...