Questions tagged [templates]
The templates tag has no usage guidance.
119
questions
-3
votes
2
answers
106
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
60
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
227
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
128
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
101
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
237
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
68
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
284
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
37
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
1k
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
324
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 ...
2
votes
1
answer
804
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
199
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
240
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
45
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 ...
14
votes
4
answers
5k
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
80
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
678
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
190
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
463
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
401
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
2k
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
79
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
381
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
889
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
1
answer
751
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 ...
10
votes
1
answer
9k
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
708
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
258
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
169
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
374
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
249
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
360
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
310
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
20k
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
565
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
93
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 ...
7
votes
1
answer
464
views
Whether to abstract small repeating code segments in HTML templates?
(The framework used in question is AngularJS so the question can be translated as "Whether to introduce Directives for small repeating code segments in Views")
As a developer who focuses on Java ...
21
votes
4
answers
3k
views
What about LISP, if anything, makes it easier to implement macro systems?
I'm learning Scheme from the SICP and I'm getting the impression that a big part of what makes Scheme and, even more so, LISP special is the macro system. But, since macros are expanded at compile-...
1
vote
1
answer
10k
views
C++ Templates where the type is a shared_ptr
When creating template classes in C++, if the type upon which the template will be specialized is intended to be a shared_ptr type, is it better to make T a shared_ptr type or make T a non-pointer ...
0
votes
2
answers
4k
views
What is the best approach for PHP mail templates
I'm working on a webshop (used to be for just one product, expanding it to multiple products and multiple shops hooked up to one backoffice, can't use PrestaShop because of compatibility).
We send 3 ...
1
vote
1
answer
425
views
C++ Template Metaprogramming and Call By Need Evaluation
I recently wrote a fairly complex C++ meta function that boils down to:
template <size_t N, typename val>
struct Rec {
using type = typename std::conditional<N == 0,
val,
...
0
votes
1
answer
50
views
Scoping template variables in "has-a" (compositional) relationships
I'm developing a new templating language for PHP, and one of the features is an object-oriented approach to nested child templates. For example, I can declare an object of type HtmlBuilder like this:
...
-1
votes
2
answers
473
views
Bootstrap licence free template
I´m creating a new website. For that I´m using a free bootstrap template. On top of my index page I have:
A Design by W3layouts
Author: W3layout
Author URL: http://w3layouts.com
License: ...