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
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
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
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
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
6 votes
2 answers
148 views

A Simple Cluster Generator v0.2

[NOTE] This question can be depreciated in favor of version 0.3. This is a code revision of a previous post and works well. Code has been reworked to be far more clear and concise, thanks to ...
Miller's user avatar
  • 533
6 votes
1 answer
981 views

Recursive Breadth First Search for Knights Tour

This was written as an experiment in performance, based on another question here on CodeReview. Input into the algorithm is the number of squares on one edge of the chess board, the point of origin, ...
pacmaninbw's user avatar
  • 23.5k
5 votes
1 answer
306 views

Knights Tour - Improved Refactored Recursive Breadth First Search for

The development and testing was performed on a Dell M6400 Laptop (Intel Core 2 Duo) running Centos 7, g++ compiler version 4.8.5, compiler switches -O3 -std=c++0x -D__cplusplus=201103L. (machine ...
pacmaninbw's user avatar
  • 23.5k
13 votes
2 answers
22k views

Unique type ID in C++

I need to have an unique ID for any type in C++ for a variant type. Is this code reliable for getting the ID? I don't care to have same ID for same type between multiple runs. Sorry for typos/...
Mircea Ispas's user avatar
9 votes
1 answer
2k views

Generate a random numbers class

I have made class to setup a random number bases on <random>. It works fine, but I have doubt in ...
MORTAL's user avatar
  • 3,278
8 votes
1 answer
3k 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 ...
utnapistim's user avatar
  • 3,577
7 votes
3 answers
3k views

Random number generation in Dice class

I don't intend on implementing this into an application yet as I'm going to test it first. As such, it doesn't do much beyond rolling. It also overloads some "typical" operators such as ...
Jamal's user avatar
  • 34.9k
5 votes
1 answer
2k views

Simple neural-network simulation in C++

The C++ code below simulates the timecourse of the membrane potential (V) of a population of 128 leaky integrate-and-fire ...
abcd's user avatar
  • 329
5 votes
1 answer
134 views

Multithreaded console-based monster battle with earliest-deadline-first scheduler

In working on this answer it occurred to me that it might be interesting to further expand the idea. The game This is an extremely simple (and boring!) text-based game that creates a few monsters ...
Edward's user avatar
  • 65.3k
3 votes
1 answer
141 views

A Simple Cluster Generator v0.3

[NOTE] This question can be depreciated in favor of version 0.31. This is a code revision of a previous post and works well. The purpose of this code is to produce a universe of points, randomly ...
Miller's user avatar
  • 533
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
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
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
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
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
17 votes
4 answers
4k views

Morse code emitter

As the first step for writing a Morse code practice program, I thought I'd start with the very simplest step of a text-based Morse code translator. This simple program reads lines from ...
Edward's user avatar
  • 65.3k
16 votes
1 answer
1k views

value_ptr<T> - a C++11 header-only, deep-copying smart pointer that preserves value semantics for polymorphic and undefined types

== UPDATED: next revision HERE == My previous two iterations were here and here. I've since finalized the concept as described in the title, and would appreciate any feedback on the new solution ...
Tom's user avatar
  • 405
13 votes
3 answers
2k views

Parallel sieve of Eratosthenes, version 2

This question is a revision of Parallel sieve of Eratosthenes. The goal is to implement a sieve of Eratosthenes with parallel strikes out from the boolean array. I tried to fix the data races and all ...
Morwenn's user avatar
  • 19.9k
12 votes
4 answers
11k views

Console-based table structure

Personally I often prefer console applications over GUI applications. However, sometimes it is quite a challenge to display everything well-aligned. Therefore I decided to create a console-based table ...
766F6964's user avatar
  • 901
11 votes
2 answers
38k views

Text-based Tetris game

How can I improve this game? ...
MORTAL's user avatar
  • 3,278
9 votes
1 answer
3k views

C++ template range

From a previous question I got an answer that included some template magic (that to be blunt was mind-boggling (as I could not understand it)). So I have been trying to achieve the same results (...
Martin York's user avatar
  • 94.3k
8 votes
1 answer
1k views

Generic pure functions memoization

I like to create tools for memoization since it can sometimes be useful. I recently created a generic tool for memoizing the results of pure functions. Here is an example of how it works: ...
Morwenn's user avatar
  • 19.9k
8 votes
2 answers
541 views

'Evolutionary AI' implementation

For the code sample that I am asked to submit with most of my job applications (usually Gameplay Programmer), I created this console application in which I attempt to figure out what is the best ...
mzi's user avatar
  • 613
7 votes
4 answers
535 views

General advice on a practice linked_list for C++ classes/templates

Introduction I'm learning C++ (Coming from Haskell, C, and Assembly - and other languages sparsely) and this was my practice with classes and templates. It's a linked list that you can call in this ...
GRAYgoose124's user avatar
6 votes
3 answers
4k views

Simple stack implementation using linked list

Please review my Stack using linked list: ...
lightning_missile's user avatar
6 votes
1 answer
7k views

Generic menu class for console applications

Expanding the title: my goal (for hobby project) was to create simple, generic (customizable) and cross-platform menu class for console applications (mostly simple, text-based games). That's what I ...
Toreno96's user avatar
  • 163
5 votes
3 answers
5k views

Natural merge sort

Note: the next iteration at Natural merge sort - follow-up I have compiled natural merge sort algorithm from Java to C++. Natural merge sort sacrifices at most \$2N\$ amount of work in order to ...
coderodde's user avatar
  • 27k
5 votes
1 answer
136 views

A Simple Cluster Generator v0.31

[NOTE] This question can be depreciated in favor of version 0.32. This is a code revision of a previous post and works well. The purpose of this code is to produce a universe of points, randomly ...
Miller's user avatar
  • 533
5 votes
3 answers
324 views

Local heapsort in C++

Suppose we need to sort a sequence and we know that every sequence component is within \$d\$ steps from its correct position. In such a case we can use a local heapsort: we take \$d\$ as an argument ...
coderodde's user avatar
  • 27k
5 votes
0 answers
223 views

deep_ptr<T>; a header-only, deep copying, value semantic smart pointer for optionally defined types

Edit: final revision here A couple days ago I posted a similar question here. Since then, I have refined the implementation a bit further, as the solution I had previously posited was a bit off ...
Tom's user avatar
  • 405
4 votes
2 answers
2k views

Project Euler - Smallest multiple

Here's Problem 5 - Smallest multiple 2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder. What is the smallest positive number that is evenly ...
lightning_missile's user avatar
3 votes
3 answers
1k views

Improved stack implementation using a linked list

This is a followup to Simple stack implementation using linked list Since my original stack implementation has lots of bugs that I did not notice, I thought I would recreate and try to improve it. ...
lightning_missile's user avatar
3 votes
2 answers
966 views

Tic-Tac-Toe in C++11 - follow-up 2

Previous question: Tic-Tac-Toe in C++11 - follow-up Is there any way to improve this code? ...
MORTAL's user avatar
  • 3,278
3 votes
2 answers
490 views

C++11 ThreadPool implementation

A new version of this code based on the provided advice can be found here. Latest improvement is found here. I made a simple ThreadPool implementation in C++ using ...
Dávid Tóth's user avatar
2 votes
1 answer
1k views

Variadic template data pack strucuture designed for debug/trace log (variable-sized records)

I am currently writing this pack template to pack all the values (raw / fundamental + arrays of such, especially c-strings and ...
user avatar
2 votes
1 answer
1k views

Producer-Consumer in C++ - follow-up

To expand from the changes supplied by the answer of my previous question: ...
T145's user avatar
  • 3,087
2 votes
1 answer
111 views

Pointer class/handle

Please review my pointer class. ...
lightning_missile's user avatar
1 vote
2 answers
2k views

Priority Scheduling Algorithm Preemptive

After implementing suggestions from my previous question and after modifying I have written this code. Function sortAccordingArrivalTime() sorts ...
coder's user avatar
  • 2,449
1 vote
1 answer
737 views

Translate a day in year to month and day

Take an integer representing a day of the year and translate it to a string consisting of the month followed by day of the month. For example, Day 32 would be February 1. This is what I came up with. ...
dino2018's user avatar
1 vote
1 answer
248 views

Implementation of logarithmic random distribution satisfying RandomNumberDistribution concept

Following from this post on SO, I provide logarithmic_distribution to satisfy the C++ RandomNumberDistribution concept implementing the PDF ...
Walter's user avatar
  • 465
0 votes
2 answers
2k views

Shortest Job First Preemptive

I will write code for all scheduling algorithm in future that is why scheduling.h will contain common data members and member functions. Please help me to improve and optimise this code. scheduling.h ...
coder's user avatar
  • 2,449
0 votes
1 answer
417 views

What can I do better in my C++ serialization implementation?

I want to serialize a class Mango recursively. ...
James_sheford's user avatar
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

1
2 3 4 5