Questions tagged [c++]

C++ is a statically typed, free-form, multi-paradigm, compiled, general-purpose programming language. This tag should be used for any question which requires knowledge or expertise with the C++ programming language. This is a general tag which is used for any of the C++ language standards (C++98, C++11, C++17, etc.). The question should identify the compiler being used, the operating system, and which of the C++ standards is being targeted.

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

My first implementation of a linked list in C++

This is my very first implementation of a full-fledged ADT, which could potentially be use-ready. Now, I'm still learning, therefore I would like to ask you what I can do to further improve the ...
user avatar
  • 123
70 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 ...
user avatar
  • 33.2k
19 votes
5 answers
4k 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 ...
user avatar
  • 64.5k
72 votes
8 answers
13k views

Open, write and close a file

I have a small 10-liner function that writes some data to a file using an std::ofstream. I did not explicitly call .close() at ...
user avatar
  • 1,098
16 votes
7 answers
4k views

Project Euler #3 - largest prime factor

I was going through the Project Euler problem #3 and made a program to solve it. The problem is as follows: The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the ...
user avatar
2 votes
1 answer
129 views

A recursive_count_if Function For Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count Function For Various Type Arbitrary Nested Iterable Implementation in C++. Thanks to G. Sliepen's answer. Based on the mentioned suggestion, the ...
user avatar
  • 3,586
5 votes
1 answer
200 views

A recursive_transform for std::vector with various return type

This is the follow-up question for A recursive_transform Function For Various Type Nested Iterable With std::variant Implementation in C++ and A get_from_variant function in C++. Thanks to G. Sliepen ...
user avatar
  • 3,586
19 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 ...
user avatar
  • 64.5k
14 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 ...
user avatar
  • 64.5k
11 votes
4 answers
909 views

C++ string Formatter

I had an uneventful afternoon, so I thought I might try and write a string formatter. This is based on the documentation I found here. ...
user avatar
  • 91.8k
4 votes
1 answer
197 views

A Summation Function For Boost.MultiArray in C++

This is a follow-up question for A Summation Function For Arbitrary Nested Vector Implementation In C++ and A Summation Function For Various Type Arbitrary Nested Iterable Implementation in C++. I am ...
user avatar
  • 3,586
5 votes
1 answer
128 views

A Summation Function For Various Type Arbitrary Nested Iterable Implementation in C++

This is the follow-up question for A Summation Function For Arbitrary Nested Vector Implementation in C++. The following code is the improved version based on Zeta's answer. I am trying to enhance ...
user avatar
  • 3,586
2 votes
0 answers
103 views

A recursive_print Function For Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_transform for std::vector with various return type and A recursive_transform for std::array with various return type. Based on these discussion about the ...
user avatar
  • 3,586
50 votes
4 answers
31k 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 ...
user avatar
9 votes
3 answers
13k views

Linked list implemented as classes, not imperative code

As an update to previous code I've submitted: Improvements this time are mainly having everything moved to a class, before I plough on and add more functionality (I've come back to C++ after a few ...
user avatar
  • 485
15 votes
1 answer
8k views

A simple Thread Pool

A very simple Thread pool: Any work added to the pool will be executed. The destructor will wait for all work to be finished before letting the threads stop. We then join all threads before letting ...
user avatar
  • 91.8k
9 votes
3 answers
292 views

A Summation Function For Arbitrary Nested Vector Implementation In C++

I am trying to deal with some calculations on nested vector data in C++. The nested vector data may be like std::vector<long double>, ...
user avatar
  • 3,586
7 votes
1 answer
466 views

Rock-Paper-Scissors engine

Looking over Rock, Paper, Scissors. C++ from a beginning programmer prompted me to think about how I'd program this simple game in C++. The RockPaperScissors class ...
user avatar
  • 64.5k
6 votes
0 answers
165 views

C++ string Formatter Again Part-4

Previously asked here. The code is now available on GitHub. Since the previous review I have added unit tests. Since it is big it will come in a couple of parts. Part 1 | Part 2 | Part 3 | Part 4 ...
user avatar
  • 91.8k
5 votes
1 answer
91 views

A recursive_count Function For Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A Summation Function For Arbitrary Nested Vector Implementation In C++ and A Summation Function For Various Type Arbitrary Nested Iterable Implementation in C++. ...
user avatar
  • 3,586
3 votes
1 answer
78 views

A recursive_count_if Function with Automatic Type Deducing from Lambda for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count_if Function For Various Type Arbitrary Nested Iterable Implementation in C++ and A recursive_count_if Function with Specified value_type for Various ...
user avatar
  • 3,586
3 votes
0 answers
184 views

C++ Crypto: Part 4- Scram

Looking around for modern Crypto libraries. Could not find anything good. I know I probably did this all wrong so work with me here. There will be four different reviews for four structures that build ...
user avatar
  • 91.8k
3 votes
0 answers
60 views

A recursive_count_if Function with Specified value_type for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count_if Function For Various Type Arbitrary Nested Iterable Implementation in C++. Thanks to Quuxplusone's answer and G. Sliepen's comments. Based on the ...
user avatar
  • 3,586
8 votes
1 answer
114 views

Nisse Server: Part 1 Helper Functions

Getting close to a release of generic server. So a couple of reviews will be coming this way over the next few weeks. Stating with the lowest levels and working up to the main server. The result is ...
user avatar
  • 91.8k
