a design structure for creating several things that are almost identical but need different values. Not template-meta-programming.
3
votes
1answer
57 views
A template-fixed-size unsigned integer class
For some reason or another, I want to have available unsigned integers of sizes other than 1, 2, 4 and 8 (e.g. an unsigned integer with 3 bytes). For most platforms, compilers don't make those ...
5
votes
1answer
63 views
Circular doubly linked list with templates
I tried to write some code namely "Circular doubly linked list" and I would like to use templates to do this.
This is the first time I use templates and throws some exceptions.
I would like to know ...
4
votes
1answer
134 views
3
votes
2answers
76 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 ...
1
vote
0answers
18 views
Fast HashIndex (HashTable) “template” for indexes and arrays C++
Another in the long line of data structures I'm writing for my 2D isometric game. This is a hashtable that only handles indexes, hence eHashIndex. It does not copy ...
3
votes
1answer
52 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 ...
1
vote
1answer
69 views
Callback class to callback member (virtual) functions
After looking at a post on CR I found that pointers to member functions are incredibly hard to use, especially as callbacks. The current solution doesn't solve the problem mentioned in the linked post,...
3
votes
0answers
26 views
Template class for an Entity Component System library
I'm working on an Entity Component System library. Right know I'm trying to clean up the Entity/Component part (only the code which manage the data).
But I have a class which I think is not really ...
4
votes
3answers
90 views
Simple wrapper for member function pointers with known signature
I always wanted to know how to pass member functions as arguments, and then I stumbled across templates that could automatically deduce types, and so I rejoiced! This is used in a Publisher-Subscriber ...
1
vote
1answer
56 views
Template binary heap with lambda function comparator C++
This heap will be used for A* search pathfinding in my 2D isometric game engine. It uses lambda functions (instead of std::less or ...
0
votes
0answers
27 views
Tag that prints expressions for my template language
This is the PrintNode class from my template language Aegis. This class' purpose is to enable printing expressions (strings, variables, numbers, ...) in the language. eg:
...
1
vote
2answers
64 views
Creating a custom template container class (vector alike)
What can be done better? What should I learn to make these tasks better and more efficiently?
The template (template.h):
...
1
vote
1answer
78 views
Array choice based on template specialization
I've got these two template functions responsible of adding/removing actors in-game in GameEngine.h:
...
3
votes
1answer
132 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 ...
1
vote
1answer
57 views
An iterator which behaves like an array with uniform values
I'm implementing an iterator which takes a single value and which you can advance for n times with a dereferencing yielding the single value - but before or after that range of n 'positions' you can't ...
5
votes
2answers
86 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
53 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 for ...
7
votes
1answer
89 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
60 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
47 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
47 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
64 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
126 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 ...
2
votes
0answers
50 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
149 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
110 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.
...
6
votes
3answers
217 views
Extended Euclidean Algorithm in modern and readable C++
In Python the Extended Euclidean Algorithm (egcd) could be written as follows:
...
2
votes
2answers
92 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
108 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
109 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
1answer
78 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
39 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 ...
10
votes
0answers
132 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
218 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
95 views
3
votes
2answers
58 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
266 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 ...
4
votes
2answers
68 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
123 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
140 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
83 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
128 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
21 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
46 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
63 views
A variadic tree class that supports multiple types
I'll define template <typename...> class VariadicTree with the following example:
...
3
votes
0answers
169 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
90 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
178 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
55 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 ...