Questions tagged [c++17]

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

Filter by
Sorted by
Tagged with
41 votes
1 answer
4k views

Recursive shared_mutex implementation

I found myself in need of a Readers-Writer mutex. With C++17 TR2 support not yet available in our compiler, I set out to implement std::shared_mutex so that we have ...
Emily L.'s user avatar
  • 16.6k
28 votes
5 answers
8k views

C++ logging library

I am creating a logging library in C++, and I wanted your opinion on code quality and performance within some methods. You may ask why yet another logger - the answer is simple. This logging library ...
Christian Panov's user avatar
26 votes
5 answers
6k views

Japanese reading of an integer

Inspired by CtCI 16.8: Integer to English phrase in C++, I wrote a program to show the Japanese reading of an integer (positive, negative, or zero). The Japanese is written in Hepburn romanization to ...
L. F.'s user avatar
  • 9,508
25 votes
4 answers
43k 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
  • 74.6k
23 votes
3 answers
4k views

Seamlessly migrating <experimental/optional> to <optional>

From this Stack Overflow answer, I learned that C++17 will have __has_include, which can [make] migrating from experimental to std almost seamless This still ...
Justin's user avatar
  • 3,295
22 votes
2 answers
4k views

Implementation of std::any

Today, I decided to implement std::any using the cppreference page. I've never actually used std::any before and after seeing ...
Indiana Kernick's user avatar
21 votes
4 answers
7k views

Rock, Paper, Scissors in C++

I have a fair few years experience with programming, and am currently working in a software development role, writing internal web applications in C#. This is the first C++ code I have ever written, ...
Jessica's user avatar
  • 818
20 votes
3 answers
64k views

Modern C++ Singleton Template

I recently read about the C++17 static inline member declaration and thought that this will make templates a little bit cleaner, since static members can now be ...
muXXmit2X's user avatar
  • 323
20 votes
1 answer
655 views

QuickMergesort — The power of internal buffering

Amongst the lesser-known unstable sorting algorithms is the QuickXsort family of algorithms, as described in QuickXsort: Efficient Sorting with n log n - 1.399n +o(n) Comparisons on Average by Stefan ...
Morwenn's user avatar
  • 20k
20 votes
1 answer
454 views

From new Q to compiler in 30 seconds

Reviewing code doesn't necessarily require actually building it, but it's often helpful to do so in order to evaluate fully. I usually create a CMake project and ...
Edward's user avatar
  • 66.4k
19 votes
3 answers
3k views

Min function accepting varying number of arguments in C++17

Come across this problem once again in the book The Modern C++ Challenge. 18. Minimum function with any number of arguments Write a function template that can take any number of arguments and returns ...
Lingxi's user avatar
  • 818
17 votes
4 answers
5k views

A minimal Fraction class in C++

I am trying to learn idiomatic Modern C++. I was wondering how you would improve upon this Fraction class. I would really appreciate any help with code organization, cleanliness and anything else that ...
rustcpp's user avatar
  • 173
16 votes
3 answers
27k views

Implementing a logging system in C++17

I've been programming for what is a probably a little bit and made a very simple logging system for my personal projects. While it works out fairly well so far, I would like advice on how to make it ...
Rietty's user avatar
  • 375
15 votes
2 answers
8k views

2D counterpart of std::array in C++17

I implemented a 2D counterpart of std::array named array2d in C++17. It is an aggregate like ...
Lingxi's user avatar
  • 818
14 votes
4 answers
11k views

BigInt class in C++

I made a BigInt class that supports almost all functions an int would. The code seems too bulky and there might be a few bugs lurking here and there. I would like ...
Sriv's user avatar
  • 2,720
14 votes
3 answers
6k views

C++ Fast Fourier transform

