Questions tagged [c++11]

Code that is written to the 2011 version of the C++ standard, sometimes known by its pre-publication name of "C++0x". Use in conjunction with the 'c++' tag.

Filter by
Sorted by
Tagged with
71 votes
6 answers
3k views

infix_iterator code

I've previously posted this on Stack Overflow, and am considering submitting it to Boost for wider distribution, but thought perhaps it would be best to put it up here for peer review first, and see ...
Jerry Coffin's user avatar
  • 33.5k
56 votes
4 answers
34k views

Seed std::mt19937 from std::random_device

Many people seed their Mersenne Twister engines like this: std::mt19937 rng(std::random_device{}()); However, this only provides a single ...
Baum mit Augen's user avatar
54 votes
6 answers
41k views

Simple integer range for C++11 range-based for loops

I'm really tired of having to type for (int iSomething = rangeBegin; iSomething < rangeEnd; ++iSomething) { ... } whenever I want to iterate over an ...
isarandi's user avatar
  • 787
54 votes
2 answers
4k views

Named operators in C++

A post by Yakk alerted me to the idea of named operators in C++. This look splendid (albeit very unorthodox). For instance, the following code can be made to compile trivially: ...
Konrad Rudolph's user avatar
51 votes
3 answers
24k views

shared_ptr and FILE for wrapping cstdio (update: also dlfcn.h)

Even in the presence of <fstream>, there may be reason for using the <cstdio> file interface. I was wondering if ...
Kerrek SB's user avatar
  • 1,193
43 votes
5 answers
7k views

Parallel sieve of Eratosthenes

For the first time, I tried to use threads by myself in order to implement a parallel sieve of Eratosthenes. The trick is that each time a prime is found, a thread is spawned to eliminate all the ...
Morwenn's user avatar
  • 19.9k
34 votes
2 answers
68k views

A multi-threaded Producer Consumer with C++11

I am trying to learn concurrent programming in C++11. I tried to write code for a classic producer consumer concurrency problem. Would you please review and make any comments about it? ...
Robomatt's user avatar
  • 391
32 votes
6 answers
3k 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 on ...
Nitin Labhishetty's user avatar
32 votes
2 answers
7k views

Lexer+Parser code for my "Reedoo" programming language

I've been working on my own programming language, as a hobby for the past couple of months now, called Reedoo. It is implemented in pure C++ 11 and uses only the libraries that come with C++; no ...
Francis's user avatar
  • 547
31 votes
2 answers
1k views

Dynamically call lambda based on stream input

Some context: I have code that looks like this (minor issue noted here): ...
Martin York's user avatar
  • 94.3k
31 votes
3 answers
28k views

Quadtree implementation

I've implemented a quadtree in C++. Ignore any apparent similarity to the pseudocode on Wikipedia, it's all in your head, I swear. How can I improve it? Algorithm speed/space improvements, any extra ...
Yann's user avatar
  • 2,226
31 votes
1 answer
3k views

Yet another 'any' class implementation, named 'some'

This is a follow-up of 'any' class implementation. After posting my answer, I kept working on the code towards parameterizing with respect to memory management as I had promised. I ended up in some ...
iavr's user avatar
  • 2,274
30 votes
3 answers
28k views

"Zip-like" functionality with C++11's range-based for-loop

My goal was to get the following code to work: ...
Andrew Spott's user avatar
29 votes
3 answers
59k views

Impossibly fast delegate in C++11

This legendary C++ delegate article can be easily converted into C++11, without the need for fancy preprocessor magic in the original. I'd like to know if I got all the necessary C++11 nuances right. ...
28 votes
6 answers
28k views

Validating opening and closing bracket pairs

I have refactored one of my old homework assignments (mainly to utilize std::stack and some C++11), and I'm still having trouble making it less repetitive. It ...
Jamal's user avatar
  • 34.9k
28 votes
5 answers
5k views

C++ Vector Clone

