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
6
votes
1answer
74 views

Smart pointer like implementations

For educational purposes I implemented standard library smart pointers like class templates. They are definitely not a full replacement for the library classes but I'd like to get some comments on the ...
6
votes
1answer
544 views

Generic Producer-Consumer in C++11

I wrote the following simple 1 producer - 1 consumer problem, in attempt to learn some C++11 threading / generics. ...
6
votes
1answer
71 views

My first (simple) template that does more than storing a value of type T

I just decided to get a bit more acustomed to using templates. Maybe this is a stupid question, but in my experience in C++ there is always some pitfall lurking aroung the corner. Thus I prefer the ...
6
votes
1answer
114 views

Text substitution templating function

In a recent interview I was asked to solve the below problem. Problem: Given a string with variables in them, e.g. "I am a string with {{ variable }} in them" ...
6
votes
1answer
870 views

Factory template method for generalized functors

(A quick note on terminology: I use 'generalized functor' to refer to a functor that can be initialized from any callable entity, similar to the definition from Alexandrescu's Modern C++ Design. I use ...
6
votes
1answer
1k views

Image Processing Pipeline

I'm currently toying around with some Computer Vision algorithms and always wanted to learn more about templates, so I came up with the idea to build a templated Image Processing Pipeline. I want the ...
6
votes
1answer
664 views

Signals & Slots implementation using Templates

I have written this code to handle events in my game engine. I guess the naming was inspired by Qt Signals & Slots, though I have never used Qt before. It might be similar. Anyways, I think it ...
6
votes
1answer
473 views

Helper functions to perform simple token replacements in a string

This script provides function T9r, which has some methods to detect, parse and replace tokens "{{ some_token }}" in a string with properties on an object. My use case, to have "composable" json ...
6
votes
1answer
333 views

Views and ranges for tuple-like objects

This interesting idea came up when I was designing the for_each for tuple-like objects in this post. The for_each in that post ...
6
votes
1answer
198 views

Custom PHP Templating System

I recently decided to see if I could make a functioning templating system. It works, but I feel like it is not all that great. What I'm looking for here is just general critique or ideas to improve. I'...
6
votes
1answer
1k views

Type erasure and deferred function calls for any function

1. Description 1.1. Functionality The objective of these types is to provide type erasure for any function while maintaining the ability to provide a return value through a combination of ...
5
votes
2answers
131 views

What might be another way to test if int is 32 bits wide at compile time?

Below is code that will compile when INT_MAX is equal to 232. It will generate a compiler error when INT_MAX is not equal to 232....
5
votes
1answer
166 views

(Optionally Concurrent) FIFO

Based on Concurrent FIFO in C++11 and my review I implemented a queue and its concurrent pendant. Is there anything left to improve regarding clarity, usability, code-style, lock-times or general ...
5
votes
2answers
176 views

Is there a circular reference in a set of template substitutions?

I have a configuration engine that allows the user to specify a dictionary with text templates (read from a JSON file) where each placeholder like {x} can be ...
5
votes
1answer
656 views

Dereference template class

Usually, C++ standard library algorithms have two versions, e.g.: ...
5
votes
2answers
240 views

C++ TemplateClass

I have written a (dynamic) TemplateArray class, for purposes to be included as a baseline for a library I am working on, and I would like feedback on any of the ...
5
votes
2answers
102 views

add_const or remove_const based on another type

Here is a type trait which - I feel - could fit in std next to std::add_const and ...
5
votes
2answers
172 views

Test if a binary tree satisfies the BST property

I implemented code logic provided in the EPI book to determine if a binary tree is a BST. There were two approaches, therefore I used polymorphism for the common parts. I'm also using templates. I ...
5
votes
1answer
796 views

Universal reference in a class template

I'm writing a templatized container and wanted to use an universal reference for the Add(T&& object) function. Check out isocpp if you need an update on ...
5
votes
3answers
940 views

Simple wrapper for member function pointers with known signature

I always wanted to know how to pass member functions as arguments, and then I stumbled across templates that could automatically deduce types, and so I rejoiced! This is used in a Publisher-Subscriber ...
5
votes
2answers
148 views

C++ wrapper class to mimic a C array's brace initialization

I have an inheritance class that mimics the behavior of C style array's brace initialization by using a class template that has a variadic constructor but the template itself is not a variadic ...
5
votes
1answer
327 views

Multi dimensional dynamic array using operator []

Context: I have already seen different implementation of multi-dimensional arrays, but most of them use that kind of access arr(i, j, k) while I find more natural <...
5
votes
1answer
749 views

Simple c++ triple class to mimic pair for use with uniform initialization

I'm trying to create a simple triplet class, but the more I look at the implementation of std::pair the more I feel like I'm missing important details. What I have ...
5
votes
2answers
3k views

Fixed size Memory Pool Implementation

Here is an attempt at implementing a fixed size Memory Pool1: pool.h ...
5
votes
2answers
140 views

Attempt at templates by creating a class for N-dimensional mathematical vectors

Originally I had tried to implement this topic after having learned about Inheritence and posted it on here, but that forced complexity and the main suggestion was that this was ideal for templates. ...
5
votes
2answers
2k views

Small PHP framework template library

The following is a new question based on answers from here: Small MVC for PHP I have written a small template library that I would like some critiques on, located here. If you are looking for where ...
5
votes
1answer
48 views

Emulating Virtual Registers Part 3

Forward This is a continuation of my work in progress and the last iteration that I posted can be found here. I have designed a compact class template that uses SFINAE with constructor delegation to ...
5
votes
1answer
745 views

Thread-Safe Variadic Printing Function

Printing to stdout is thread-safe in many systems when using printf or std::cout, but not in ...
5
votes
1answer
188 views

Generic container assignment

For setters that set a member collection, I write template functions so as to accept any collection type as input: ...
5
votes
1answer
129 views

Emacs module that generates templates for my blog's static site generator

I wrote a simple emacs module that generates standard templates that I use for my blog's static site generator. ...
5
votes
1answer
851 views

Simple Tree C++ implementation

I've done this simple c++ assignment. The homework was "Design a Tree class that allows insertion of nodes and visit of the graph". What do you think of the style/design I used? I chose to store in ...
5
votes
1answer
343 views

C++ Template Matrix Class - WIP

I've created simple matrix class in c++ and I would like to know what you think about the code. I've left the implementation in header file for simplicity for now. The class is not finished yet, it ...
5
votes
1answer
1k views

Modular Visitor Pattern

Motivation I created this because the Visitor pattern felt like the most appropriate, but I also wanted to satisfy the Open/Closed principle with respect to the logic when visiting specific node ...
5
votes
1answer
609 views

Fixed capacity unordered_map

I have a need for a container that behaves like an unordered_map, but has a fixed capacity, and an eviction policy where the least recently inserted key-value pair ...
5
votes
1answer
3k views

A trait class to detect whether a template is specialized for a given type

Today's question will just be about a small utility that I needed at some point for one of my projects: a template to detect whether a template is specialized for a given type. The utility uses ...
5
votes
2answers
78 views

First WordPress template

I wrote my first template, but didn't include any styling. What do you think? What's good what's bad? ...
5
votes
1answer
202 views

C++ Nullable template class

Today I implemented a C++11 template class which allows for Nullable types. The reason for this is that std::optional is not yet available, (I use C++11/14) and I wanted to practice a bit, so I ...
5
votes
1answer
2k views

Template Method Checker

I have written some template helpers to check if a class has a certain method with a certain signature. The code is based on this answer. I attempted to extend it for generic methods. An important ...
5
votes
1answer
103 views

Simplifying a class template

I wrote this code over night for a little project that my friend and I have been working on. This class template was created over a year ago during as a class assignment for C++ programming. I ...
5
votes
1answer
2k views

Wrap function pointers in template classes

I'm working on a C++ library for Arduino and other embedded systems. I'm currently working on wrapping up function pointers and member-function pointers into two C++ template classes (function and ...
5
votes
1answer
344 views

JavaScript module to render and handle a form to add users

I recently switched to modular JavaScript and really like the idea of having the state of your application in JavaScript and not in the DOM. I want to know if what I am doing is considered best ...
5
votes
0answers
409 views

Console Command module (in-game console or base for script engine)

I've created a console/terminal command handling module that allows the programmer to bind functions to a command name and later execute them from std::string. What's new is that it handles most stuff ...
4
votes
3answers
180 views

Basic binary number container

Summary: a templated class, whose main purpose is to store a binary representation of a decimal number. I choose array of booleans as a storage, since bitset was forbidden. One of the requirements was ...
4
votes
2answers
147 views

Detecting if an element is found inside a container

I just wrote this template to detect if a given element is found inside a container: ...
4
votes
3answers
130 views

Generically encapsulating random generators and distributions into a class template

I previously had a set of classes in one of my older libraries for working with the random number generators and distributions that was written when Visual Studio 2008 - 2010 were commonplace and ...
4
votes
2answers
58 views

Header-only variadic console output and runtime input validation in C++ using templates

Template IO Module This is a single-file, header-only input validation with two variadic output functions. One output function simply inserts a new line char after every output and the other one ...
4
votes
2answers
427 views

Doubly linked list std::unique_ptr template class implementation

Inspired by the talk of Herb Sutter in CppCon2016, I decided to make a doubly linked list using templates, smart pointers, and raw pointers (for back-pointers, having a cycle of ...
4
votes
3answers
157 views

Using a template to cycle through a sequence of containers

I'm trying to implement a template that takes a container as parameter. The template has a getnext method that cycles through the elements in the parameter. Take ...
4
votes
2answers
110 views

C++ Pixel/Array manipulation libs

I was tired to always perform pixel manipulation one by one, so I started to create my own templated header to perform computation over pixel (RGB, or RGBA), but I also make it for ND for some cases. ...
4
votes
1answer
109 views

A basic multi-dimensional array

I have been lurking on the C++ side of stack-overflow only long enough to know there are a lot of beginners and intermediate programmers baffled by multi-dimensional arrays. I've seen a lot of ...