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
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 ...
3
votes
4answers
2k views

My own std::vector

I've made my own std::vector but it's the first time that I work with template and new/delete. The code works, but surely there are a lot of things that are wrong. ...
3
votes
3answers
1k views

C++ Node class template

I'm working on building understanding of data structures in general, and specifically linked lists in this example. I'm also trying to increase my ability with templates. In cross-referencing dozens ...
3
votes
4answers
634 views

Sending templatized e-mail to a million contacts

This code runs fine without a bug, I need to optimize this code for following interview requirement. Lets say i need to send it to 1 million contacts and emailBody is ~100Kb. What code optimization ...
3
votes
3answers
198 views

Template class to demonstrate array manipulation

Today I didn't pass the test task for the position C++ junior/middle developer. What i did wrong? Please help improve myself. Task: Description. Write a template class - an array of any type ...
3
votes
3answers
421 views

Bit manipulation tool set

I made a tool set to facilitate bit manipulation as follows. Any comments are welcome, be it about the interface design, the implementation, or even the naming. Also, I want to make sure that the tool ...
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 ...
3
votes
3answers
2k views

Template 3d vector class

I've created this 3D vector class and would like it to be reviewed. I wonder if there are still some improvements that can be made. This is a header only implementation. ...
3
votes
3answers
623 views

Simple shared pointer

I wrote a simple shared pointer, which I think works pretty well. I would like to see your review of it. This is the header file: ...
3
votes
1answer
106 views

Generic implementation of an HeapArray and StackArray

I present my implementation of an HeapArray and StackArray. Similar to the implementation of my ArrayView which justs open a ...
3
votes
1answer
81 views

Elevation to power function using class templates

I attached below a small working example of a function that is able to perform x^y. As it is possible to see the base (x) takes ...
3
votes
2answers
131 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. ...
3
votes
2answers
322 views

C++ finalizer template

Consider, please, my code of the finalizer template: ...
3
votes
1answer
1k views

std::string/std::wstring template wrapper for Win32 API

I have not completed this but want to make my own template library for wrapping the Win32 API to make it compatible with std::string/std::wstring... Here's a sample of what I've worked with so far. ...
3
votes
1answer
61 views

Predefined values for some values in a template function like with a #define macro (e.g. template<int foo, typename bar>)

I want to overload an operator (e.g. operator<<) with different types, but also change only 1 or 2 values in the function itself. I want to get some fancy output of a vector with the primitive ...
3
votes
1answer
144 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
94 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 ...
3
votes
1answer
42 views

D minMax function implementation

I happened to need to find both the maximum and the minimum of an array, so I decided to implement a minMax function in D. Questions: Is this an efficient ...
3
votes
2answers
411 views

Triple-type template container

I made a triple-type container, that is, a single type that can store a value, under one of the three types used. It's somewhat similar to Boost::Variant. The header file (multitype.hpp): ...
3
votes
1answer
152 views

Templated renderer class

A class that matches the rendered objects shader and render function(sets shader resources) based on its typeid hash. ...
3
votes
1answer
757 views

Ensure only a single instance of static template class member

I am interacting with a C library, whose documentation states that certain functions are not thread safe. Since its functions deal heterogeneously with multiple types, I have written a template ...
3
votes
1answer
52 views

Could this template function be improved?

I'm writing wrapper functions for some of the functions in <algorithm>. While the following works perfectly, I'm not sure if this is the best way to approach ...
3
votes
1answer
73 views

IniReader template overrides become ambiguous

I was tasked with refactoring our existing IniReader class, which is Windows only compatible, to be cross-platform ( specifically UNIX compatible ). We decided that ...
3
votes
1answer
303 views

O(lg n) algorithm for a fibonacci number with c++ template

I wrote a function to find a specific fibonacci number, which runs in O(lg n). Then I modified it with a template. Though it works, I'm new to template and want to ...
3
votes
3answers
207 views

Plain type serializer design

I am designing a class to store primitive types into byte buffer using predefined byte order. I am not going to use Boost.Serialization because I am working with plain types only and I need predefined ...
3
votes
2answers
3k views

C++ templated singleton class - properly destroyed?

I have written a templated singleton class in C++ but I am afraid that it is not properly destroyed. Can you advise me on that ? my singleton.h ...
3
votes
1answer
3k views

Template system with master layout

Here is my template code ...
3
votes
1answer
100 views

