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

learn more… | top users | synonyms

-1
votes
1answer
76 views

Using templates and function overloads to set DOM attributes [on hold]

I'm making a library to build and manage a website. I want to control what gets to be inserted. For example I don't want to be able to insert ...
1
vote
0answers
31 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 ...
2
votes
0answers
28 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 ...
7
votes
0answers
74 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 ...
6
votes
0answers
101 views

C++ identity function

I've implemented an identity function (well, actually a functor struct) in C++. The goal is that every occurrence of an ...
3
votes
2answers
84 views

C++ finalizer template

Consider, please, my code of the finalizer template: ...
3
votes
2answers
36 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): ...
6
votes
1answer
59 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 ...
3
votes
1answer
133 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 ...
2
votes
2answers
45 views

Data structure to store large numbers of runtime-dependent arithmetic types

Warning: lots of code. If it's too much, please focus primarly on channel.h and channel.hpp. This is my first time posting on ...
4
votes
1answer
77 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 ...
4
votes
1answer
44 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 ...
3
votes
1answer
70 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. ...
4
votes
1answer
93 views

C++ template to randomly choose from N elements with uniform distribution

There is a nice algorithm to randomly choose an element from a list in a single pass: Pass through the list keeping the element chosen so far (X) and the number of elements processed (N). When ...
1
vote
0answers
13 views

Modular widget that minimizes js and css scope pollution

So, my goal with this is to create a simple login widget that does as close to nothing to the global scope as possible. The login mechanism is less important than the encapsulation. The whole script ...
4
votes
0answers
36 views

implementing a StringEnum

this is to be used like an Enum (as parameter mostly), but for string using .net 3.5 Actual Implementation ...
1
vote
1answer
46 views

A variadic tree class that supports multiple types

I'll define template <typename...> class VariadicTree with the following example: ...
3
votes
0answers
72 views

Thread-safe LRU cache for C++

I'm working on a simple LRU cache for C++. There's nothing spectacular or unusual about it, but I would like it to be thread safe. (I'm going to be using this for instructional/benchmarking/...
2
votes
1answer
83 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
3answers
103 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 ...
1
vote
2answers
51 views

Storing and loading functions

The class Functions can store/load any functions. It does this by assigning a unique name to every function that gets added. You can then call the function by ...
1
vote
1answer
43 views

Handler for incoming network packages

I want to let you look through my NetHandler which is basically the component which gets notified when a full packet arrived (not like tcp-packet but my own type of ...
2
votes
0answers
48 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 ...
3
votes
0answers
88 views

Enum to string with template metaprogramming

This allows enum values to be outputted as strings. But enum_strings is a type, not a map or a vector, so if the enum value is known during compile time, there ...
4
votes
1answer
60 views

A “policy-based” design for a generic CUDA kernel

I am faced with a design issue that has been discussed on SO several times, the most similar question being this one. Essentially, I want polymorphism for a CUDA kernel in the form of a "generic" ...
4
votes
1answer
58 views

A class to encapsulate a pair of ints with range-checking

The goal is to have a helper class to wrap the concept of a resolution safely, encapsulating the range check into the class, since otherwise it can get lost by a client not so cautious. I think this ...
3
votes
0answers
88 views

C++ time types and format conversions

I wrote a small header-only C++11 header for converting between various C++ time formats. Here's the code in question: ...
2
votes
1answer
26 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
3answers
81 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. ...
6
votes
0answers
101 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'...
3
votes
1answer
173 views

C++ template Partial Specialization Member Function; Am I doing right?

I'm trying to improve my C++ template metaprogramming skills. From my understanding, I can't partially specialize a function(either member function or not). So, I need to define another class that can ...
2
votes
1answer
54 views

Convert custom format to XML Template

I have just finished writing a simple Python3 program which converts a custom input file (or multiple files within the same folder) to an XML template. It works as it is, but I think that I somehow ...
2
votes
1answer
37 views

Rendering comments in a Backbone view

I want to make show/hide logic more maintainable in my codebase. Because they are too faraway located in separate js files, it hard for people to maintain. The flow in my codebase is: require....
2
votes
0answers
45 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
2answers
139 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
2answers
91 views

Templated Stack of 5

This is my first time using C++ Templates to make a data structure. I have written a program to implement a stack of up to 5 items. ...
3
votes
0answers
40 views

Implementing a templated Array class

I have implemented an Array class using templates. I have used a std::allocator object for memory allocation. Will it be better to use operator new along with placement new for memory allocation? ...
3
votes
1answer
85 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 ...
1
vote
1answer
54 views

Generic implementation of SiftUp/Down operations on binary heap

Binary heap construction and maintenance boil down to the two basic operations: sift up and sift down. Following are generic template implementations of the two operations. Any comments are welcome. I'...
3
votes
3answers
86 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 ...
1
vote
1answer
94 views

Set openCV basic structures to zero in a unique way

For test cases I need a unique way to set any structure to zero. For openCV I wrote this: ...
3
votes
1answer
92 views

Minimalist Tree

While working on a small project, I tried to implement a super simple tree class in C++. It supports an arbitrary number of branches from each node. In addition to general comments, my main concerns ...
3
votes
1answer
42 views

C++ Template for one to many Registration (pre Gang of Four)

I use this template to lookup clients registered for data. The data is associated by name(key) and clients are shared pointers (value) to a class which will consume the data. ...
0
votes
1answer
75 views

HTML template for win-loss data in Javascript with Mustache

Can anyone suggest a better way to implement my template code? ...
3
votes
0answers
74 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 ...
2
votes
2answers
126 views

Template Binary Search Tree

This is a simple binary search tree implementation written with C++'s templates feature I wrote to learn C++. What improvements would make this cleaner and better as far as C++ practices go, and are ...
4
votes
1answer
88 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 ...
5
votes
2answers
91 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. ...
6
votes
1answer
79 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"...
12
votes
1answer
186 views

Simple Python 3 templating module

The module adds syntactic sugar to Python 3 to allow concise specification of templates. I use it to generate a collection of static web pages from various data sources. I wanted something ...