Questions tagged [templates]

The templates tag is used in multiple contexts: generic programming (especially C++), and data/document generation using template engines, web template for a pre-designed webpage, or set of HTML webpages. When using this tag on implementation heavy questions - tag the code language the implementation is written in.

The templates tag is used in multiple contexts:

###C++ templates

Templates in allow for generic programming and . The C++ Book Guide contains books treating templates as well, especially:

Before asking a question, consider looking into these FAQs first:

There are also useful questions on StackOverflow:

Books

###Other templates (PHP, django, drupal, mediawiki, etc.)

There are several varieties of template engines used with web servers, web applications, and web scripting languages. Questions for these types of templates should use the language specific tag.

The web server or scripting language templates are different from templates as used in or generics as used in . These templates are used to help with separating view or presentation of data with the business logic generating or transforming the data.

PHP template questions should use the specific template product tag such as , , etc.

django template questions should use .

drupal template questions should use .

mediawiki template questions should use .

54454 questions
16
votes
1 answer

Deduction guides, templates and subobjects: which compiler is right?

Consider the following snippet: struct S { S() {} template struct T { T(B &&) {} }; template T(B &&) -> T; }; int main() { S::T t{0}; } Clang accepts it while GCC rejects the code…
skypjack
  • 49,335
  • 19
  • 95
  • 187
16
votes
2 answers

Is `template;` legal C++?

GCC and Clang disagree on whether template; is a valid statement in C++ at global scope. I'd expect it not to be allowed in the C++ standard because templatization pertains to declaration statements, not to expression statements and in…
Fytch
  • 1,067
  • 1
  • 6
  • 18
16
votes
9 answers

Typesafe variadic function

I want to write a function that accepts a variable number of string literals. If I was writing in C, I would have to write something like: void foo(const char *first, ...); and then the call would look like: foo( "hello", "world", (const…
16
votes
6 answers

PHP Looping Template Engine - From Scratch

For a group project I am trying to create a template engine for PHP for the people less experienced with the language can use tags like {name} in their HTML and the PHP will replace that tag with a predefined variable from an array. As well as…
Pez Cuckow
  • 14,048
  • 16
  • 80
  • 130
16
votes
4 answers

How do I make a template parameter's constructor a friend?

In C++11, they made it possible to friend a template parameter simply with friend T. You can also friend methods within that parameter with friend T::Method(). However, how do you friend a template parameter's constructor? class…
irfna
  • 525
  • 1
  • 4
  • 13
16
votes
6 answers

checking invariants in C++

Are there any established patterns for checking class invariants in C++? Ideally, the invariants would be automatically checked at the beginning and at the end of each public member function. As far as I know, C with classes provided special before…
fredoverflow
  • 256,549
  • 94
  • 388
  • 662
16
votes
1 answer

Non-dependent name lookup and lambda

I have the following code: template class Outer { public: Outer(); template void templateFunc() { } private: class Inner { public: Inner(Outer& outer) { …
16
votes
7 answers

A C++ iterator adapter which wraps and hides an inner iterator and converts the iterated type

Having toyed with this I suspect it isn't remotely possible, but I thought I'd ask the experts. I have the following C++ code: class IInterface { virtual void SomeMethod() = 0; }; class Object { IInterface* GetInterface() { ... } }; class…
El Zorko
  • 3,349
  • 2
  • 26
  • 34
16
votes
1 answer

Partial template specialization with multiple template parameter packs

Continuing my journey into the world of variadic templates, I encountered another problem. Assuming the following template class: template < typename T > struct foo { //default implementation }; it is possible to partially specialize it for…
Luc Touraille
  • 79,925
  • 15
  • 92
  • 137
16
votes
1 answer

What is template<> template<> syntax in the context of template-alias for?

(This question is not about template template arguments.) I just discovered that GCC compiles such code template struct P {}; template template using Q = P; where Q is a doubly-templated…
Yuri Syro
  • 549
  • 2
  • 16
16
votes
1 answer

NgStyle returns: ERROR Error: Cannot find a differ supporting object '{"background-color":"blue"}'

With this in my template, HELLO And this in my component, myStyle(): string { return '{"background-color":"blue"}' } I'm getting ERROR Error: Cannot find a differ supporting object…
Evan Carroll
  • 78,363
  • 46
  • 261
  • 468
16
votes
3 answers

What template engine should I use in Spring MVC?

I'm learning Spring MVC and want to create a site. The main problem is a template system. Should I use JSP / JSF / Apache FreeMarker / Thymeleaf or something else? I saw a lot of discussion on this subject, but they are all outdated. So, I'm…
Sergey Bakotin
  • 373
  • 1
  • 3
  • 15
16
votes
4 answers

How to tell if a type is an instance of a specific template class?

I have a function that takes a template type to determine a return value. Is there any way to tell at compile time if the template type is some instantiation of a template class? Ex. class First { /* ... */ }; template class Second {…
Cameron Rowe
  • 223
  • 2
  • 5
16
votes
2 answers

mustache.js vs. jquery-tmpl

I'm looking at javascript templating for the first time and mustache and jquery-tmpl are the top contenders at the moment. Some of my requirements: templates will live in separate files to be included on multiple pages all (or almost all) data…
sprugman
  • 19,351
  • 35
  • 110
  • 163
16
votes
2 answers

Why is gcc failing when using lambda for non-type template parameter?

The following snippet compiles with no error with Clang 4.0 but GCC 7.0 produces errors (note the use of -std=c++1z flag). using FuncT = int (*)(double); template int temp_foo(double a) { return FUNC(a); } int foo(double a) { …
dcmm88
  • 1,445
  • 1
  • 12
  • 30