Questions tagged [template]
a design structure for creating several things that are almost identical but need different values. Not template-meta-programming.
523
questions
-2
votes
0
answers
31
views
C++ template function specialisation within class template [closed]
I'm not used to template programming - much more used to inheritence & composition.
But in terms of a general solution, I'm using a tiny project to ensure a reasonable approach for using class ...
2
votes
2
answers
46
views
A recursive_minmax Template Function Implementation in C++
This is a follow-up question for A Maximum Function For Various Type Arbitrary Nested Iterable Implementation in C++. Besides the function for finding maximum, I am trying to implement ...
2
votes
0
answers
36
views
A recursive_fold_right_all Template Function Implementation in C++
This is a follow-up question for A recursive_fold_left_all Template Function Implementation in C++. Besides recursive_fold_left_all function, I am trying to ...
1
vote
1
answer
78
views
An Updated recursive_reduce_string Template Function Implementation in C++
This is a follow-up question for A recursive_reduce Template Function with Unwrap Level Implementation in C++ and A recursive_reduce_string Template Function Implementation in C++. Considering the ...
1
vote
1
answer
99
views
A recursive_reduce_string Template Function Implementation in C++
This is a follow-up question for A recursive_sum Template Function Implementation with Unwrap Level in C++, A recursive_reduce_all Template Function Implementation ...
1
vote
0
answers
70
views
An Updated recursive_transform Template Function Implementation in C++
This is a follow-up question for A recursive_transform_view Template Function Implementation and A recursive_transform_view Template Function which returns a view in C++. In those implementations ...
2
votes
1
answer
87
views
in_place_constructor helper type
recently I implemented a little helper class, which can be primarily utilized on perfect forwarding constructors.
Introduction
As a slight example, let me pull in two of the ...
0
votes
1
answer
39
views
js template engine
I am building a template engine for js and I need some help refactoring the code for fast and more efficient performance. If you can help modify or suggest some updates I'll be grateful.
...
2
votes
1
answer
81
views
A recursive_foreach_all Template Function Implementation in C++
This is a follow-up question for A recursive_fold_left_all Template Function Implementation in C++. As mentioned in G. Sliepen's answer, I am trying to implement <...
2
votes
1
answer
54
views
A recursive_fold_left_all Template Function Implementation in C++
This is a follow-up question for A recursive_sum Template Function Implementation with Unwrap Level in C++. I am trying to implement a recursive version fold_left ...
2
votes
0
answers
51
views
A recursive_depth Function Implementation with Target Type Parameter in C++
This is a follow-up question for A recursive_depth function for calculating depth of nested types implementation in C++. I am rethinking about the proposed ...
1
vote
2
answers
83
views
An arithmeticable Concept Implementation in C++
This is a follow-up question for A recursive_reduce_all Template Function Implementation in C++. As G. Sliepen's answer mentioned:
...
5
votes
2
answers
879
views
Skeleton for a command-line program that takes files in C
First. If this question is not allowed, I am sorry. Please, tell me so, and I will try to delete this. If it is, I will delete this paragraph.
Personal-ish note/Motivation
I was studying assembly ...
4
votes
1
answer
123
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
173
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
64
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
1
answer
139
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
70
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
122
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
61
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
63
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
145
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
98
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
126
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
143
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
199
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
153
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
647
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
357
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
237
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
63
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
150
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
181
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
81
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
93
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
72
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
214
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
88
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
129
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
267
views
Decorator Pattern with member functions
Motivation: without SaveDecorator, we would have to write:
...
3
votes
1
answer
112
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
303
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
70
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
611
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
344
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
59
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
595
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
221
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
519
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 ...