This is a very simple FFT, I am wondering what I can do to make this faster and more memory efficient from the programming side (better data types, and maybe some tricks like unrolling loops or using ...
Pel de Pinda's user avatar
13 votes
4 answers
3k views

FizzBuzz, ’17-style

My exercise is to write the Fizz Buzz problem with the following in mind: Use the latest up-to-date style and best practices for a C++17 compiler. Don’t just show that I can write a loop. Rather, ...
JDługosz's user avatar
  • 11.3k
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
3 answers
440 views

Compute mean and variance, incrementally

I have previously reviewed code that computes standard deviation using the mathematical formula E(x²) - E(x)², and warned against the use of this formula because floating-point precision is severely ...
Toby Speight's user avatar
  • 74.6k
13 votes
1 answer
432 views

Game-oriented UDP protocol

As part of a small multiplayer game project I designed a generic (and not too complex) protocol (used over udp). The game is 2D, has physics-based elements (e.g. rigid body, smoke) and should be ...
nyorain's user avatar
  • 151
12 votes
3 answers
501 views

C++, sort integers using knowledge of entire vector

I am solving the "Sort" problem on Kattis. Mirko is a great code breaker. He knows any cipher in the world can be broken by frequency analysis. He has completely the wrong idea what ...
YuJin Kim's user avatar
  • 123
12 votes
2 answers
2k views

C++ std::array wrapper

I implemented a std::array wrapper which primarily adds various constructors, since std::array has no explicit constructors ...
Matthias's user avatar
  • 319
12 votes
3 answers
8k views

Implementation of static_for to iterate over elements of std::tuple using C++17 features

I have implemented a static_for loop to iterate over the elements of an std::tuple using C++17 features. Here is what I have ...
Steve Rodeen's user avatar
12 votes
3 answers
2k views

Matrix implementation

I am trying to implement an optimal and fast running matrix in C++. I need some review of the code and ideas on how to improve the code quality if it shall be. ...
Hrant Nurijanyan's user avatar
12 votes
1 answer
3k views

Generalized Cartesian Product

Much to my chagrin, neither STL nor Boost has a cartesian product. Namely, given as arguments one or more iterables, create an iterator producing std::tuples of ...
Bailey Parker's user avatar
12 votes
1 answer
195 views

Composable by-member comparison

Motivation Quite often, I find myself creating types that must be compared memberwise. For example, consider this simple Person: ...
Toby Speight's user avatar
  • 74.6k
12 votes
1 answer
5k views

C++17 <span> implementation

C++20 added the span library under the header <span>. As voluntary exercise (not homework!), I spent approximately 1.5 ...
L. F.'s user avatar
  • 9,508
12 votes
2 answers
2k views

Modern C++ singly linked list

This is a rather minimal (though fully functional) implementation of a singly linked list. It supports \$\mathcal{O}(1)\$ front insertion and deletions, as well as \$\mathcal{O}(1)\$ random insertions ...
hoffmale's user avatar
  • 6,468
11 votes
1 answer
1k views

Customization of memory class C++

I have implemented a customized memory allocation class template for an assignment. Codes are commented; Hopefully it's clear. I would love to know if there is any way to make the code more optimized. ...
starrk's user avatar
  • 369
11 votes
3 answers
1k views

Sudoku solver program written in modern c++

This is a simple program that solves a given Sudoku puzzle recursively. The input is provided as a file that contains the cells, 0 if empty, delimited by a , ...
adityagnet's user avatar
11 votes
2 answers
5k views

C++17 saturating integer (arithmetic) type library

I wrote a C++ library to provide extra signed and unsigned integer types that saturate in overflow situations. It's in proof of concept stage and I'd love to get some feedback on it. A short usage ...
Stefan's user avatar
  • 813
11 votes
2 answers
10k views

C++17 thread pool

I've implemented a thread pool in C++17. This is not backwards compatible with C++14, due to the usage of std::invoke_result, which is new to C++17. The focus of ...
osuka_'s user avatar
  • 517
11 votes
1 answer
343 views

C++17 pointer_traits implementation

pointer_traits is a lightweight trait that provides a uniform interface to builtin pointers and user-defined fancy pointers. That said, things like ...
L. F.'s user avatar
  • 9,508
11 votes
1 answer
5k views

Simple uint128_t implementation

I made a simple uint128_t implementation for a project that I'm working on. The reason for not using for example boost::uint128_t...
Rakete1111's user avatar
  • 2,562
10 votes
2 answers
2k views

Iterator for traversing a tree [v2]

this is an update of the implementation after I followed the feedback from Iterator for traversing a tree. After that I did changed quite a bit on the design and decided to ask for another round of ...
Christopher Boo's user avatar
10 votes
2 answers
513 views

Disassembler for intel 8080

I have written a disassembler for Intel 8080, able to translate binaries into opcodes and parameters. Sorry for posting so much code, but everything posted here is useful for the understanding of the ...
Stud's user avatar
  • 786
10 votes
2 answers
30k views

Converting std::chrono::time_point to/from std::string

Consider these functions that allow to convert std::chrono::time_point to/from std::string with a predefined date-time format. <...
Vahagn's user avatar
  • 211
10 votes
2 answers
542 views

Identify files within folder structure that have common file sizes

The code takes in two arguments, a path to search and an output file name. It searches the supplied path (including sub directories) and writes out all files that have the same size as any other ...
forsvarir's user avatar
  • 11.6k
10 votes
2 answers
1k views

Simple parser using Flex and C++

This is an alternative parser based on the specifications from this question. Briefly stated, the input file is a text file which has at least 33 fields separated by semicolons. If the fourth field ...
Edward's user avatar
  • 66.4k
10 votes
1 answer
178 views

Consuming a picnic lunch

I have a number of related classes (Burger, Pizza, Cupcake) with a common base class ...
Edward's user avatar
  • 66.4k
10 votes
2 answers
2k views

Custom C++ random access iterator for pointers to arrays

I have implemented a custom iterator to iterate over an array that is held by a pointer. The iterator accepts a unit which specifies by which amount the underlying pointer is increased (or decreased) ...
Timo's user avatar
  • 343
10 votes
1 answer
397 views

Displaying programming languages on a timeline

I did the following two exercises in Programming: Principles and Practice Using C++ (2nd Edition), by Stroustrup, which build upon each other: From Chapter 22 (Ideals and History), Write a ...
Sandro4912's user avatar
  • 3,056
10 votes
2 answers
2k views

Generic binary search tree in C++

Introduction This is yet another data structure I'm going over again for the algorithms course. This time it is binary search tree. Implemented operations: Insert Exists Remove Clear Move ...
Incomputable's user avatar
  • 9,454
10 votes
3 answers
5k views

C++ Template to implement the Factory Pattern

Design A template class that will create a concrete instance of an interface class when given the name (as a string) of the concrete class. This design is often seen in code, so the purpose of this ...
Blue7's user avatar
  • 383
10 votes
2 answers
7k views

C++ Bit shift whole array (left)

For an embedded project I want to shift a (byte) array left by a certain amount of bits. I've built this template function to do so: ...
Stefan's user avatar
  • 813
10 votes
2 answers
387 views

N-Body Optimization

I've created a serial C++ code for gravitational N-Body calculation. Because I expect to have upwards of 8-71 sparse bodies (ie, where Barnes-Hut is not necessarily practical) and running for long ...
Marius Popescu's user avatar
10 votes
1 answer
5k views

C++ Inventory System

I have recently been working a lot on a project for a system that represents an inventory and item usage in a game, with one of the important features is that it should be reusable in multiple ...
MivVG's user avatar
  • 205
10 votes
1 answer
2k views

Static block memory allocator

I've found a little task to create a block memory pool allocator. This allocator is required to allocate memory in single fixed-sized blocks from the pool in static memory. Sizes of block and pool are ...
Michael K's user avatar
  • 103
10 votes
1 answer
13k views

An interval-map data structure

This data structure maps values from intervals of some type Key which satisfies LessThanComparable<Key> to values of some ...
Maikel's user avatar
  • 740

1
2 3 4 5
12