Questions tagged [c++20]

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

Filter by
Sorted by
Tagged with
4
votes
1answer
111 views

Efficient vector-like polymorphic container which retains type information

This is my attempt of implementing an efficient, cache-friendly, vector for polymorphic objects. From now on I will refer to "virtual functions" as functions which are dependent on an object'...
3
votes
1answer
71 views

Function to use projections in legacy algorithms [closed]

I love the "projections" introduced by the ranges library, and I would like to use them in algorithms that haven't been rangeyfied yet. I had the idea of using them through a function like ...
2
votes
2answers
120 views

Partial function composability in C++

Similar to Partial Function composability in Haskell, I've attempted to implement partial function composability in C++20 via C++ concepts. More details about the problem(for which my solution is ...
10
votes
3answers
787 views

C++20 Vector2D Template

Pretty simple 2-Dimensional Vector template with operators and two utility functions making use of C++20 concepts. Header-only templates, function inlining and operator overloading, etc. is not ...
3
votes
1answer
45 views

Piping operator in c++

I wrote a simple piping operator in c++. I just wanted to make sure that my code was robust, modern c++ code, and made correct use of perfect forwarding. Here's the code: ...
5
votes
1answer
92 views

Generic Visitor pattern library for polymorphic virtual class hierarchies

Inspired by this cppcon talk from Fedor Pikus about design patterns and some real-world need I implemented a library that allows the user to add a generic visitor pattern capabilities to class ...
5
votes
1answer
68 views

Binary IO inspired by struct pack

About I'm writing a header-only template library for helping with binary IO. It is inspired by pack-d, which is in turn inspired by Python's struct module. I've only finished the output part and ...
10
votes
3answers
335 views

C++20 standard compatible vector

I decided to write my own vector class template for learning purposes. My main goal was a correct interpretation of C++20 standard (as of n4810). I took some liberties and decided to use concepts ...
1
vote
1answer
60 views

c++ multithreaded message broadcaster using callbacks

note: This is an updated design after a previous review round. I have written a class that handles listeners registering callbacks to receive messages. Registered callbacks can be replaced or removed. ...
0
votes
1answer
80 views

Best practice for factory pattern in c++?

I'm implementing a simple data reader to get image sequences from either a pre-recorded video file (In my case ROS bag file), or a camera device (In my case Intel Realsense). Basically I intend for ...
0
votes
0answers
39 views

A recursive_count Function with Unwrap Level 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++, A recursive_count_if Function with Unwrap Level for Various Type Arbitrary ...
1
vote
0answers
55 views

A Function Applier for Applying Various Algorithms on Nested Container Things in C++

This is a follow-up question for A recursive_replace_if Template Function Implementation in C++, A recursive_copy_if Template Function Implementation in C++, A recursive_count_if Function with Unwrap ...
2
votes
1answer
135 views

C++ callback multithreaded, can unregister itself

update: a new version of this code is posted here With this post, i would like to 1) ask for feedback on below code as it stands: do i apply all best practices for c++20? is it safe? is my way to ...
1
vote
0answers
45 views

A recursive_replace_copy_if Template Function Implementation in C++

This is a follow-up question for A recursive_copy_if Template Function Implementation in C++. Besides the recursive version std::ranges::copy_if, I am trying to ...
2
votes
1answer
46 views

A recursive_copy_if Template Function Implementation in C++

This is a follow-up question for A recursive_transform for std::vector with various return type and A recursive_transform Template Function Implementation with std::invocable concept in C++. Besides ...
6
votes
1answer
33 views

Filter out comments in Delphi source code

Today I am working on refactoring and documenting some ancient Delphi code. In that language, which is derived from Pascal, there are three forms of comments: ...
2
votes
1answer
47 views

A recursive_transform Template Function Implementation with recursive_invoke_result_t and std::ranges::transform in C++

This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++, A recursive_transform Template Function Implementation with std::invocable ...
0
votes
0answers
67 views

Various Type Test Cases for recursive_transform Template Function in C++

This is a follow-up question for Nested std::deque and std::vector Type Test Cases for recursive_transform Template Function in C++, A recursive_transform Template Function Implementation with ...
3
votes
1answer
67 views

C++20 “FixedArray” Container (dynamically allocated fixed-size array)

I've wrote a FixedArray to fit seamlessly (function-wise) with the default C++ containers, including working with algorithms/etc. It is a dynamically allocated, but fixed size array. Code ...
6
votes
1answer
113 views

2D Matrix in C++20 and Strassen's algorithm

I wrote C++20 implementation of a simple matrix class and its usage in Strassen's \$O(n^{lg_2{7}})\$ matrix multiplication algorithm. Live demo: https://wandbox.org/permlink/JaSC8fQccFbcl1QY (For n = ...
4
votes
2answers
90 views

Nested std::deque and std::vector Type Test Cases for recursive_transform Template Function in C++

This is a follow-up question for A recursive_transform Template Function Implementation with std::invocable concept in C++, A recursive_transform Template Function ...
5
votes
2answers
79 views

sum of multiples by 3 or 5 using ranges

