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

learn more… | top users | synonyms

2
votes
0answers
30 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. ...
4
votes
1answer
99 views

Simple mathematic operations (add, sub, mul, div) in C++11 template

I made a simple script to implement basic mathematics operations by using variadic functions. I would like to know if my implementation is correct. The code only works for visual C++ compiler Nov ...
5
votes
1answer
68 views

Simplifying a class template

I wrote this code over night for a little project that my friend and I have been working on. This class template was created over a year ago during as a class assignment for C++ programming. I ...
15
votes
2answers
257 views

A header-only linear-time C++11 PEG parser generator supporting left-recursion and grammar ambiguity

I've rewritten my original parser generator to a header-only library which uses templates and functionals for better type safety and clarity. The generated parser creates an abstract syntax tree which ...
3
votes
1answer
72 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 ...
10
votes
0answers
125 views

Object storing and retrieving using wildcard identifier

I'm writing an interpreter for a scripting language which allows objects to: Have an alias Be referenced using a wildcard Contain child objects Combination of all three above For example: ...
5
votes
2answers
100 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 ...
8
votes
1answer
73 views

consecutive_find function for returning a consecutive range of elements

consecutive_find() is a function that returns the beginning of a range that contains strictly N consecutive elements. It was part of a SO question that I answered. ...
2
votes
1answer
49 views

Static to Instance method trampolining with templates

I finally have a working trampoline mechanism. Would anyone care to critique it? Ideone ...
4
votes
1answer
294 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
82 views

Wrap function pointers in template classes

