Skip to main content

Questions tagged [c++14]

Code that is written to the 2014 version of the C++ standard. Use in conjunction with the 'c++' tag.

Filter by
Sorted by
Tagged with
38 votes
5 answers
5k views

Easier user input in C++

A more proper version of this utility can be found at the following link here: Giveth me thy easier user input in C++ - follow up. I've always been a little bothered by the fact, that in order to get ...
Ethan Bierlein's user avatar
37 votes
8 answers
26k views

Thread Pool C++ Implementation

I have been working on this thread pool for awhile to make it as simple to use as possible. I need some tips on improving performance, and some good ways to test its performance. I was wondering if ...
Paul's user avatar
  • 492
27 votes
4 answers
3k views

RPG skeleton, Part 1 - The Character

I've been on a quest to learn C++, and to learn, I've started building a small Role-Playing-Game skeleton to help myself learn the language. I've tried to make sure that I've followed C++ styles/...
Ethan Bierlein's user avatar
26 votes
1 answer
17k views

Ford-Johnson merge-insertion sort

The Ford-Johnson algorithm, also known as merge-insertion sort (the name was probably given by Knuth) is an in-place sorting algorithm designed to perform as few comparisons as possible to sort a ...
Morwenn's user avatar
  • 20k
25 votes
3 answers
1k views

Gray codes addition

As some of you know, I have been working with Gray codes and am trying to design a good gray_code class in modern C++. I will end up posting several parts of the ...
Morwenn's user avatar
  • 20k
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
5 answers
6k views

Sorting algorithms - Bubble sort

For pure practice purposes, I started implementing different sorting algorithms in modern C++ in a standard library style way (i.e. using templates on iterators). This is my version of bubble sort. ...
Ben Steffan's user avatar
  • 5,228
23 votes
3 answers
5k views

C++ FlagSet: typesafe usage of enumeration as bitset/bitmask

Below is my attempt at providing a type-safe way to combine enumeration and bitset together. The resulting class is intended to be use as a set of flags, where each flag is a member of the "user-...
Xaqq's user avatar
  • 333
23 votes
1 answer
4k views

CMake Project Template for a General Cross Platform C++14 Project

UPDATE: I am no longer updating this post with the contents of my actual project since they have changed significantly (Unit testing is now done with doctest, code coverage is included, etc.). This ...
Arnav Borborah's user avatar
22 votes
2 answers
5k views

C++ function composition

What is a good way to compose std::function objects in C++? I tried the following, and it seems to work well: ...
davidhigh's user avatar
  • 538
22 votes
1 answer
643 views

Aligning your heterogenous uninitialized memory to make the processor happy

After learning more about memory alignment and how it can impact processor data access, I tried to find something in the standard that offers proper memory alignment inside blocks of raw memory that ...
user2296177's user avatar
  • 3,543
21 votes
3 answers
9k views

A vector-like polymorphic container to store objects from a type hierarchy in contiguous memory

Normally, in order to have a polymorphic collection, we store pointers to a base class: ...
user2296177's user avatar
  • 3,543
20 votes
1 answer
2k views

Compile-time sieve of Eratosthenes

There are many instances of prime number sieve implementation both here and other places on the web, but I wanted something a little different. In particular, I wanted to create a static array of the ...
Edward's user avatar
  • 66.5k
19 votes
1 answer
3k views

for_each for tuple-likes

I've implemented a C++14 for_each for tuple-like objects. It's similar to std::for_each in that it also returns the functor once ...
Zizheng Tai's user avatar
18 votes
5 answers
14k views

Banking system in C++

I've created a program for Banking System in C++14. You are given 9 options: Open Account Close Account Show All Accounts Deposit in Account Withdraw from Account Transfer to an Account Show Balance ...
Sriv's user avatar
  • 2,740
18 votes
1 answer
920 views

Integer packs (and integer pack utilities) for template meta-programming

Introduction In template meta-programming, integer sequences and ranges are very useful. I've made a couple of utility classes that do various operations on compile-time integer packs. The ...
user2296177's user avatar
  • 3,543
17 votes
2 answers
666 views

Re-implementation of `std::tuple` for MCUs

Background I'm writing code for an 8-bit MCU with very limited RAM (1KiB) and program flash space (64KiB). I have a C++14 capable compiler with no standard library implementation available. This is a ...
Emily L.'s user avatar
  • 16.6k
