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
5 votes
1 answer
52 views

Traverse/transform (xml) tree

I am trying to write a utility for transforming xml trees using single pass and specifying node handlers. I used pugixml prior to this, and the library provides a ...
4 votes
0 answers
92 views

Multithreaded MVC game engine

This is an attempt at a multithreaded model-view-controller based engine for 2d console games (board games, roguelikes that sort of thing.) The code below will provide a fully working example but is ...
  • 397
0 votes
1 answer
48 views

Flippable atomic boolean

I was trying to implement a boolean that can be atomically flipped. The suggestion on Stack Overflow is to use an integer. This would be my implementation. ...
  • 133
5 votes
5 answers
865 views

Palindrome Permutation string

I’m starting to learn C++ by doing a lot of exercises, and I need your help so I can improve, Here is how it goes, I will try to solve an exercise and post both the ...
4 votes
1 answer
86 views

Bin-packing C++ solution using multi-map

The need (context). Several times a day, we need to migrate a set of digital assets from one system to another. The process uses memory (the assets are held in memory for a short time) and we need to ...
  • 197
4 votes
1 answer
137 views

A toy application of pub/sub using C++ for self-learning

Firstly, I apologize for the lengthy post. I was not sure which code I should include. In practice of c++, I am writing a toy application for pub/sub using c++17. ...
2 votes
3 answers
69 views

How to efficiently build an object from list or array of strings

I am working with an API that delivers some data in a QStringList or basically a list of strings. The data contains keys and values but it is not a ...
  • 121
1 vote
0 answers
16 views

Return type-erased object to the caller, use typesafe cast in a subsequent call [closed]

Libraries might need to return "context" objects to the caller, and then require the same object in subsequent calls. In some cases, the user is not required to know what's the concrete type ...
2 votes
2 answers
64 views

Virtual method with variations for different types

Each animal type will call reactToOwner() and exhibit its own behaviour. So simply define a reactToOwner() override for each ...
  • 1,109
3 votes
1 answer
48 views

Load and execute shared library

This is my attempt to load shared library on linux (and may be mac - did not test yet) I am interested if I am implementing everything correctly and if I can really use my function in a loop like that....
  • 1,266
1 vote
1 answer
245 views

Convert string to date C++

New to C++ here, by combining different pieces of code I've found, i came with this solution below to convert a date in string to a date object. It works as I want but I'm not certain to do the ...
  • 219
2 votes
1 answer
70 views

Storing (and retrieving) functions by indexing them by address

I want to implement a "service" of callbacks, where subscribers register or unregister a callback. I was thinking about indexing the callbacks by the function address, so that to unregister ...
  • 133
5 votes
3 answers
307 views

Templatizing a Timer class

I'm making a timer class in C++. This is the overview: ...
  • 75
2 votes
1 answer
73 views

C++17 view over the Ith elements of tuples in containers of tuples

For mainly didactic reasons, I have designed my ElementsView<I, T> class template, which provides a view over the I th ...
  • 123
4 votes
1 answer
590 views

Create and view a family tree

I have an assignment due Friday to make a family tree. Started to code in January. My reviews from the teacher for this code was that the use of pointers was horrendous and it wasn't OOP enough. This ...
  • 43
4 votes
2 answers
115 views

Multi-threaded Mandelbrot set generator slower than single thread

I am new to parallel programming. I have been playing around with multi-threading and for some reason, multi-threading the Mandelbrot set is slower than running a single thread. I have been trying to ...
1 vote
1 answer
108 views

Storing different types with common base using atomic-based typeid

I'm trying to develop some kind of in-memory store for my entities. These entities are representations of the devices available on the system. There may be eg. 3 leds, 1 temp sensor, 2 engines etc. ...
  • 241
0 votes
3 answers
222 views

Find local maxima of a sequence

I'm well versed in Python and Java, am just starting out with C++. Am enjoying the language and would really appreciate feedback on this solution. kata: Return positions and values of the "peaks&...
0 votes
1 answer
107 views

C++ stack class design

I am trying some hands on recent C++ standards. For the purpose of learning, I have implemented a Stack class as below which can hold any type of data member. I would like everyone to review this ...
3 votes
1 answer
216 views

visit for std::any

While solving an online excersise I have written some basic implementation for a visit function that works with std::any. The ...
8 votes
4 answers
1k views

Forward linked list implementation in C++

I wrote a linked list implementation in C++ to learn the concepts about linked lists as well as C++(17). I decided to use std::unique_ptr to help me avoid leaks and ...
2 votes
1 answer
214 views

C++ circular buffer that guarantees contiguous data

For interfacing with C-API that requires data in one contiguous block I came up with the following, which seems to work nicely, but I wanted to see if I didn't miss anything crucial. Drawback is of ...
  • 23
1 vote
1 answer
101 views

C++ Chess Engine - (Magic)Bitboard-based move generation

I am currently writing a bitboard-based Chess Engine in C++, and I recently finished the move generation. I am using move-lookup-tables that get pre-calculated at application startup for sliding and ...
  • 390
11 votes
3 answers
898 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. ...
4 votes
0 answers
38 views

formatting flattened string into JSON-like object in C++, part 2

I have reworked the code from my previous (linked) post. For reference: I have a string which contains JSON-like object flattened (stringify()ed). I need to JSON-...
2 votes
2 answers
84 views

Event Dispatcher for GLFW/Glad

I've tried to write an event dispatcher for a GLFW/Glad library. However I am not very used to writing efficient code (spent the majority of my life writing in C# and performance was never really the ...
1 vote
2 answers
201 views