I'm working on a C++ library for Arduino and other embedded systems. I'm currently working on wrapping up function pointers and member-function pointers into two C++ template classes (function and ...
1
vote
2answers
62 views

Binary search tree with templates

I am currently attempting to become proficient in C++ and started by implementing a basic binary search tree. Most of the programming I have done is in Ada, Python and C. I would like to be able to ...
4
votes
1answer
106 views

Recode C -> C++ trampoline function macros using templates

I'm reworking PyCXX (C++ wrapper for Python). I'm currently examining the following macro code, and wondering whether there is a way to write it using templates rather than macros. If so, the ...
5
votes
2answers
74 views

Using a CRTP approach for loading OpenGL programs

I wanted to try using CRTP (also new for me) to try making the loading of shared resources implicit. (Specifically I'm using it for loading OpenGl shader programs) This will also help separate some ...
5
votes
1answer
143 views

Dereference template class

Usually, C++ standard library algorithms have two versions, e.g.: ...
4
votes
2answers
61 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? ...
8
votes
0answers
60 views

Wrapping types with alignment requirements

Visual Studio 2013 still doesn't support the alignas keyword in C++11. This causes some problems with alignment of types in various situations. Thankfully the ...
2
votes
1answer
22 views

Making empty cells in Underscore template

From the back-end, I am receiving 8 data. The client requires showing that the row per data is 7, so I have 1 data in balance. I have created empty data and made the empty cells, which works fine. But ...
1
vote
0answers
60 views

Writing a universal “call” function: call(f, args…) where “f” might be a member function/data pointer

I need a function call(f, args...) which calls the "function" f with the arguments args.... ...
6
votes
1answer
112 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 ...
10
votes
2answers
300 views

Templated doubly-linked-list

I've been wanting to revise what I knew on templated classes so thought I'd write a doubly linked list to practice. It works fine, so all is well and good on that front, but is there something I've ...
2
votes
1answer
152 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
1answer
61 views

C++ messaging using templates

I wanted to allow components of my program to communicate without the components knowing about each other, thus keeping coupling low. So I devised some template classes that implement the observer ...
7
votes
2answers
215 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 ...
7
votes
1answer
90 views

A tiny switcher for arbitrary types in C++11

I was about to use the awful enum+map trick to switch on std::strings when I thought to see if I could let some variadic templates do the job for me and I started ...
10
votes
1answer
202 views

Template 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 ...
3
votes
3answers
214 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
152 views

Wrapping std::bind call in a function returning std::function

Is this code correct? It appears to work in g++ 4.8.3 and clang (bcc64), however appearing to work is no guarantee of correctness :) The aim is to be able to replace a call to a member function: ...
11
votes
5answers
542 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 ...
2
votes
1answer
97 views

After refactoring using template class, PHP file takes forever to load, timeout after 30 seconds at times

I've been learning how to code for the past 3 years about. I have made some really good progress I think, and right now I'm trying myself on creating an MVC framework. I found this awesome idea on ...
6
votes
2answers
2k views

Binary Search Tree implementation using templates

I wrote this implementation using templates. It works fine and as expected. Just want to know if this can be improved. I have some specific questions too at the end. Please feel free to critique to ...
0
votes
1answer
98 views

Refusing to use a common template engine

As the title says, I refuse to use a common template engine. I have my reasons, so instead of doing this: ...
4
votes
4answers
102 views

Naming a template print method properly

Some might not think it's worth asking but I consider good function names quite important. I am not sure what should be the overridable function name in what I think is template design pattern. I am ...
4
votes
2answers
279 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 ...
5
votes
1answer
87 views

Template for endianness-free code, data always packed as BIG-Endian

It's been a while since I've been properly grilled about my code. I had this Idea which should probably never make it into production code but still I couldn't find anything seriously wrong with it ...
15
votes
3answers
1k views

Creating .cpp, .c, .h. and .java file templates

This code builds template .cpp, .c, .h and .java files based on a file name and #include, import lines provided at the command line. The file opens after creation. I am looking for a review of this ...
2
votes
1answer
98 views

Is this a meaningful Intrusive Pointer Class?

Is this intrusive pointer implementation correct? I tried to use the CRTP Pattern to avoid a virtual destructor in my class ReferenceCounting which provides the ...
6
votes
1answer
608 views

Smart enum templates

Here is some code I wrote 10 years ago. I'm now reviewing it and there are a lot of things I don't like. There is possibility for weird behaviour if the template is attempted to be used with a type ...
6
votes
2answers
605 views

Multiple dispatch with variant and multi visitation in C++

The following program is a demonstration of variant and double visitation used to obtain double dispatch between the elements of two inhomogeneous containers. Most of the work is done at compile time. ...
6
votes
2answers
2k 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 ...
7
votes
2answers
506 views

std::tuple foreach implementation

I wrote a "foreach" implementation for std::tuple: ...
2
votes
1answer
165 views

std::tuple objects or rvalue references?

I have some small "plugin system" (not sure this is right name). It allow you to store objects (plugins), and then call some methods from each of them. With this approach we have absolutely no ...
5
votes
1answer
189 views

User defined literal for std::integral_constant

I created a user defined literal _c to convert an "integer" literal into an std::integral_constant. Basically, the goal is to ...
2
votes
0answers
101 views

Associative container that produces a unique, instance specific handle for each inserted object

It is not always possible to simplify program design by strictly managing the lifetimes of objects. If two objects have unpredictable lifetimes, but one of them needs to refer to the other, a simple ...
7
votes
2answers
320 views

Simple and efficient boost::unordered_set intersection

I wrote this function to do unordered_set intersection using templates. I have seen this answer but I thought that is was overkill. I would like the method to take ...
5
votes
3answers
223 views

Std lib-like C++ function to find nearest elements in a container

Initial problem For a project I found myself in the need to search for elements in a container that are the closest neighbours to another precise element I have. In my case it was points in any ...
4
votes
3answers
113 views

Using a template to cycle through a sequence of containers

I'm trying to implement a template that takes a container as parameter. The template has a getnext method that cycles through the elements in the parameter. Take ...
9
votes
1answer
331 views

Is my C++11 generic container a good design?

After refactors and refactors and the discovery of very common patterns on many of the classes of the software I wrote, I decided that it would be fine to have something like an arbitrary-keyed map, ...
10
votes
2answers
1k views

Compile time decorator pattern in C++ with templates

I'm doing some high energy physics modelling in C++. I have written code that implements class that score interactions of particles with detector material. Here is a base class: ...
6
votes
1answer
87 views

Dynamically call lambda based on stream input: Try 3

Based on Dynamically call lambda based on stream input: Try 2 This fixes most of the points pointed out by @Morwenn. It has been generalized so anybody can call it. The only extra part needed by the ...