16 votes
4 answers
992 views

Array alive/dead entity "refresh" algorithm

I have an Entity class that can be either dead or alive. I store entities contiguously in a resizable array. During an update()...
Vittorio Romeo's user avatar
16 votes
2 answers
50k views

Ring Buffer Implementation in C++14

A ring buffer or circular buffer is a fixed sized queue that advances head and tail pointers in a modulo manner rather than moving the data. Ring buffers are often used in embedded computer design. ...
davidbear's user avatar
  • 577
16 votes
2 answers
519 views

Exact sort - sorting with few move operations

A while ago, I found a somewhat interesting sorting algorithm named Exact-Sort, which is introduced with the following somewhat bold claim: No sort algorithm can sort an array with less position ...
Morwenn's user avatar
  • 20k
16 votes
2 answers
1k views

C++ SQL wrapper/Connection

Working on my SQL project at last. The concept is easy to use and integrate SQL into C++. ...
Loki Astari's user avatar
  • 95.3k
15 votes
1 answer
6k views

128-bit unsigned integer

This implements 128-bit unsigned integer using C++14. It works on MSVC and 32-bit architectures being complementary to the unsigned __int128 type provided by GCC ...
Paweł Bylica's user avatar
15 votes
3 answers
533 views

Melsort — Sorting with encroaching lists

For the nth time already I come back with yet another alien sorting algorithm. Today I will present Melsort, implemented from the description I found in the paper Encroaching Lists as a Measure of ...
Morwenn's user avatar
  • 20k
15 votes
1 answer
2k views

Comparing std::vector<bool> to std::vector<char>

A recent comment to an answer of mine here on Code Review brought up an interesting point. The comment was that one should use std::vector<char> over ...
Edward's user avatar
  • 66.5k
15 votes
1 answer
1k views

Battleship strategy evaluation framework

In preparation for the May 2015 Community Challenge, I decided to build a Battleship strategy tester. Implementing an ocean First, there is an underlying Ocean ...
Edward's user avatar
  • 66.5k
15 votes
1 answer
6k views

Simple linear equation solver

In working on a review for Solve a set of "restricted" linear equations efficiently, I decided to reimplement from scratch using the method I proposed in my answer. The application I won't ...
Edward's user avatar
  • 66.5k
15 votes
1 answer
366 views

Permuting a typelist

Given a typelist, return a typelist of all the permutations of it. For example: ...
Barry's user avatar
  • 18.4k
15 votes
1 answer
449 views

An implementation of a static any type

This describes type util::any<std::size_t size, std::size_t align> - an implementation of std::any with a static size/no ...
user2296177's user avatar
  • 3,543
14 votes
4 answers
13k views

Simple stopwatch class

I'm not sure what the best way is when dealing with users calling start() multiple times or stop() before calling ...
user2296177's user avatar
  • 3,543
14 votes
3 answers
10k views

Apply a function to each element of a tuple ("map" a tuple)

C++ doesn't (yet) have a 'map' higher-order function, certainly not one which applies to a compile-time sequence of values like a tuple. We have std::transform, and ...
einpoklum's user avatar
  • 2,015
14 votes
1 answer
3k views

C++ identity function

I've implemented an identity function (well, actually a functor struct) in C++. The goal is that every occurrence of an ...
Zizheng Tai's user avatar
13 votes
1 answer
1k views

Simple NAPI wrapper around self written C++ msgpack, horrible performance

I have written a relatively small msgpack implementation in C++, with performance that is not too bad, so I decided to write a NAPI wrapper around it, but the performance is just horrible. I am ...
t348575's user avatar
  • 233
13 votes
2 answers
1k views

C++ data type to store and manipulate individual bits

The use cases I’m facing require me to have a C++ data type that can store and manipulate the state of somewhere between 400 and 500 bits. In addition it is necessary to be able to store that state ...
ackh's user avatar
  • 245
13 votes
2 answers
607 views

Elementwise iterator adaptor

There are many C++ implementations of the Euclidean vector. I.e., a vector in what is typically a 3- or 4-dimensional space. Something along the lines of ...
Frederik Aalund's user avatar
13 votes
1 answer
4k views

Container with sorted by multiple keys