I'm learning C++, so I decided to make a simpler clone of std::vector. Concerns: I have seen people defining methods outside of the class, and only prototyping ...
internet_user's user avatar
27 votes
4 answers
5k views

If she floats then she is not a witch like we thought

Continuing my C++ saga, this is the third project for my CS1 class: Buoyancy is the ability of an object to float. Archimedes' principle states that the buoyant force is equal to the weight of ...
syb0rg's user avatar
  • 21.8k
27 votes
4 answers
24k views

Measuring execution time in C++

I had time measuring pretty much figured out when I ended up using this structure. ...
Nikos Athanasiou's user avatar
27 votes
2 answers
10k views

C++11 Any class

This is a polymorphic wrapper capable of holding any type. (It is loosely based on boost::any) In particular, this is useful when you want to store a ...
user1131146 account abandoned's user avatar
27 votes
2 answers
3k 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 ...
Edward's user avatar
  • 65.3k
27 votes
2 answers
3k views

A header-only linear-time C++11 PEG parser generator supporting left-recursion and grammar ambiguity

I've rewritten my original parser generator to a header-only library which uses templates and functionals for better type safety and clarity. The generated parser creates an abstract syntax tree which ...
Lars Melchior's user avatar
26 votes
6 answers
107k views

Conversion between enum and string in C++ class header

I have the following redundant-feeling design to convert between enums and strings regarding a class that stores enums. The ...
Veksi's user avatar
  • 431
25 votes
4 answers
42k views

Create a C++ string using printf-style formatting

It's often convenient to use C-style printf format strings when writing C++. I often find the modifiers much simpler to use than C++ I/O manipulators, and if I'm ...
Toby Speight's user avatar
24 votes
5 answers
3k views

The Term-inator: Pi edition

The fourth project, continuing my C++ saga with terrible post names. :P An approximate value of pi can be calculated using the series given below: $$ \pi \...
syb0rg's user avatar
  • 21.8k
24 votes
2 answers
15k 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 ...
Emily L.'s user avatar
  • 16.5k
24 votes
1 answer
20k views

UDP Network server/client for gaming using boost.asio

I've designed those classes for use in a multiplayer game with possibly very high number of clients for one server. Is this implementation good, or is there something obvious I overlooked or something ...
DarkWanderer's user avatar
24 votes
1 answer
2k views

Chrono-like clock with different epoch (from 1.1. 2000)

The following will by my simple helper, that should behave just like std::chrono::system_clock but with the epoch being 1.1. 2000, that I can easily cast durations ...
user avatar
23 votes
11 answers
11k views

Find nth Fibonacci Number, using iteration and recursion

I'm a beginner programmer and I came upon this problem which is to find the n​th number in the Fibonacci series. I used to solve the problem using a for loop; ...
David Peterson's user avatar
23 votes
4 answers
21k views

Pong game using SDL 2.0

I've just finished writing my first game: a clone of the classic Pong game for Linux and Mac only. You will need SDL 2.0, SDL_ttf 2.0 and SDL_Mixer 2.0 to compile it. The complete project can be found ...
Chafic's user avatar
  • 585
23 votes
3 answers
3k views

Brainfuck on-the-fly interpreter in C++

I was bored yesterday morning, so I wrote a brainfuck interpreter. I know there are a lot, but this one is different. Why? Because it evaluates brainfuck code on the fly, reading from the input file, ...
Emilio Cobos Álvarez's user avatar
23 votes
1 answer
7k views

Ultimate Tic-Tac-Toe with AI and GUI

During my hiatus, I decided to revisit some of the Tic-Tac-Toe questions here. I created a simple Tic-Tac-Toe GUI game, and then thought, might as well do the Ultimate Tic-Tac-Toe challenge. I am ...
Quaxton Hale's user avatar
  • 2,629
21 votes
3 answers
57k views

C++ Task Scheduler

I needed a task scheduler that could be used somehow like this: ...
Gabriel's user avatar
  • 505
