Questions tagged [templates]
The templates tag has no usage guidance.
126
questions
-1
votes
2
answers
89
views
Template Source Control Repository
What is the best practice, for creating a template repository, and then creating n projects based on that template?
With "template" I mean: Let's say the template site is x. So x is a site ...
1
vote
1
answer
70
views
How to develop data bound html with strong typing and intellisense?
I'm a huge believer in the value of Intellisense for showing you what syntax is expected and allowed (and also saving typing, though this is a secondary consideration).
When you build a web component (...
2
votes
1
answer
176
views
C++ behavior as a template argument
I would like to have a class, let's say a queue, that can be specialized to its behavior. For example, let them be a SafeQueue (which disables IRQs before any access) and a FastQueue (which doesn't). ...
1
vote
0
answers
90
views
Is it bad practice to specialize template method to implement strategy pattern in C++?
I came across a class that implements a kind of "strategy pattern" with a concrete implementation defined inside the main class as a template method.
#include <iostream>
struct ObjA {
...
0
votes
3
answers
2k
views
Is it possible to instantiate a template class at runtime?
Suppose I have two abstract classes called Color and Animal
And I can create classes Green/Red/Blue derived from Color and classes Dog/Cat/Pig derived from Animal at runtime using factory pattern.
...
7
votes
2
answers
1k
views
How to generate java class files with framework boilerplate in a project?
The Java project I am working on currently has a complicated folder structure, and to add a new functionality, one needs to add many .java files in different places in order to let it work in our ...
1
vote
1
answer
160
views
C++20, specialize struct once per type and allow member functions to take type as reference, raw, std::unique|shared_ptr or any other smart ptr
Situation
I have some existing functions which expect containers which can be iterated and which have certain value_type. The value_type can be a value or some (smart) pointer.
All the value_type have ...
-3
votes
2
answers
431
views
Using templates to define sizes of containers?
Is using templates for specifying capacities of containers a good use or misue of the templates? Eg.
template <unsigned int Length>
class String {
public:
String();
String(String& ...
0
votes
2
answers
109
views
Design for generating/filling a document based on a template-file, while considering permissions from a database?
You have the backend for a web application. I'd like to keep this is as disconnected from specific programming lanuages as possible, but if necessary, assume we're talking about PHP.
You need to write ...
0
votes
2
answers
571
views
Template argument type exclusion: Would this make for a useful C++ feature?
When using templates we can have T be any type upon class instantiation. If T is a specific type that needs to be handled differently or in a special way we can specialize or partial specialize that ...
1
vote
1
answer
146
views
Templates for generic code and code flexibility
I have a data which is a std::vector of a "small collection" of items of a given type struct Bunny {};.
I was vague about "small collection" because for now it's a collection of ...
1
vote
1
answer
154
views
Is this a good use of template specialization? Or should the factory method be used?
I have a program that involves two different data structures, and so I created a class that acts as a generalized data structure that either of the original two can be represented as. (Because the ...
5
votes
1
answer
252
views
Create C++14 library where each class has 2 similar variants
I'm writing a C++ library which does some computation on vectors of audio data.
The library supports both GPU (using Thrust, a C++ STL-like library for GPUs) and CPUs (using the STL). I'm using CUDA ...
0
votes
1
answer
86
views
MVC (templates): is it OK to call functions with arguments from the View?
In a MVC scenario, is it OK to pass arguments to functions from the View to satisfy different formatting needs?
For example: let's say that the model has a DateTime object and the view must show this ...
2
votes
2
answers
468
views
C++: Achieving a decoupled "Definition is Registration" paradigm for derived classes?
I'm trying to engineer this:
200 subclasses [ Derived Classes ]
After a subclass is defined, I wont need to edit any other file. [ Decoupled ]
Subclass Definition registers itself. [ Definition is ...
0
votes
0
answers
39
views
Template engine design question?
I don't know if this is the proper forum for the question as any answers will be rather subjective. But here it goes, please advise if there is a better place to ask this.
I am designing a small ...
2
votes
4
answers
2k
views
Why doesn't C++ support covariance in STL containers like C# or Java?
The Covariance and Contravariance feature is well supported in C# and Java collections. However C++ doesn't support them in their STL containers. Why is it so?
For example the below code will ...
1
vote
2
answers
399
views
C++ tactics / data structures / design patterns to avoid or postpone unnecessary object creation?
A couple of months ago I wrote a C++ program for computational mathematics that was supposed to compete with a highly optimized C code.
After a while I did manage to get it fast enough to beat the C ...
3
votes
1
answer
2k
views
C++ design pattern for template instantiation based on run time information?
Say I want to be able to create objects for a range of template parameter
template<int a> class Myclass : public MyclassSuper{...};
And I want to create objects like
Myclass<...
3
votes
3
answers
201
views
A better way to generate plaintext content
I'm generating plaintext emails with heavily personalized content: depending on various factors, sections or sentences need to be inserted, left out or phrased differently and placeholders need to be ...
0
votes
0
answers
246
views
c++ templates - combining deduction with default template arguments
I have a simple class (details here)
namespace MemoizerSupport {
template <typename T1, typename T2>
using DEFAULT_CACHE = LRUCache<T1, T2>;
}
template <typename RESULT, ...
0
votes
1
answer
47
views
Is it appropriate to have a template get "streamed" data while rendering?
I'm dealing with code that renders HTML pages. I'm cleaning up an old, messy PHP code base.
Let's say I have a template that loops through a long list of rows in a database. I can load my data into ...
16
votes
4
answers
8k
views
C++ Preferred method of dealing with implementation for large templates
Typically when declaring a C++ class, it is best practice to put only the declaration in the header file and put the implementation in a source file. However, it seems that this design model does not ...
0
votes
1
answer
120
views
What are the advantages of dynamic configuration based form templates?
When developing an application which presents the user with many similar forms for data entry, a common approach is to build a framework for defining the form structure in a standardised configuration ...
0
votes
1
answer
752
views
Is there a coding style for Blade templates?
Since when I used smarty I always tried to separate logic statements from html tags, so my approach to blade would be to write:
template.blade.php
<div>
<div>
@if ($something == true)...
1
vote
1
answer
236
views
Web Design Pattern For Displaying Dynamic Content
I currently have a WinForms app that uses XML documents to drive dynamic content that is shown to the user. I call these XML documents template files.
The template file determines the features the ...
1
vote
1
answer
523
views
Responsibility of message template for OTP microservice
We want to design a solution for generation and validation of OTP(One Time Password) process. We decided to create OTP process as a separate micro service. Since OTP need to be communicated to users ...
0
votes
1
answer
447
views
T4 Template vs manual conversion in C#
I need to convert a large number of XML files into JSON. The XML files all have same structure, and differs only in data that they contain.
I could write a basic C# utility that would parse XML and ...
0
votes
3
answers
3k
views
What approaches can be used to convert existing JSON structure to existing XML structure?
I am working on a component for an enterprise message queue that consumes a message from a queue and sends it as a text message. The message is picked up by my consumer in JSON format (I do not have ...
1
vote
1
answer
80
views
Handling more specialized interface with no code duplication
I have the following code:
struct AInterface {
XXX some_method(/* some params */) = 0;
};
void foo(const AInterface & a) {
do_work();
while (x) {
do_work_2();
...
5
votes
2
answers
1k
views
When one should use template specialization, if not for metaprogramming?
When do we use template specializations for in C++, if not for SFINAE or metaprogramming? type_traits, enable_if and others rely on it a lot, but I'm more curious about situations which are more "...
1
vote
0
answers
478
views
Dependency injection in the template class
I have a template wrapper class around the container std::priority_queue that supports multithreading. The short version of it is below. In this class I employ the function IsReady() that checks ...
3
votes
1
answer
963
views
C++ generic graph search algorithm with generic data types
I'm trying to implement a generic graph search algorithm in C++, as part of assignment at university, and I encountered problems when trying to implement it, mostly struggling with templates. this is ...
4
votes
2
answers
3k
views
Was template meta programming really discovered "by accident"? [closed]
When I first saw this meme:
I thought to myself, yeah right, but now I am not sure any more. So was template meta programming in C++ discovered by accident as the meme claims or was it intentional?
...
0
votes
2
answers
951
views
template restrictions in C++
I am creating a template class in C++ for numeric operations and I want to restrict it to only numbers or similar numeric types. My question is that is there any way in C++ to restrict a template ...
11
votes
1
answer
10k
views
Way for generating C# classes from existing C# class
I have simple POCO classes, like this:
public class Book
{
public string BookId { get; set; }
public string Name { get; set; }
//etc...
}
I want to get all those classes and generate ...
0
votes
1
answer
2k
views
When do I use square brackets around routerLink in Angular2?
In Angular 2 (currently 2.0.0-rc.6), routerLink is used as a directive to indicate a path we wish to follow in our routing, e.g. in response to clicking a link.
However, in the documentation both of ...
4
votes
2
answers
897
views
C++ function (de)duplication in templatized classes
Please have a look at this code snippet:
template<int N> class Foo {
public:
int f() { return N; }
int g() { return 0; }
};
Foo<3> a;
Foo<4> b;
I think it's compiler ...
-2
votes
1
answer
270
views
What is an efficient way to implement 'Stack' without generics?
Today I was reading a lot of articles complaining about Java Generics or C++ Templates. Now, my question is: How can someone implement a collection data structure like Stack without using them?
7
votes
1
answer
1k
views
Can the C++ template system be used to perform type safe operations of the relational algebra
Assume that the parameters of functions representing operations of the relational algebra are represented by individual types: structs or classes. An operation such as (natural) join will have ...
0
votes
1
answer
177
views
JavaScript templating trick or treat?
I've recently been looking into using JavaScript for templating and I was wondering about the legibility of using this approach.
I understand that JavaScript templating is a very common and much ...
1
vote
1
answer
409
views
Get or infer template type from inherited member
So I have an assignment from college where I have to apply multiple metaheuristics to different problems. I thought that I should make everything as modular and reusable as possible to reuse ...
2
votes
2
answers
3k
views
C++ Parametric Polymorphism
In the wikipedia article on Parametric Polymorphism, is the following commentary on C++. Can anyone explain what it's referring to when talking about "ad hoc aspects"? (I think it needs a citation)....
1
vote
0
answers
250
views
User-editable templates for reporting: alternatives to word? [closed]
Not sure if this is the right platform for this, but here goes :) Throughout my career I have been generating reports for users, and most of the times it always started from a Word template (.dot/....
2
votes
2
answers
1k
views
Why are the smart folks who write and adopt react.js okay with the way markup is tightly-coupled/buried inside Javascript?
Quite a while ago there was a concerted trend in the industry to move towards adopting templating to separate markup from logic, or something like that. The result was much more pleasing to the eye ...
0
votes
1
answer
366
views
Can I use an external Mustache template without Ajax?
I wrote up a site using Mustache to template it. Right now though, the template is embedded in the page, which defeats the purpose of using the template since I'll need to copy it to any other pages ...
1
vote
1
answer
318
views
Is opening a templating engine to users a bad idea?
My site allows users to create custom HTML templates for their profiles (very much like Tumblr and the theme system), and I picked the Twig template engine for the site.
However, I'm not sure if it'...
8
votes
1
answer
21k
views
Template Function: Passing Iterators
I am struggling with making a design choice in the following setup:
I am writing (C++) functions which take a pair of iterators (to template containers) and compute a return value of the same type ...
5
votes
1
answer
609
views
Command pipeline design question - where to place validation?
Here is the situation:
I have a database and a class that is basically a representation of a set of fields of different tables in it. Let's call it Message.
"Message" does not know of the database ...
1
vote
1
answer
95
views
Templating a member name
I'm writing a library that provides graphs for search algorithms.
Usually you want to rank nodes using a priority queue.
Normally you want to search for an specific node in the queue and lower its ...