dc.js and crossfilter app to display multiple charts

Consider the following crossfilter / dc.js app (screenshot): ...
3
votes
1answer
78 views

JavaScript module to filter data and render it as a table

I want to organize some JavaScript code using module pattern. The scenario is as follows: Having the following html table created dynamically ...
3
votes
1answer
2k views

C++ Registry pattern implementation

I created a template registry class. It supports custom factory functions and custom constructors. Any kind of feedback is welcome (style, performance, bugs) registry.hpp: ...
3
votes
1answer
327 views

Check balanced brackets in a text

Given an input text that is a combination of {, }, [, ], (, ) characters, check whether the input text has balanced brackets or not. This was a question from hackerrank, and the code below solves it ...
3
votes
1answer
351 views

C++ Policy-based object pool

Description This is an improved implementation for a previous post My goal was to implement a decent object pool using templates and policy based design. The object pool behaviour can be customized ...
3
votes
1answer
88 views

Checking for a palindrome in any sub-range of a range

This is my attempt at answering "Palindrome from all the substrings" which asks to detect if a string contains a palindrome as a substring. The algorithm implemented here is the one described in its ...
3
votes
1answer
173 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 ...
3
votes
1answer
1k views

Using simple HTML template to create HTML formatting rules

One of my tools that renders HTML needs some rules about document formatting. The renderer can format the output so that it is indented and contains appropriate line-breaks. In the first version I ...
3
votes
1answer
1k views

Cloning Windows Forms controls from a template

In a recent project I needed a way to clone windows forms controls from a template which had predefined Size, Font, etc. Since ...
3
votes
1answer
416 views

Mad Libs program

My code creates a Mad Libs program. Its a prewritten story that you fill in blindly. There are 4 pages of 7 entry boxs and labels. When the inputs are in and next is pressed it saves inputs as ...
3
votes
1answer
2k views

A small generic array in C

The generic arrays in C I found on the net used either of these methods: The preprocesser with #define and #include (a lot of ...
3
votes
1answer
317 views

Liquid navigation tree generator

This include was written for a Jekyll site I'm building. It generates nested HTML unordered lists to a given depth dynamically by parsing page urls. It works fine, but the code feels messy and it ...
3
votes
1answer
2k views

Generating a zoo of animals

The pattern I've come up here is for the AnimalGenerator itself, outside of the (abstract) Factory Pattern used within it. The factory classes themselves are not ...
3
votes
1answer
72 views

Seeking proper system for pairing types

My code below ensures that only land animals can be a "representatives" for Land while only ocean animals can be representatives for ...
3
votes
1answer
110 views

Should I use an object or type as trait?

Edit: Disclaimer: I am new to templates and traits. I apologize in advance if this is a bad question. I am refactoring two similar classes with small differences strewn all over them into one ...
3
votes
1answer
136 views

JavaScript templating language: ivy-markup

This library is a markup parser which is intended to be used in node.js and browser environment. I've decided to use Jasmine for tests. The library's name is ivy-markup. URL: https://github.com/...
3
votes
1answer
1k views

Passing anonymous functions and getting variables from an outer scope

I'm doing something quite strange. I'm trying to create a tiny system for creating templates inline in PHP, so that I can refactor by creating multiple templates in the original script, and ...
3
votes
1answer
123 views

Logic/Presentation separation

I have the following code: ...
3
votes
2answers
525 views

Inline visitor implementation for C++11

I've been looking at getting back into C++11 after a few years and came across the idea of implementing the 'inline' visitor pattern. The idea is that you can specify your visitor class locally in the ...
3
votes
1answer
171 views

C++ LinkedList Implementation

I've been studying data structures and making implementations for different types. This is my linked list code. Please let me know if there's anything here that could be improved upon or changed for ...
3
votes
1answer
157 views

Split big PDF into smaller documents and insert text at specific position

I’m new to Java programming and uncertain if I used the right approach to solve my job. This little program uses the iText library to split one big PDF into smaller documents. The trigger for this is ...
3
votes
1answer
172 views

C++11 Quicksort any container

As the title says, simple quicksort to help myself get used to C++ templates and iterators. Main concern is whether there's a better way to template so that you can have a simple function (e.g. ...
3
votes
1answer
1k views

C++ Template Binary Search Tree

I've been trying to improve my C++ skills as well as work on some general coding techniques so I've attempted to build my first binary search tree in C++ using templates. I've mostly done Java ...