3 votes
1 answer
179 views

A recursive_transform Template Function Implementation with std::invocable concept in C++

This is a follow-up question for A recursive_transform for std::vector with various return type, A recursive_transform Template Function with Execution Policy, A recursive_count_if Template Function ...
user avatar
  • 3,586
3 votes
1 answer
57 views

A recursive_count_if Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count_if Function For Various Type Arbitrary Nested Iterable Implementation in C++, A recursive_count_if Function with Specified value_type for Various ...
user avatar
  • 3,586
2 votes
1 answer
120 views

A recursive_transform Template Function with Execution Policy

This is a follow-up question for A recursive_transform for std::vector with various return type, A recursive_transform Function For Various Type Nested Iterable With std::variant Implementation in C++ ...
user avatar
  • 3,586
26 votes
6 answers
105k 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 ...
user avatar
  • 431
36 votes
6 answers
6k views

Parser written in PHP is 5.6x faster than the same C++ program in a similar test (g++ 4.8.5)

I'm absolutely dumbfounded by this. I was trying to demonstrate to myself how much faster C++ is than even modern PHP. I ran a simple CSV parsing program in both that have the same output. The CSV ...
user avatar
  • 461
33 votes
1 answer
6k views

JSON Serializer

Carrying on from: Yet another C++ Json Parser Yet another C++ Json Parser (Recursive) All the code is available from git hub: ThorsSerializer but only reviewing a small section here. The idea is ...
user avatar
  • 91.8k
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): ...
user avatar
  • 91.8k
14 votes
1 answer
2k views

Stream that opens an HTTP GET and then acts like a normal C++ istream

Needed a quick stream to get JSON objects. ...
user avatar
  • 91.8k
6 votes
2 answers
138 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 ...
user avatar
  • 533
3 votes
1 answer
152 views

A recursive_transform Function For Various Type Nested Iterable With std::variant Implementation in C++

This is a follow-up question for A TransformAll Function For Various Type Arbitrary Nested Iterable Implementation in C++. The following code is the improved version based on G. Sliepen's answer. In ...
user avatar
  • 3,586
6 votes
1 answer
911 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, ...
user avatar
  • 18.9k
5 votes
1 answer
84 views

Nisse Server: Part 3 Stream Layer

Getting close to a release of generic server. Nisse Server: Part 1 Helper Functions Nisse Server: Part 2 Socket Layer Here is the stream layer code. This basically provides a ...
user avatar
  • 91.8k
5 votes
2 answers
115 views

Nisse Server: Part 2 Socket Layer

Getting close to a release of generic server. Nisse Server: Part 1 Helper Functions Here is the socket layer code. This has previously been reviewed here. But there have been some changes. Socket.h ...
user avatar
  • 91.8k
5 votes
0 answers
123 views

A recursive_transform Template Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++ and A recursive_transform Template Function Implementation with ...
user avatar
  • 3,586
5 votes
1 answer
206 views

Overhauled tokenizer for markargs

In the previous post I've started writing a tokenizer for my imaginary programming language (which I decided to name markargs; trivia at the end of the post). Problem definition: Read the line and ...
user avatar
  • 9,171
3 votes
1 answer
187 views

std::array and std::vector Type Arbitrary Nested Iterable Generator Functions Implementation in C++

This is a follow-up question for the previous questions about recursive functions, including A Summation Function For Arbitrary Nested Vector Implementation In C++, A recursive_count_if Function For ...
user avatar
  • 3,586
2 votes
1 answer
86 views

A recursive_transform Template Function Implementation with std::invocable Concept and Execution Policy in C++

This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++ and A recursive_transform Template ...
user avatar
  • 3,586
2 votes
1 answer
90 views

An arithmetic_mean Function For Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A recursive_count Function For Various Type Arbitrary Nested Iterable Implementation in C++ and A Summation Function For Boost.MultiArray in C++. I am trying to ...
user avatar
  • 3,586
1 vote
1 answer
65 views

invocable_traits v4

Update: there is a new version of this code: v5 is posted here Goal: implement traits that for anything callable return its arity, return type and the argument types. Since pointers to data members ...
user avatar
48 votes
1 answer
7k views

Yet another C++ JSON parser

This is a framework for a JSON parser I put together last night. Any comments appreciated. JsonLexer.l: Breaks the input into lexemes JsonParser.y: Understands the language syntax JsonParser.h: ...
user avatar
  • 91.8k
30 votes
2 answers
57k views

Custom iterator for a linked list class

I have made a LinkedList class. This is a singly-linked-list and I want to make a forward_iterator for this class without using ...
user avatar
  • 403
13 votes
2 answers
21k 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/...
user avatar
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 ...
user avatar
  • 3,577
12 votes
1 answer
2k views

Macro to build type declaration

These are some macros to help build a traits class (for the parser/printer classes I am building). Traits.h ...
user avatar
  • 91.8k
10 votes
3 answers
5k views

Typelist with extractor

The purpose of the code is to store arbitrary number of types. The type can be extracted from it using Extract template, which uses template recursion to get the needed type. There will be compilation ...
user avatar
  • 9,171
9 votes
3 answers
19k views

Simple string joiner in modern C++

(See the next iteration.) I have this small template function for conveniently dumping a sequence into a string such that there is a delimiter between two consecutive elements, and no such after the ...
user avatar
  • 26k

1
2 3 4 5
23