This program calculates the sum of all integers in the range \$[1, 1000)\$ which are multiples of either 3 or 5 or both. Inspired by x86-64 Assembly - Sum of multiples of 3 or 5 the other day, and ...
2
votes
1answer
67 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 ...
4
votes
3answers
359 views

Calculate the centroid of a collection of complex numbers

In working on another problem, one component I needed was to calculate the centroid of a collection of complex objects. The well-known way to calculate this is to simply average the real and ...
3
votes
1answer
79 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++ ...
2
votes
1answer
96 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 ...
2
votes
1answer
59 views

A recursive_count_if Template Function with Execution Policy in C++

This is a follow-up question for Avoiding requires clause if possible on a series recursive function in C++ and A recursive_count_if Function with Automatic Type Deducing from Lambda for Various Type ...
1
vote
1answer
70 views

Avoiding requires clause if possible on a series recursive function in C++

This is a follow-up question for A recursive_transform_reduce Function for Various Type Arbitrary Nested Iterable Implementation in C++, A recursive_count Function For Various Type Arbitrary Nested ...
2
votes
1answer
74 views

A recursive_transform_reduce Function for Various Type Arbitrary Nested Iterable Implementation in C++

This is a follow-up question for A population_variance Function For Various Type Arbitrary Nested Iterable Implementation in C++. Thanks to G. Sliepen's answer, I am trying to implement the mentioned <...
2
votes
1answer
72 views

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

This is a follow-up question for A Summation Function For Various Type Arbitrary Nested Iterable Implementation in C++, An arithmetic_mean Function For Various Type Arbitrary Nested Iterable ...
6
votes
1answer
128 views

A Various Container Type Arbitrary Nested Iterable Generator Function Implementation in C++

This is a follow-up question for std::array and std::vector Type Arbitrary Nested Iterable Generator Functions Implementation in C++ and std::deque and std::list Type Arbitrary Nested Iterable ...
7
votes
1answer
119 views

Non-nested std::deque and std::list Generator Function for arithmetic_mean Function Testing in C++

This is a follow-up question for A non-nested test_vectors_generator Function for arithmetic_mean Function Testing in C++ and An arithmetic_mean Function For Various Type Arbitrary Nested Iterable ...
1
vote
0answers
46 views

A non-nested test_vectors_generator Function for arithmetic_mean Function Testing in C++

This is a follow-up question for An arithmetic_mean Function For Various Type Arbitrary Nested Iterable Implementation in C++. As Toby Speight's answer mentioned, some self-checking unit tests are ...
7
votes
3answers
618 views

Array based queue implementation with C++20

I implemented a queue that holds elements on an array as underlying data type: ...
3
votes
1answer
82 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 ...
1
vote
0answers
35 views

std::deque and std::list Type Arbitrary Nested Iterable Generator Functions Implementation in C++

This is a follow-up question for std::array and std::vector Type Arbitrary Nested Iterable Generator Functions Implementation in C++ and the previous questions about recursive functions, including A ...
3
votes
1answer
144 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 ...
2
votes
1answer
44 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 ...
2
votes
1answer
66 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 ...
6
votes
1answer
68 views

Compiletime (constexpr) Differential Equation System Description for use in Optimal Control

Background In the field of optimal control, it is part of everyday business to solve ordinary differential equations numerically. A differential equation system or dynamic system describes e.g. the ...
10
votes
2answers
805 views

Floyd's cycle-finding algorithm

I am writing a piece of code for some students and I came up with the following implementation of Floyd's algorithm for finding cycles in linked lists. I was wondering if there are ways I can improve ...
1
vote
0answers
53 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 ...
2
votes
1answer
94 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 ...
4
votes
1answer
71 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++. ...
6
votes
1answer
443 views

C++20 sort of infinite “Consumer-Producer”

I think I can summarize the idea to the Producer-Consumer problem, with some modifications. And I think I misused the term "Producer" (it depends from which point of view :)) An infinite ...
5
votes
1answer
123 views

Template Metaprogramming - Multidimensional Vector Declaration

[EDIT] The question has been edited. Please make sure to read the summary at the end of the post. If you'd like me to make a new post with a cleaner explanation and better examples, tell me to do so ...
2
votes
1answer
59 views

A ones Function for Boost.MultiArray in C++

This is a follow-up question for An Element-wise Increment and Decrement Operator For Boost.MultiArray in C++ and A recursive_transform Template Function for BoostMultiArray. I am trying to implement ...
10
votes
1answer
208 views

Two constexpr ceil functions

ceil_constexpr is is based on: https://stackoverflow.com/questions/8377412/ceil-function-how-can-we-implement-it-ourselves/8378022#8378022 ceil_constexpr2 is a simpler version that takes advantage of ...
1
vote
1answer
59 views

An Element-wise Increment and Decrement Operator For Boost.MultiArray in C++

This is a follow-up question for A recursive_transform Template Function for BoostMultiArray and An Add/Minus Operator For Boost.MultiArray in C++. Besides the add / minus operator for Boost....
2
votes
1answer
66 views

A recursive_transform Template Function for BoostMultiArray

This is a follow-up question for A Sine Template Function For Boost.MultiArray in C++, A recursive_transform for std::array with various return type, A recursive_transform for std::vector with various ...