Last call to make your voice heard! Our 2022 Developer Survey closes in less than a week. Take survey.

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
1 vote
1 answer
45 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, ...
user avatar
  • 188
2 votes
1 answer
44 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 ...
user avatar
0 votes
1 answer
56 views

Decorator Pattern with member functions

Motivation: without SaveDecorator, we would have to write: ...
user avatar
  • 1,089
3 votes
1 answer
45 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 ...
user avatar
5 votes
3 answers
99 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 ...
user avatar
2 votes
1 answer
60 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 ...
user avatar
3 votes
1 answer
71 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: ...
user avatar
3 votes
1 answer
100 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 ...
user avatar
  • 45
0 votes
1 answer
44 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) ...
user avatar
  • 103
2 votes
2 answers
79 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 <...
user avatar
  • 3,302
2 votes
1 answer
69 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 ...
user avatar
9 votes
1 answer
445 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 ...
user avatar
  • 3,302
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 ...
user avatar
7 votes
5 answers
917 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 ...
user avatar
  • 25.3k
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, ...
user avatar
4 votes
1 answer
130 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 ...
user avatar
  • 331
3 votes
2 answers
153 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 ...
user avatar
  • 3,302
3 votes
0 answers
73 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 ...
user avatar
  • 3,302
2 votes
1 answer
71 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 ...
user avatar
7 votes
1 answer
200 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 ...
user avatar
2 votes
2 answers
90 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 ...
user avatar
  • 777
2 votes
1 answer
81 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...
user avatar
2 votes
1 answer
69 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,...
user avatar
  • 1,925
2 votes
4 answers
316 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. ...
user avatar
2 votes
1 answer
463 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 ...
user avatar
1 vote
2 answers
40 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 ...
user avatar
  • 3,302
2 votes
1 answer
54 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 ...
user avatar
  • 3,302
3 votes
1 answer
80 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 ...
user avatar
  • 1,925
4 votes
5 answers
1k 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: ...
user avatar
5 votes
2 answers
326 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. ...
user avatar
  • 145
3 votes
1 answer
72 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 ...
user avatar
  • 31
2 votes
3 answers
469 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 ...
user avatar
  • 145
1 vote
1 answer
70 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 <...
user avatar
  • 3,302
1 vote
0 answers
63 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 ...
user avatar
  • 11
2 votes
1 answer
120 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, ...
user avatar
  • 1,354
0 votes
1 answer
85 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 ...
user avatar
  • 3,302
2 votes
1 answer
82 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 ...
user avatar
  • 3,302
1 vote
0 answers
65 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 ...
user avatar
  • 3,302
2 votes
1 answer
93 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 ...
user avatar
  • 3,302
2 votes
1 answer
66 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 ...
user avatar
  • 3,302
7 votes
2 answers
206 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 ...
user avatar
  • 3,302
3 votes
1 answer
755 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 ...
user avatar
  • 3,302
-1 votes
1 answer
61 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 &...
user avatar
  • 1
0 votes
0 answers
58 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 "...
user avatar
4 votes
0 answers
109 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,302
1 vote
1 answer
88 views

Check if two types are the same without template instantiations

Below is my attempt to check if two types are the same without template instantiations. ...
user avatar
5 votes
1 answer
278 views

Emplace a lambda which captured a unique_ptr into container like queue

I'd like to emplace a lambda which captured a unique-pointer into a container, but it failed to compile under GCC 7.3.0 as C++17. From the error messages, it's calling the copy constructor of ...
user avatar
7 votes
2 answers
180 views

re-implementation of std::vector

I've implemented a simple vector-like structure. I would appreciate all criticism relevant to code. I have also published code under github. Here is the link to source code + unit test for most ...
user avatar
  • 73
2 votes
1 answer
115 views

Assignment function as alternative to std::tie

What do you think about this assignment "idiom"? ...
user avatar
  • 1,354
10 votes
3 answers
893 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 ...
user avatar
  • 399

1
2 3 4 5
10