From this question: Sorted vector (aka flat_set) for objects (pointers) with custom embedded key (functor used) This is an example of a multi-index container. Note: this is not a container as ...
Loki Astari's user avatar
  • 95.3k
13 votes
1 answer
137 views

ThorsSQL Lib: Part 3: Layer 1

Have a working version of MySQL implementation of ThorsSQL library done. If you want to check it out you can find the whole thing on github ThorsSQL. This is a follow on to previous code Reviews: ...
Loki Astari's user avatar
  • 95.3k
13 votes
1 answer
325 views

Vergesort — A runs-adaptive layer to enhance sorting algorithms

More than a full-fledged sorting algorithm, vergesort is a Runs-adaptive algorithm that falls back most of the time to another sorting algorithm to sort a sequence of elements, but is able to identify ...
Morwenn's user avatar
  • 20k
12 votes
3 answers
5k views

"contains" function for STL containers

I have made a simple program that tests if the given element exists in any STL container. The program tests if the container has a find member function. It will use ...
MORTAL's user avatar
  • 3,278
12 votes
3 answers
2k views

A moveable QScopedPointer, or a Qt and std cross-compatible unique_pointer

I'm a hobby programmer, so I've never been through a code review before (online or offline). That said, here goes: Background I use Qt extensively but have long wanted ...
jonspaceharper's user avatar
12 votes
2 answers
4k views

Generic absolute value function

I wanted to write a generic abs function that would correctly work for every type. Basically, I wanted to use the following algorithm: If the type is a built-in ...
Morwenn's user avatar
  • 20k
12 votes
1 answer
2k views

Minimal C++ Unit Test Framework

I've written a minimal unit test framework. The goal was to allow assertions of booleans, for equality and catched exceptions. Two things are bugging the most. That assertions have to rely on macros ...
aggsol's user avatar
  • 404
12 votes
1 answer
3k views

Compile-time-fixed templated integer range

This is a follow-up of an old question by @LokiAstari, modified for the current community challenge. The idea is to provide a compile-time integer range. I applied all the modifications that I ...
Morwenn's user avatar
  • 20k
12 votes
1 answer
573 views

A Smarter random bomber for Battleship

In a further exercise of my original Battleship test framework, I have enhanced and refactored the SmartRandom class from an earlier question and have updated ...
Edward's user avatar
  • 66.5k
12 votes
1 answer
1k views

An optional_ref<T>

I omitted all free operators but the equality comparisons ones because of verbosity. I am glad about any comments and improvements. Motivation I know that optional references are equivalent to ...
Maikel's user avatar
  • 740
12 votes
1 answer
1k views

A polymorphic callable wrapper for any callable

I recently answered a question that had an interesting problem statement (I've slightly modified the wording): I have an abstract class A which is base for the ...
user2296177's user avatar
  • 3,543
12 votes
2 answers
232 views

Thread safety/Transaction enforcer

I have some legacy classes written without thread safety in mind. Instances of these classes are now being accessed in a multithreaded context in a thread-un-safe manner. Cue chaos. To fix this I ...
Emily L.'s user avatar
  • 16.6k
11 votes
5 answers
3k views

Efficiently counting rooms from a floorplan (version 2)

This is version 2 of Efficiently counting rooms from a floorplan. I had accidentally pasted in the wrong version of the code. Update Final version (version 3) of the code with updated test harness ...
Edward's user avatar
  • 66.5k
11 votes
3 answers
3k views

Safe strcpy implementation with C++

After reading this article, I've decided to take a crack at implementing a "safe_strcpy" function that would remove some of the errors that the author speaks about. Obviously, my ...
Bizkit's user avatar
  • 1,719
11 votes
2 answers
209 views

Dynamically call lambda based on stream input: Try 2

Originally asked here: Dynamically call lambda based on stream input The following version is based heavily on the answer provided by @iavr, though I hope that I have done enough more to make it ...
Loki Astari's user avatar
  • 95.3k
11 votes
2 answers
2k views

C++ vector that uses expression templates technique to increase performance of mathematical expressions

I've been reading Item 6 from Scott Meyers' Effective Modern C++ and noticed that he mentioned a technique called expression templates. I've decided to give it a try and implemented a vector that ...
rubix_addict's user avatar

1
2 3 4 5
10