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
18
votes
5answers
4k views

Stopwatch template

It's often useful to be able to time code, for instance, to evaluate alternative approaches to the same problem. Because this is a thing I use frequently, I have created this Stopwatch templated ...
28
votes
2answers
1k views

Dynamically call lambda based on stream input

Some context: I have code that looks like this (minor issue noted here): ...
6
votes
2answers
2k views

Stack implementation using vectors and templates with no overflow version 1.1

I have modified my code as per the suggestion given by some of the developers. Let me know if there are any further concerns or scope for improvements. Original Version ...
4
votes
2answers
2k views

Platform independant thread pool v3

This is a continuation of this question, v4 can be found here Taking the advise given previously, the deadlock was fixed in the non-yielding code. The next problem comes from the suggestion to make ...
8
votes
2answers
18k views

STL Stack Implementation

I implemented std::stack from the STL for deeper understanding of the language and memory since I still am only a beginner. I implemented the stack using a singly ...
5
votes
1answer
343 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 ...
13
votes
4answers
2k views

Use of templates with templated Deck class

I have previous revisions of my deck of cards project, but I may not need to link them here since the emphasis is on the use of templates. I've never used them before until now, and I like how ...
8
votes
2answers
459 views

Template integer range, version 2

This question is a follow-up. The original question was itself a follow-up to an older question by @LokiAstari. The idea is to provide a compile-time integer range. This version incorporates ...
9
votes
3answers
462 views

n number of x on the y

Everyone knows "99 bottles of beer on the wall". Mat's Mug made a comment about mugs on the wall in The 2nd Monitor and I realized I never wrote a "beer on the wall" program. But that seemed way too ...
8
votes
1answer
1k views

C++ template range