21 votes
1 answer
8k views

C#-like class properties

I am currently developing a new breed of 3D engine for my upcoming thesis and I really liked the C# properties, but now I am on C++11 for obvious reasons. Since I couldn't find it elsewhere, I tried ...
thesaint's user avatar
  • 311
20 votes
5 answers
5k 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 ...
Edward's user avatar
  • 65.3k
20 votes
3 answers
4k 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 ...
StackedCrooked's user avatar
20 votes
2 answers
11k views

Unique type ID, no RTTI

Following my answer to Unique type ID in C++, I have worked towards a "safer" version that I am posting here. This is a lightweight type that can store a unique (also across compilation units) ID per ...
iavr's user avatar
  • 2,274
20 votes
0 answers
2k views

Building a good C++11 template library - compile-time checked enum array [closed]

The task is to add data or values to members of a given enum class. The compiler should check if a value for each enum member is ...
Mike M's user avatar
  • 341
19 votes
6 answers
3k views

Testing whether characters of a string are unique

Critiques (even pedantic ones) are welcome. ...
tgm's user avatar
  • 193
19 votes
2 answers
2k views

Hangman on the C++ommand line

I'm wondering if my code is just a tad too long to post here, but if the only consequence seems to be getting high-level reviews, then that's perfectly fine. This is my implementation of Hangman in C+...
vvye's user avatar
  • 699
18 votes
4 answers
4k views

N closest points to the reference point

Here is working code to get N closest points to some reference point. Please help to improve it, specifically by commenting on my use of std algorithms and ...
Maxim Galushka's user avatar
18 votes
4 answers
16k views

std::tuple foreach implementation

I wrote a "foreach" implementation for std::tuple: ...
tower120's user avatar
  • 357
18 votes
2 answers
2k views

C-style language lexer for a syntax highlighter

I'm working on implementing a syntax highlighter for a simple text editor I've been working on. To do this, I need a simple lexer for various languages (I don't need a full one - I'm only interested ...
CmdrMoozy's user avatar
  • 417
18 votes
2 answers
4k views

Rock-Paper-Scissors-Lizard-Spock challenge in C++

Here's my take at the Rock-Paper-Scissors-Lizard-Spock challenge. The outcomes are as follows: Scissors cuts paper paper covers rock rock crushes lizard lizard poisons Spock Spock ...
Jamal's user avatar
  • 34.9k
18 votes
2 answers
9k views

Unique compile time (constexpr) type ID without RTTI

I am making a library where I need to generate a unique ID for a type where the ID must be known at compile time. I first relied on the address of a template function, but it proved itself unreliable ...
Guillaume Racicot's user avatar
18 votes
2 answers
6k views

Variant class with full move support

I tried to write my own variant class, that is fully move-semantics enabled. WRT to implemented visitors, they don't require any policy and like to be derived from <...
Tomilov Anatoliy's user avatar
18 votes
2 answers
28k views

Portable periodic/one-shot timer implementation

Note: I have posted a follow-up question for a significantly updated version of this code. I have implemented a class that provides portable one-shot or periodic timers. The API provides a way to ...
doug65536's user avatar
  • 513
18 votes
1 answer
1k views

Fluid Simulation with SDL

I have always wanted to write a fluid simulation, and with the help of a paper and some StackOverflow users I've got something that works. My goal is to have a program that someone can run right away ...
qwr's user avatar
  • 1,016
18 votes
1 answer
4k views

TCP Socket Wrapper

I'm trying to build a simple server software for training purpose, most likely a IRC server, but I'm not there yet. I'm currently implementing a TCP socket class, to ease the use of the C socket API. ...
florian-s's user avatar
  • 183
17 votes
6 answers
13k 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). ...
w.b's user avatar
  • 281
17 votes
4 answers
5k views

Bezier curves of grade n

I made a function which creates Bezier curves of grade n. What do you think? ...
NaCl's user avatar
  • 370

1
2 3 4 5
35