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
102 views

Simple bash script creates apache2 virtualhost config for subdomain

Simple bash script to create apache2 virtualhost for localhost. Can be used for public subdomains on developer server with changes - "replace .localhost". Tested on Ubuntu, but should work where ...
6
votes
2answers
2k views

Thread-safe Phoenix Singleton class template with Boost

I've implemented the phoenix-singleton as a class template with boost inspired by Modern C++ Design. The code compiles fine with MSVC 2013 - and it seems to work, but I'm new to multi-threaded ...
6
votes
1answer
1k 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
669 views

Bitfield class and Register depiction

For a few months now I have been working with an ARM CPU. To be specific an ARM Cortex M3 from STM (STM32107VC). Complete example So far I am using the StdPeriphal library, and will continue to do so ...
6
votes
2answers
4k views

Fixed size Memory Pool Implementation

Here is an attempt at implementing a fixed size Memory Pool1: pool.h ...
6
votes
1answer
2k views

Simple event system

I made this simple event system: ...
6
votes
2answers
813 views

Typesafe scanf-like function with variadic templates

I'm hoping to get some feedback on a function with variadic templates that parses a format string and fills in some parameters whose order and types are based on the characters in the format string. ...
6
votes
2answers
1k views

Type safe program uniform manipulation in OpenGL

I've made an attempt at writing class wrappers around basic OpenGL objects to make managing them easier and more intuitive. Writing a generic one for program uniforms proved to require a little bit ...
6
votes
1answer
10k views

C++ compile-time checked switch 'statement'

In the project I work on there are several places where a switch statement is used on a type enum. (I know, better to use virtual functions or a visitor pattern or something, but sometimes switching ...
6
votes
1answer
79 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
2k 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 ...
6
votes
1answer
80 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
115 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
966 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
90 views

C++ Template to implement the Factory Pattern

Design A template class that will create a concrete instance of an interface class when given the name (as a string) of the concrete class. This design is often seen in code, so the purpose of this ...
6
votes
1answer
876 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
778 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
484 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
208 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 ...
6
votes
1answer
360 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
3answers
449 views

Template Matrix Class: implemented some basic functionalities

Basically I have written a matrix class for addition, multiplication and scalar multiplication. I need your review of the class implementation below in terms of efficiency, memory consumption and new ...
5
votes
3answers
208 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 ...
5
votes
2answers
132 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
2answers
714 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 ...
5
votes
1answer
990 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
1answer
735 views

Dereference template class

Usually, C++ standard library algorithms have two versions, e.g.: ...
5
votes
2answers
250 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
213 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
176 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
3answers
1k 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
223 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
397 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
1k 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
144 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
66 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
821 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
190 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
136 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
71 views

`zip` operator to iterate on multiple container in a sign

I worked out a zip operator similar to Python's, because I didn't find one in std. It allows to use range-based ...
5
votes
1answer
1k 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
451 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
817 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
2k views

Normalize integer types to float range

I wrote two template functions to take an integer type and output a float in the given range. One function takes signed integers and the other takes unsigned ...
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
251 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

Heavily templated mathematical vector class

I started to write a library for linear algebra for personal use, but also for revitilization of my C++. Below is the first class of this library, a templated vector class, which is templated over ...
5
votes
1answer
3k 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 ...

1 2
3
4 5
9