Questions tagged [template]
a design structure for creating several things that are almost identical but need different values. Not template-meta-programming.
512
questions
4
votes
1
answer
85
views
Tokeniser which yields a Range of string views
In my answer to string_view tokenizer function template I suggested that a flexible tokeniser would yield a Range that could be iterated over. This is my implementation of such a tokeniser.
...
2
votes
2
answers
97
views
Basic pygame program template
I have a basic pygame program that I use at the start of every project that involves pygame. The idea is every time I start a project that involves pygame I can copy and past and I can immediately ...
1
vote
0
answers
37
views
A recursive_reduce Template Function with Unwrap Level Implementation in C++
This is a follow-up question for A recursive_sum Template Function Implementation with Unwrap Level in C++ and A recursive_reduce_all Template Function ...
2
votes
0
answers
50
views
A recursive_reduce_all Template Function Implementation in C++
This is a follow-up question for A recursive_sum Template Function Implementation with Unwrap Level in C++ and A recursive_unwrap_type_t Struct Implementation in C++. Considering the answer provided ...
1
vote
0
answers
43
views
A recursive_unwrap_type_t Struct Implementation in C++
This is a follow-up question for A recursive_sum Template Function Implementation with Unwrap Level in C++. As G. Sliepen's answer mentioned, I am trying to implement a recursive struct for retrieve ...
2
votes
1
answer
93
views
A recursive_sum Template Function Implementation with Unwrap Level in C++
This is a follow-up question for A Summation Function For Various Type Arbitrary Nested Iterable Implementation in C++ and A recursive_transform_view Template Function Implementation. In the previous ...
1
vote
0
answers
58
views
DOM manipulating that I called Framework
I'm building a framework like this that can turn SASS-like code into CSS, a template engine like Mustache, a DOM manipulator like React, and a router to add a single page app, and I'm having a ...
0
votes
0
answers
44
views
Generate INSERTs from function parameters with jinja2
I'm writing unit-tests with pytest for sqlite database and reporting functions and I need to arrange them by inserting minimal ...
2
votes
1
answer
134
views
Using Ada's access type and generics to solve an ODE
This post is linked to Ada: Convert float to decimal
I have produced Ada codes which uses the Euler algorithm Euler method to solve an ordinary differential equation. The codes given below are working ...
0
votes
1
answer
82
views
The usages of make_view Template Function in C++
This is a follow-up question for A recursive_transform_view Template Function which returns a view in C++. I am trying to revise the structure of recursive_transform...
2
votes
2
answers
94
views
A recursive_transform_view Template Function which returns a view in C++
This is a follow-up question for A recursive_transform_view Template Function Implementation. Following the suggestions mentioned in G. Sliepen's answer:
Of course, it might be interesting in itself ...
3
votes
2
answers
123
views
A recursive_transform_view Template Function Implementation
This is a follow-up question for A recursive_transform Template Function with Unwrap Level for std::array Implementation in C++. Considering the suggestion mentioned in Davislor's answer, I am trying ...
1
vote
1
answer
51
views
A recursive_transform Template Function with Calling reserve for Performance Improvement
This is a follow-up question for A recursive_transform Template Function with Unwrap Level for std::array Implementation in C++. Following the suggestion mentioned in G. Sliepen's answer, the function ...
3
votes
2
answers
125
views
A recursive_transform Template Function with Unwrap Level for std::array Implementation in C++
This is a follow-up question for A recursive_transform Template Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++. I am following the suggestions proposed by ...
3
votes
1
answer
109
views
Utility IOC Container
This is an inversion-of-control object store. It is meant to be for a multithreaded application where it can load components at start-up based on complex environmental setup,
Worker threads can ...
6
votes
2
answers
452
views
Dynamically allocated N-dimensional array in c++
I've seen a few implementations of N-Dimensional arrays in C++. This is the first time I've worked with them and wanted to get some opinions on my implementation.
...
5
votes
1
answer
116
views
Implement scope_exit
I want to use the scope_exit class but my compiler/standard library (clang++-16 with libc++) don't support it. Until they do I wanted an implementation. I found a ...
2
votes
1
answer
152
views
Templated state machine
I decided to try a hand at writing a simple state machine. The StateMachine class accepts any number of classes as template arguments, along with a base class. The ...
1
vote
1
answer
56
views
Find probable primes with maximum size of n bits
I created the following program to calculate probable primes with a maximum number of bits. It works as expected but I'm sure there must be a better way to implement ...
1
vote
1
answer
114
views
A greedy approach to the Knapsack problem with C++ templates
The assignment is to be implemented on the following instructions:
You are to write a Knapsack class and the main() to support and
demonstrate the functionality required here.
A function generate(int)...
2
votes
2
answers
72
views
Template Complex class
I have created a class Complex which represents a complex number of any arbitrary arithmetic type. Overloads are given for the 4 common functions, addition, ...
2
votes
1
answer
60
views
Ring buffer for non-trivial types
I tried to explain in detail everything there should be of concern regarding this particular implementation, and non-code body turned out quite long, scroll down if you just want to read the ...
2
votes
1
answer
71
views
Absolute value meta programming
I am implementing a generic absolute value function that handles signed and unsigned integer values correctly over the input type's domain. The std::abs(...) ...
2
votes
2
answers
70
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
...
6
votes
1
answer
143
views
MadLibs builder
This is actually my version of a project I'm giving to my class of High School juniors. I'm not the greatest programmer and also a new teacher so I was hoping someone could check out this code and ...
1
vote
1
answer
81
views
Verified downcasting if RTTI is active
In an application that uses heavily polymorphic classes, I have often the need to downcast a pointer or a reference to the correct derived class. They should always be of the correct derived class, ...
2
votes
1
answer
97
views
std::unique_ptr adapter class template for libgit2 objects
I'm working on a personal project to build an open-source gui for git. I'm hoping to learn a lot from the project, and maybe produce something useful for folks as I do.
I'm making use of libgit2 to ...
0
votes
1
answer
143
views
Decorator Pattern with member functions
Motivation: without SaveDecorator, we would have to write:
...
3
votes
1
answer
76
views
checked conversion function for C++20
Similar to C++ int_cast<> function for checked casts?, but C++20, and with target type deduced from context.
The goal is to implement a runtime check that the value being converted can be ...
5
votes
3
answers
219
views
Generic exponential damping to smooth noisy signals
Exponential damping is a type of "moving average", but it's not an arithmetic mean. The latter has the disadvantage that it requires storage of the last N ...
2
votes
1
answer
63
views
Generic "running averager"
The basic "running averager" is familiar, both in embedded as well as real-time applications such as games, eg for fps. This algorithm is implemented in many microcontrollers (notably the ...
3
votes
1
answer
316
views
function template for string_view-to-integer conversion
I want to make the following function a function template that supports all the integral types:
...
3
votes
1
answer
271
views
Resume Builder using Jinja Templates and HTML
I have attempted to hack together a CV/Resume builder and I would like a review. The aim is to output a styled PDF containing dynamic fields. I have taken a simple HTML file, an arguably bloated CSS ...
0
votes
1
answer
58
views
Class accepting data input by variable, function pointer or lambda
Background
I am writing a library that takes some data from the user and works with it. I was experimenting with ways to allow users to provide the data by the following methods:
As a (global) ...
2
votes
2
answers
452
views
Checking image size in C++
This is a follow-up question for 3D Inverse Discrete Cosine Transformation Implementation in C++. After checking G. Sliepen's answer, I am trying to update the part of width and height checking of <...
2
votes
1
answer
139
views
callable_traits implementation
Update: there are new versions of this code: v2 is posted here, v3 is posted here and v4 is posted here
Goal: implement traits that for anything callable return its arity, return type and the ...
9
votes
1
answer
503
views
3D Inverse Discrete Cosine Transformation Implementation in C++
This is a follow-up question for 3D Discrete Cosine Transformation Implementation in C++. In this post, I am trying to follow user17732522's answer to update ...
21
votes
2
answers
3k
views
Python - Tkinter - periodic table of chemical elements
Inspired by a question on StackOverflow I decided to code a GUI that is simple, efficent and can be used in other projects as well. I wanted to share this code since it probably is usefull to other ...
7
votes
5
answers
963
views
Checking whether a string is a permutation of a palindrome in C++20 - follow-up
This post is the follow-up of Checking whether a string is a permutation of a palindrome in C++20.
So, what's new? Well, nothing else except that the procedure is now generic and accepts all ...
3
votes
0
answers
36
views
ANTLR4 grammar for tags substitution
I want your criticism of the following ANTLR4 grammar intended for use in templating engine of sorts. Its task is to look through (presumably rather short) potentially multiline piece of plaintext, ...
4
votes
1
answer
301
views
C++ bond mathematics calculator
I have written a program in C++ that processes financial bond mathematics, making extensive use of the valarray class, so that mathematical functions and operations ...
3
votes
2
answers
205
views
Manhattan distance calculation between two images in C++
This is a follow-up question for Two dimensional gaussian image generator in C++ and Image pixelwise operation function with multiple inputs in C++. For learning C++20 and researching purposes, I am ...
3
votes
0
answers
116
views
Order guaranteed recursive_transform template function implementation with execution policy in C++
This is a follow-up question for A recursive_transform Template Function with Execution Policy, A recursive_transform Template Function Implementation with std::invocable Concept and Execution Policy ...
2
votes
1
answer
137
views
C++ template and inheritance - Generic Sqrt Decomposition
So I tried implementing a easily extendable solution for Sqrt decompostion, I deduced that only identity value, operation and block update logic change and rest of the code is same. So i created 3 ...
7
votes
1
answer
234
views
Custom implementation to provide an immutable range of a container without copying it
I needed to pass a const reference to part of a std::vector without copy. I posted the previous version in my earlier question, thank you for the great support! As ...
2
votes
2
answers
204
views
Using JS Template Literals as for a simple Templating Engine
There are many template engines but my question is: Why do they still exist? Can we not achieve the same job with readily available JavaScript Template Literals?
So influenced from this blogpost, I ...
2
votes
1
answer
118
views
Gallery template class
I have created a template class Gallery which is intended to be used as a container for objects. I used a private member of type...
2
votes
1
answer
154
views
A proxy class as a generic replacement for getters and setters v2
Have you ever written proxy objects, instead of using a setter and a getter method? In that case, I'm interested in your opinion on the following design for a templated proxy.
This is a second version,...
2
votes
4
answers
1k
views
Single-linked-list in C++ with iterators
I'm implementing a single linked list as close as it could be to std::forward_list. I would welcome a review and also more suggestions on what to test additionally.
...
2
votes
1
answer
686
views
Generic Event class
C++ Event class
From the desire of having a callback function which includes a void* userdata argument, I've made this generic event class.
It is tested and working, but some desired features are ...