a design structure for creating several things that are almost identical but need different values. Not template-meta-programming.
5
votes
2answers
49 views
Typesafe scanf-like function with variadic templates
I'm hoping to get some feedback on a function with variadic templates that parses a format string and fills in some parameters whose order and types are based on the characters in the format string. ...
4
votes
1answer
34 views
Markdown parser, template engine, and then some
I've got my own website! Woo! It's got HTML and everything! But after struggling for a while with HTML and keeping my navbar consistent across pages, I gave up and wrote a program which:
Searches ...
6
votes
1answer
67 views
C++ template type traits for class members
I have written type traits for checking, if given class T has_member, then if it either ...
0
votes
1answer
52 views
RAII object for releasing pointer with arbitrary function
The following class is a sort of "smart pointer" that can be used for automatically releasing pointers:
...
2
votes
1answer
36 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
42 views
A simple template engine to display value
For a specific usage I made a very simple template engine in Python, to display value. The code:
...
5
votes
1answer
43 views
Fixed capacity unordered_map
I have a need for a container that behaves like an unordered_map, but has a fixed capacity, and an eviction policy where the least recently inserted key-value pair ...
3
votes
3answers
122 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 ...
2
votes
0answers
32 views
Rust-like “Result” in C - nicer error handling
There are frequently things I miss when using C; one of them is a nice error-handling (exception-like) system. After trying Rust, I realized I could implement something similar in C itself. So here's ...
8
votes
2answers
128 views
Call a lua function - the C++ way
I'm not that good when it comes to templates, especially when it comes to variadic templates. I want to show you some code where I use both - templates and variadic templates - to call a lua function. ...
2
votes
2answers
84 views
A function for convenient string concatenation with variadic templates
I wrote this function for string concatenation some time ago.
Jo() stands for "Join". The name is shortened on purpose, because this function is used very often.
...
3
votes
1answer
72 views
Extended Euclidean Algorithm in modern and readable C++
In Python the Extended Euclidean Algorithm (egcd) could be written as follows:
...
2
votes
2answers
81 views
Allocate N-dimensional array in C++
I need to allocate n-dimensional arrays of type T, currently I am using the following functions. Is there a better way to do this? Also, ideally I would like to allocate a 1-D array and access that as ...
2
votes
4answers
101 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. ...
-1
votes
1answer
108 views
Using templates and function overloads to set DOM attributes [closed]
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 ...
3
votes
0answers
51 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
31 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 ...
8
votes
0answers
92 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
149 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
90 views
3
votes
2answers
42 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
60 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
160 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
57 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
84 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
73 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
75 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
105 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
14 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
44 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
49 views
A variadic tree class that supports multiple types
I'll define template <typename...> class VariadicTree with the following example:
...
3
votes
0answers
113 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
87 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
130 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
53 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 ...
2
votes
1answer
66 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
52 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
121 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
72 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
59 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
215 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:
...
3
votes
1answer
50 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
107 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
116 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
456 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
55 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
40 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
47 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
142 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
96 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.
...