From a previous question I got an answer that included some template magic (that to be blunt was mind-boggling (as I could not understand it)). So I have been trying to achieve the same results (...
8
votes
3answers
401 views

Generators and Distributions 2.0

In my original question: Generically encapsulating random generators and distributions into a class template I was given some excellent suggestions from two very informative users. I will give a basic ...
6
votes
4answers
519 views

General advice on a practice linked_list for C++ classes/templates

Introduction I'm learning C++ (Coming from Haskell, C, and Assembly - and other languages sparsely) and this was my practice with classes and templates. It's a linked list that you can call in this ...
2
votes
1answer
779 views

Variadic template data pack strucuture designed for debug/trace log (variable-sized records)

I am currently writing this pack template to pack all the values (raw / fundamental + arrays of such, especially c-strings and ...
2
votes
0answers
113 views

Counting words in files - follow-up 2

Previous question: Counting words in files - follow-up I have fixed punctuation problems in my previous code by using template, because it is easy to understand and my focus on template mechanism. ...
18
votes
4answers
10k views

std::tuple foreach implementation

I wrote a "foreach" implementation for std::tuple: ...
15
votes
3answers
11k views

Very basic tuple implementation

I've been messing with metaprogramming and variadic templates in C++, and I came up with this very primitive implementation of a tuple: ...
12
votes
2answers
12k views

C++ string_cast<> template function

In C++, to simplify string conversion between std::string and std::wstring, I created the following utility template functions: ...
11
votes
1answer
7k views

Variadic templates and pointers to member functions to achieve a named-parameters interface in C++

I studied a bit and packed all the suggestions that I received here: Fluent interface and polymorphism for building a scene with shapes and I came up with this: ...
11
votes
3answers
11k views

C++ Stack using template

I'm learning C++, so I wrote a stack with the help of templates. I'm wondering if there is anything I can improve or if I did something vastly wrong. Stack.h ...
8
votes
1answer
779 views

Create New C++ Class

I'm currently developing a new version of ExpressGenGen Using TDD. While I'm rewriting the new version of my Code Generator Generator. I'm using its old version to generate code to be used by the new ...
8
votes
2answers
168 views

Type-safe cartesian co-ordinates

I've recently been fiddling around with a type safe implementation of cartesian co-ordinates (and a few operations on those co-ordinates). Often it's easy to get units mixed up: is something in metres,...
19
votes
1answer
2k views

for_each for tuple-likes

I've implemented a C++14 for_each for tuple-like objects. It's similar to std::for_each in that it also returns the functor once ...
11
votes
1answer
2k views

Compile-time-fixed templated integer range

This is a follow-up of an old question by @LokiAstari, modified for the current community challenge. The idea is to provide a compile-time integer range. I applied all the modifications that I ...
4
votes
1answer
369 views

Handling views and templates

My guts tells me that this isn't the proper way to handle views / templates, so that's why I'm asking you what could be done better. Some background: This application I'm building now is for use in a ...
4
votes
0answers
195 views

Text-based Snake game on Window - follow-up

Previous question: Text-based Snake game on Window Summary of improvements: Removed unnecessary functions such as clearScreen() Added new ...
4
votes
1answer
130 views

CakePHP change 'miniMap' action and respect template

I have some questions on how I can improve this "action" (method) in "controller": My template has a navbar with dynamic content (if the user is logged in a special button appears, his name appears ...
11
votes
3answers
4k views

Fastest possible text template for repeated use?

While reviewing Sending templatized e-mail to a million contacts, I wrote this implementation to illustrate an alternate approach. It is designed to be the fastest possible way to generate templated ...
11
votes
1answer
377 views

Vector implementation, which received unhelpful negative feedback from professor

I've just finished a homework assignment to implement a simple Vector class. -Kindly ignore the following two paragraphs if you don't want to read someone whining about their professor Yadda, yadda,...
9
votes
2answers
2k views

boost::unordered_set intersection using templates

I wrote this function to do unordered_set intersection using templates. I have seen this answer but I thought that it was overkill. I would like the method to take ...
9
votes
2answers
1k views

Concurrent FIFO in C++11

I have implemented a simple FIFO that can optionally be used by either a single thread or way to pass data between threads. The class is templated with arguments for the types the queue will contain ...
7
votes
2answers
149 views

A C++ template function for doing multi-indexing a sequence

The idea behind the below code is that I can index a sequence with a sequence of indices and get a std::vector of the indexed elements: multi_index.hpp ...
7
votes
2answers
1k views

Sorted vector (aka flat_set) for objects (pointers) with custom embedded key (functor used)

BEFORE YOU READ: this link should be included when you just don't like the format of the question and for those that read this question for the first time, the link may give you the idea what happened ...
6
votes
2answers
317 views

First template class - Matrix functions

This post has been answered and updated. This was the first time I've ever written a template class. I've spent probably a bunch of times re-writing matrix code for different types, different ...
6
votes
2answers
462 views

Generic implementation of an array view

I present my implementation of an "ArrayView". I am totally aware the standard nowadays provides such facilities, but for the purpose of learning generic template coding (or is template meta ...
5
votes
3answers
932 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
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
1answer
323 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 <...
4
votes
0answers
38 views

Emulating Virtual Registers Part 2

This is a follow up of my original question in which I'd still like to have some answers, opinions etc. but after looking through some of the standard library's features I have come across ...
4
votes
1answer
266 views

Template with boost::operators extremely verbose and repeating

I got the following ugly code: ...
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 ...
3
votes
2answers
247 views

Generic sliding average in C++

I tried hard to come up with a function template computing a sliding average. A sliding average over data \$x_1, x_2, \dots, x_n\$ with window length \$k \leq n\$ is a sequence \$y_1, y_2, \dots, y_{n ...
2
votes
1answer
1k views

Object Oriented Finite State Machine

I wrote a little library for myself: implementing a generic finite state machine. I will be using this library in class assignments. I clearly have little understanding of C++ templates because most ...
2
votes
0answers
52 views

Emulating Virtual Registers by experimenting with unions, bitfields, structs and template specialization

To get a better handle and understanding of how bitfields, unions, and the byte alignment of structures work, I'm simulating a template Register structure. The requirements of my Register are as ...
2
votes
0answers
79 views

Any class implementation - follow-up

Based on the previous question, I have improved it to make it insert regular function. Also, I have implemented a new template approach to obtain the signature from any function by testing its ...
2
votes
2answers
184 views

Efficiency of vector like class

I've written a vector-like class in C++ and I'm trying to figure out issues in efficiency. When I use clock() to measure the time taken to emplace objects, ...
2
votes
1answer
271 views

Auto-resizing array, that accepts negative indexes

I've been coding a helper container template to contain tiles in 2D games. What I figured out I would like when writing code for my games is forgetting all resize stuff, allowing negative indexes (for ...
2
votes
1answer
194 views

Class templates for encapsulation of datasheet limits

I've written some classes to encapsulate the limits given for datasheet parameters, e.g. for the classic 741 op amp: As the above example datasheet snippet shows, there are some challenges for ...
2
votes
1answer
236 views

Memoization via template

This is kind of follow up of this question on stack overflow... I wrote the following to utilize memoization for functions that take a single parameter and return a value: ...
1
vote
1answer
101 views

Template matrix class, second version

This is my first matrix class which I updated after already asking here already. The updated code is below. Are there any suggestions regarding member function parameters? Is there a convenient ...
1
vote
1answer
126 views

Simple Batch Templating Utility in Python

I would like to present for review my (much) revised batch templating utility which had it's humble beginnings here in a previous post. As I mentioned there, this program is my entry into python ...