Skip to main content

Questions tagged [templates]

The tag has no usage guidance.

Filter by
Sorted by
Tagged with
1 vote
1 answer
183 views

Using templates without generic implementation

Is it a good practice to declare a template class, but only with specialized implementations ? Ie, there are many CRC flavours (see https://en.wikipedia.org/wiki/Cyclic_redundancy_check#...
Oodini's user avatar
  • 121
0 votes
1 answer
78 views

Identify downsides: versioning auto-generated Terraform source code [closed]

HINT: the purpose of this question is to identify downsides for the scenario described. If something is a downside, then it should be quantifiable and it should clearly have a negative impact. ...
pgpb.padilla's user avatar
0 votes
0 answers
69 views

What is the use case for blocks in template engines?

Most template engines have two ways to refer to other templates: Inheritance with blocks (child template inherits from parent template and fills one or more blocks) Includes (parent template includes ...
Toxiro's user avatar
  • 101
-1 votes
2 answers
132 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 ...
Divan's user avatar
  • 349
1 vote
1 answer
92 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 (...
Joshua Frank's user avatar
2 votes
1 answer
261 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). ...
JD.'s user avatar
  • 131
1 vote
0 answers
101 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 { ...
Delgan's user avatar
  • 366
0 votes
3 answers
3k 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. ...
Xie Qing's user avatar
7 votes
2 answers
2k 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 ...
teamol's user avatar
  • 1
1 vote
1 answer
186 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 ...
ridilculous's user avatar
-3 votes
2 answers
726 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& ...
r0k1m's user avatar
  • 851
1 vote
2 answers
162 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 ...
Lux's user avatar
  • 31
1 vote
2 answers
1k 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 ...
Francis Cugler's user avatar
1 vote
1 answer
150 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 ...
Enlico's user avatar
  • 130
1 vote
1 answer
193 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 ...
Aaron's user avatar
  • 19
5 votes
1 answer
254 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 ...
Sevag's user avatar
  • 179
0 votes
1 answer
94 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 ...
Dr. Gianluigi Zane Zanettini's user avatar
2 votes
2 answers
586 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 ...
Anon's user avatar
  • 3,613
0 votes
0 answers
44 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 ...
Andrew Erwin's user avatar
4 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 ...
Sisir's user avatar
  • 858
1 vote
2 answers
450 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 ...
mathreadler's user avatar
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<...
mathreadler's user avatar
3 votes
3 answers
202 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 ...
chiborg's user avatar
  • 273
0 votes
0 answers
250 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, ...
Lewis Pringle's user avatar
0 votes
1 answer
49 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 ...
duckbrain's user avatar
  • 151
16 votes
4 answers
11k 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 ...
fhorrobin's user avatar
  • 271
0 votes
1 answer
128 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 ...
ses's user avatar
  • 19
1 vote
1 answer
779 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)...
Crayon's user avatar
  • 119
1 vote
1 answer
272 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 ...
scott_f's user avatar
  • 113
1 vote
1 answer
540 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 ...
nak's user avatar
  • 153
0 votes
1 answer
461 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 ...
digitguy's user avatar
  • 131
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 ...
Chris Maggiulli's user avatar
1 vote
1 answer
82 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(); ...
Svalorzen's user avatar
  • 467
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 "...
yeputons's user avatar
  • 334
1 vote
0 answers
501 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 ...
Konstantin's user avatar
3 votes
1 answer
1k 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 ...
David's user avatar
  • 33
4 votes
2 answers
4k 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? ...
Mr. Developerdude's user avatar
0 votes
2 answers
1k 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 ...
Suhas Srivastava's user avatar
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 ...
Yurii N.'s user avatar
  • 341
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 ...
Andrew Willems's user avatar
4 votes
2 answers
1k 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 ...
Toni Homedes i Saun's user avatar
-2 votes
1 answer
297 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?
Mahdi's user avatar
  • 189
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 ...
david.pfx's user avatar
  • 8,077
0 votes
1 answer
182 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 ...
Brummy's user avatar
  • 13
1 vote
1 answer
421 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 ...
carloscb's user avatar
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)....
spirc's user avatar
  • 280
1 vote
0 answers
252 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/....
nathanvda's user avatar
  • 151
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 ...
tacos_tacos_tacos's user avatar
0 votes
1 answer
372 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 ...
Carcigenicate's user avatar
1 vote
1 answer
324 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'...
Dubstaphone's user avatar