Questions tagged [template]

a design structure for creating several things that are almost identical but need different values. Not template-meta-programming.

Filter by
Sorted by
Tagged with
0 votes
0 answers
19 views

Adding multiple images to a html file using Jinja2 [closed]

I am trying to load and add multiple figures from disk to a HTML file For adding a single image, I tried the following (ref.: https://stackoverflow.com/questions/35855777/jinja2-python-insert-a-images-...
  • 101
2 votes
2 answers
46 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
40 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 ...
  • 21
2 votes
1 answer
62 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(...) ...
  • 21
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
6 votes
1 answer
98 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
50 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, ...
  • 188
2 votes
1 answer
53 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
79 views

Decorator Pattern with member functions

Motivation: without SaveDecorator, we would have to write: ...
  • 1,109
3 votes
1 answer
49 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
116 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
61 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
91 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
143 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 ...
  • 55
0 votes
1 answer
45 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) ...
  • 103
2 votes
2 answers
110 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 <...
  • 3,596
2 votes
1 answer
81 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
474 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 ...
  • 3,596
18 votes
2 answers
2k 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
934 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 ...
  • 26.1k
3 votes
0 answers
33 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
154 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 ...
  • 331
3 votes
2 answers
171 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,596
3 votes
0 answers
81 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 ...
  • 3,596
2 votes
1 answer
79 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
209 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
136 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 ...
  • 779
2 votes
1 answer
99 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
89 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,...
  • 1,925
2 votes
4 answers
614 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
494 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 ...
1 vote
2 answers
43 views

A recursive_count function with recursive_depth for unwrap_level checking in C++

This is a follow-up question for A recursive_depth function for calculating depth of nested types implementation in C++ and A recursive_count Function with Unwrap Level for Various Type Arbitrary ...
  • 3,596
2 votes
1 answer
59 views

A recursive_depth function for calculating depth of nested types implementation in C++

This is a follow-up question for A recursive_count Function with Unwrap Level for Various Type Arbitrary Nested Iterable Implementation in C++. A function ...
  • 3,596
3 votes
1 answer
112 views

A predicated version of std::for_each

For reasons, I want to implement a predicated version of std::for_each. I know that, in C++20, this is made somewhat redundant or less useful, as we can use ...
  • 1,925
4 votes
5 answers
2k views

C++11 Custom Vector Implementation

This was my solution to an interview question: Q: Implement an std::vector style container (does not have to be exactly compatible) with a fixed buffer and the following requirements and restrictions: ...
5 votes
2 answers
563 views

C++ template class to calculate CRC

Here is a template class to calculate various CRC checksums. I go out my way to achieve a good C++ encapsulation for a C style code . Any advice or suggestion is welcome. ...
  • 29
3 votes
1 answer
79 views

Abstract wrapper for fundamental types

I have created this interface as part of my C++ learning path. This post inspired me a lot. The idea is to use its concrete implementations to perform some actions before and after any change of the ...
  • 31
2 votes
3 answers
754 views

C++ logger by template

If the log file is not available, then output the log message to the console. Any improvement or suggestion for this implementation for the logger by the template? Any potiencial problem that I should ...
  • 29
1 vote
1 answer
87 views

Unit Tests for the operators of image template class with Boost.Test framework in C++

This is a follow-up question for Tests for the operators of image template class in C++. As G. Sliepen's answer mentioned, I am attempting to use Boost.Test and several test cases are created with <...
  • 3,596
1 vote
0 answers
84 views

template Matrix class with Static or dynamic size

I started implementing the folowing Matrix class in order to get a better understanding of templates classes in general. For now, it lacks a lot of features, it does very basic things: addition ...
  • 11
2 votes
1 answer
186 views

splitting a tuple into N-element tuples

This nice hack should allow you to split a tuple into N-element tuples, thereby effectively splitting a tuple into pairs, triples, ... For example, this allows you to split an input parameter pack, ...
  • 1,404
0 votes
1 answer
86 views

Image pixelwise operation function with multiple inputs in C++

This is a follow-up question for Tests for the operators of image template class in C++ and A recursive_transform template function for the multiple parameters cases in C++. I appreciated G. Sliepen's ...
  • 3,596
2 votes
1 answer
85 views

A recursive_transform template function for the multiple parameters cases in C++

This is a follow-up question for A recursive_transform template function for the binary operation cases in C++. Thanks for G. Sliepen's answer. Based on the mentioned suggestion, I am attempting to ...
  • 3,596
1 vote
0 answers
68 views

A recursive_transform template function for the binary operation cases with execution policy in C++

This is a follow-up question for A recursive_transform template function for the binary operation cases in C++, A recursive_transform Template Function with Unwrap Level for Various Type Arbitrary ...
  • 3,596
2 votes
1 answer
98 views

A recursive_transform template function for the binary operation cases 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++ and A recursive_print Function For Various ...
  • 3,596
2 votes
1 answer
67 views

Tests for the operators of image template class in C++

This is a follow-up question for Two dimensional gaussian image generator in C++. Thanks for Cris Luengo's answer and JDługosz's answer. I am attempting to update the implementation of ...
  • 3,596
8 votes
2 answers
221 views

Two dimensional gaussian image generator in C++

This is a follow-up question for Two dimensional bicubic interpolation implementation in C++ and Two dimensional gaussian image generator in C. Based on user673679's answer, another file ...
  • 3,596
4 votes
1 answer
1k views

Two dimensional bicubic interpolation implementation in C++

This is a follow-up question for Two dimensional bicubic interpolation implementation in C and A recursive_transform Template Function with Unwrap Level for Various Type Arbitrary Nested Iterable ...
  • 3,596
-1 votes
1 answer
65 views

Passing a partial application as an argument of an other function with no overhead [closed]

I am trying to find a way to pass a partial application as an argument of an other application with no overhead. I think I have find a way to do it (which might be dirty). The templated structure &...
  • 1
0 votes
0 answers
63 views

Is this a good way to construct the class for a C++ template partial specialisation of a member function?

I am teaching myself c++ by doing a series of exercises. I liked the idea of working out how hash tables could be done using just the language and no std calls. I discovered that you cant do "...

1
2 3 4 5
11