Automatically registering a class using header-only templated classes

I'm trying to reduce the boilerplate of a lot of header-only classes I'm using. Each of these classes must go through a registration step. I want this step to be defined in the same file as the class ...
  • 551
0 votes
1 answer
93 views

Derived class constructor taking rvalue ref to base class

I've got the following classes: BaseWidget, ActiveWidget, and DetachedWidget. Both derived classes use resources provided by BaseWidget: vector and int. The current so-called "state" (...
  • 241
2 votes
1 answer
101 views

Counting Radix Sort: A C++ version

Follow up to original question: This is Radix Sort, using a counting implementation. For numbers that are N bytes in length, we use an N pass counting approach. Starting with the least significant ...
  • 91.9k
2 votes
0 answers
134 views

A reuseable reconnecting TCP socket with Asio

I'm using (non-boost) Asio 1.18.1 and C++17. Forgive the boost tag, there wasn't a more specific one. I have a async_connect_with_retry composed asynchronous ...
  • 153
2 votes
3 answers
174 views

Fixed-size memory allocator

I've been trying to implement a simple Boost PMR allocator that has a fixed amount of memory. My first implementation (which can be found here) had undefined behavior and did not handle memory ...
  • 31
5 votes
2 answers
563 views

C++ Garbage Collector - Simple Automatic Memory Management

I made a general smart pointer which fixes the problems of loops between std::shared_ptr's. While use is simple, I feel that my code is inefficient and clumsy. Here ...
6 votes
2 answers
509 views

Writing a C++ Matrix class

I am refreshing my C++ programming skills, and I'm currently reading the book C++ 17 by Ivor Horton. The idea is to code some naive implementations of numerical algorithms (Root finding, solving a ...
  • 335
2 votes
1 answer
469 views

Implementation of an entity component system in c++

I tried to write a simple entity component system for my game engine. Each scene will have an EntityManager. It will create entities and add or remove components from them. An entity will be destroyed ...
7 votes
5 answers
2k views

Robust program to write an array of certain data type to a binary file and read back from it (C++17)

Problem description As the title indicates, I want to be able to write to and read from a binary file safely, in the sense that I want to have full control of everything that might go wrong. Since I ...
3 votes
3 answers
171 views

Convert program arguments to std::wstring

Due to recent need I wrote a simple main function that has the goal to convert the C-style strings and arrays into a more STL-style. Then because I also had a need ...
2 votes
1 answer
68 views

C++ allocator for std::wstring_convert

In my application, I'm using std::wstring_convert to convert std::string into std::u32string....
9 votes
2 answers
718 views

Yet another minesweeper field calculator

The task is to read in a data file containing a representation of a rectangular array with '*' signifying a mine and '.' signifying the absence of one. Each such array is preceded by a row and column ...
  • 64.6k
5 votes
1 answer
143 views

C++ Mine Sweeper Attempt

Saw this question and though I wanted to try. So my version of reading Mine Sweeper: For the Online Judge Some Utilities Classes ...
  • 91.9k
4 votes
2 answers
108 views

Python's enumerate for C++

I implemented an enumerate() method for C++ containers similar to Python's enumerate to iterate through a range with an index and the actual value. I have the following questions: Does the usage of ...
1 vote
1 answer
60 views

Blocking until one or multiple signals is emitted

I've written this little helper function, that will block the current thread until any of a given list of signals is emitted by an object or until an optional timeout is reached. It can be used to ...
  • 125
2 votes
1 answer
114 views

looping over variables of heterogeneous type

These snippets are nothing special, but they remind us to sometimes loop without a for or a while loop. It is even possible to ...
  • 1,394
8 votes
0 answers
338 views

A simple Qt + MQTT doorbell application

So I built a house recently and didn't want to rely on "privacy-questionnable" systems like Google Home or Amazon whatever so I decided to build a doorbell system myself. Hardware I use a ...
  • 181
4 votes
1 answer
133 views

Cryptographic hashing class using OpenSSL's EVP interface

I have written a cryptographic hashing class named Ccksum::DigestHasher that allows the caller to select a hashing algorithm by name via OpenSSL's EVP interface. ...
's user avatar
1 vote
2 answers
130 views

Chess engine generates moves

I am currently writing a chess engine to improve my C++. I was able to improve my first results in terms of performance. (It is still really weak, but it does not lose a queen in one move) I ended up ...
  • 11
2 votes
2 answers
131 views

Creating a threadsafe, mutable, global configuration struct wrapper with C++17

I'm trying to create a relatively simple class that stores global configuration in some serializable struct, and reads/writes from/to a file. My main goal is to make this class easy to use correctly. ...
  • 153
2 votes
2 answers
72 views

A simple write-once-read-many indexed based database

I started writing a cyrptocoin from scratch, and then got sidetracked writing the database portion which I eventually turned it into its own project. Data is written to the database and then retrieved ...
  • 121
1 vote
1 answer
126 views

Typesafe implicit wrapper for C enums

This is meant to go in a vulkan.hpp-like strongly-typed wrapper for a pure C library. A wrapped enum provides back and forth implicit conversion between itself and ...
's user avatar
0 votes
1 answer
58 views

Enter the randomly displayed letter console game

The below code segments compose a simple console game where the user is prompted to enter a randomly generated letter displayed in the console. It also saves and loads user data through a .txt file. ...
4 votes
1 answer
314 views

Token class implementation with std::variant

So I've been trying to implement a Token class in C++. At first I wanted to use a simple enum class to store the Kind of the ...
  • 196

1
2 3 4 5
11