Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [template]

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

8
votes
2answers
17k 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 ...
4
votes
1answer
324 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 ...
12
votes
2answers
11k 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: ...
2
votes
1answer
48 views
4
votes
2answers
145 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: ...
2
votes
1answer
48 views

Replacing MIN and MAX macros with type-safe, recursive templates of variable arity

I'm currently reading Mastering Perl for Bioinformatics; I'm using the book for learning bioinformatics while implementing the code in C++. I came across a situation where I needed to use the minimum ...
4
votes
2answers
102 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. ...
3
votes
0answers
45 views

Generic Variable Elimination with multiple entry points

I have this algorithm, called Variable Elimination, which is used quite often in my code-base (library). It is an algorithm for factor graphs (a type of bipartite graphs), used to efficiently maximize ...
5
votes
1answer
57 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 ...
0
votes
0answers
50 views

Simple dynamic array template

For my game engine I needed a simple templated array class that can be safely passed across module boundaries. It's not supposed to be a replacement for std::vector and thus doesn't need all of its ...
1
vote
0answers
38 views

Value-To-Type Map

Context For one of my projects I have to use a library which works similarly to the following code : ...
1
vote
1answer
114 views

Calculating array size in C++

This code shows two ways to calculate size of array of any type. I would like to know, which should be preferred? Is there any advantage/disadvantage? ...
6
votes
2answers
14k views

Modern C++ Singleton Template

I recently read about the C++17 static inline member declaration and thought that this will make templates a little bit cleaner, since static members can now be ...
0
votes
0answers
32 views

Templated JSON parsing methods that work with an element or elements array

Consider the following two Java methods. The first takes a JSON string representing one element, the second representing multiple elements. gson.fromJson() can be ...
4
votes
1answer
230 views

Variadic Datablocks

I would like to have my variadic template class reviewed. First some explanation what it should do: I'm writing an application where I read in blocks of data. I know before i read in the data which ...
17
votes
4answers
10k views
6
votes
1answer
70 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 ...
0
votes
1answer
50 views

Generate a text file representing an email for a job application followup

Purpose: After you've submitted a resume and cover letter for a job position, you haven't heard anything back, so you decided to send a follow up email. The script generates the follow up e-mail based ...
1
vote
2answers
74 views

Insertion Sort and Selection Sort Implementation

I wanted to practice using templates since I have no experience with them, so I implemented these sorting algorithms. Selection Sort: ...
0
votes
0answers
12 views

Optimizing Datatables table of tens of thousands of client-provided rows

We have this employees table, that looks like this: that contains 16,530 employee rows. As expected, this table takes more than 30 seconds to load. I have been tasked with speeding it up somehow. ...
2
votes
1answer
57 views

Loop over whole array starting from any index

I recently had to repeatedly iterate over an array but increment the index to start from each time. Since this is quite cumbersome in comparison to a normal for loop I made a small template function ...
3
votes
1answer
106 views

Implementation of static_vector using an array of std::aligned_storage, with std::launder and forwarding

I'm trying to expand on the implementation of static_vector on the std::aligned_storage reference page, but would like to split it into two parts. First, an ...
3
votes
2answers
88 views

Simple Matrix Template Class

I wanted to make a matrix template class to see if I can learn how to use templates, work on figuring out the indexing in loops, and making an interface so the user can know if an operation will work. ...
1
vote
0answers
33 views

Displaying Singapore bus arrival times using a Go template

I am wondering whether my template usage in main.go could be better. For example in other code I notice: ...
2
votes
0answers
73 views

Observer(Event) system (Signals and Slots), type and template based

Signals are represented as types. You can connect a member function of some instance to the Observer system. This connected function will be called whenever a signal of a type that is the same type as ...
1
vote
1answer
52 views

Simple template engine in PHP

I tried writing my very first template engine today. I designed it to just replace variables in templates, and keep it basic for now. Can anyone give me some constructive criticism? I'm getting ...
0
votes
1answer
25 views

Injecting a set of files in a Thymeleaf template while keeping the amount of tags at a minimum

I use a Thymeleaf template to inject a set of files (which contain precalculated HTML) into one big HTML. The files with their metadata are stored in a map called ...
4
votes
0answers
56 views

Tracker for object construction, copy, and movement

I made an object tracker for debugging and testing purposes called ccm_counter (construction, copy, move counter). It counts constructor, copy and move calls. It ...
2
votes
0answers
35 views

vb.net Create textfile from template

What is the best approach for creating textfiles from/with a template ? Currently I just read the template from a textfile and Replace all values needed, but I don't think that this is the most solid ...
5
votes
2answers
131 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
2answers
75 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 ...
1
vote
1answer
91 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 ...
6
votes
2answers
203 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 ...
1
vote
0answers
68 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 ...
10
votes
1answer
969 views

C++ math vector template

I wrote a basic template for a vector of arbitrary dimension to be used in a 3D-engine. Most operators make use of C++ template meta programming and instances are implicitly convertible to glm types. ...
3
votes
2answers
87 views

C++ Vector with templates

I am learning about templates in C++ so I decided to implement an N-dimensional vector. The code seems to work fine, but there are a few things that I am unsure about. To stop ...
4
votes
2answers
117 views

Templated string formatting

This function formats a string by replacing every occurrence of '{n}' with the corresponding argument that was passed to the function where n is an index that ...
2
votes
1answer
213 views

C++ - Trie Implementation

I am trying to learn trie and this is my first implementation. I started off with the idea of being able to handle different data types for key and value; however, I found the data structure a bit ...
2
votes
1answer
80 views

Synchronized template wrapper class

Issue: Code base has lots of data structures which are accessed between threads with >= 1 writer. Application logic becomes obfuscated due to lots of mutex locks. Solution: Create a template ...
0
votes
1answer
40 views

PHP simple template loader

This is not really a question but I'd like to obtain some opinions about this simple class. For an old project I had the necessity to load some php template files that includes some ...
1
vote
0answers
310 views

A simple and efficient packet frame encoder/decoder

I have written a simple packet-framing class, for converting un-encoded 'packets' into encoded/delimited 'frames,' to be sent over a P2P serial connection. The functionality is based on the RFC 1662 "...
-2
votes
1answer
60 views

Is this a good/bad/ugly way of assigning unique IDs to objects in C++? [closed]

My project has many different objects from different classes, and I want each object to have a unique ID. IDs should be unique within each class type, but can be the same among different classes. For ...
3
votes
1answer
158 views

Internal Zip-like Iterator

My goal was to create an zip-like iterator to selectively iterator over a subset of arrays in a larger manager object, compare itself to any other zip-like iterator, but can be copy constructed from ...
4
votes
2answers
363 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 ...
6
votes
1answer
386 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
2answers
388 views

Small Formatting Library

I am learning C++ and currently playing with variadic template functions and formatting string, So here is my small attempt to write a formatting function and provide a simple iostream-like interface ...
6
votes
1answer
330 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. ...
2
votes
1answer
39 views

Implement metaclass for Maximumlikelihood estimator

For the purpose of defining a lot of Maximum Likelihood estimators, I think I need a metaclass. At the moment I have to copy/paste a lot of code for every new class definition and just substitute the ...
2
votes
2answers
129 views

C++ Software cache for shared resources

I wrote a basic C++ template to manage shared resources like textures and shaders in a 3D engine. The idea is that the cache itself holds weak references to the resources (through ...
8
votes
3answers
1k views

Templated CSV file parser

I want to parse a CSV file and store the data using the istream >> operator but I am running into big performance issues. Here is the current version: ...