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
17
votes
2 answers

Template specialization for multiple types

Title is a little ambiguous. Lets say I have a template defined as: template < typename T > void foo ( int x ) ; template <> void foo ( int x ) ; template <> void foo ( int x ) ; template <> void foo ( int x )…
Twifty
  • 3,267
  • 1
  • 29
  • 54
17
votes
3 answers

Doing a static_assert that a template type is another template

How do I static_assert like this? Maybe Boost supports it if not C++ or new features in C++11? template struct foo {}; template struct bar { static_assert(FooType is indeed foo for some T,"failure"); //how? };
roger.james
  • 1,478
  • 1
  • 11
  • 23
17
votes
14 answers

JQuery's $ is in conflict with that of StringTemplate.Net in ASP.Net MVC

I am exploring ASP.NET MVC and I wanted to add jQuery to make the site interactive. I used StringTemplate, ported to .Net, as my template engine to generate html and to send JSON. However, when I view the page, I could not see it. After debugging,…
OnesimusUnbound
  • 2,886
  • 3
  • 30
  • 40
17
votes
2 answers

What are the expression syntax over types C++ support?

I was working with a templated class which takes a set of integers. The code was like, template struct work{ ... }; Then I realized, user may need to provide either a set of integers, or a range of integers. So, I changed the…
abir
  • 1,797
  • 14
  • 26
17
votes
2 answers

Declaring member or not depending on template parameter

Is it possible to declare or not a member variable depending on template condition without using dummy empty type? Example: struct empty{}; struct real_type{}; template struct foo { typename std::conditional
Mircea Ispas
  • 20,260
  • 32
  • 123
  • 211
17
votes
7 answers

Class 'is not a template type'

What does this error mean? Generic.h:25: error: 'Generic' is not a template type Here's Generic. template class Generic: public QObject, public CFG, public virtual Evaluator { Q_OBJECT std::string key_; …
Scott
  • 5,135
  • 12
  • 57
  • 74
17
votes
3 answers

Why can't a struct be passed as value as template non-type parameter?

Non-type template parameters are obviously ones that aren't types, for example: template void foo() { cout << x; } There are other options than int in that case, and I'd like to refer to this great answer. Now, there's one thing that bugs…
Bartek Banachewicz
  • 38,596
  • 7
  • 91
  • 135
17
votes
1 answer

What does “In instantiation of … required from here” mean?

I get the following compiler¹ message main.cpp: In instantiation of ‘void fkt(Foo) [with Foo = int]’: main.cpp:5:7: required from here The binary is created anyway, so it's not an error. But it's also not marked as a warning. What is this message…
Marco
  • 849
  • 1
  • 7
  • 21
17
votes
3 answers

How to organize resources (styles, ...) in a complex WPF scenario?

How can WPF resources - including styles, templates, etc. - be organized, so that I can use them across Windows, Pages or even Projects. What options do I have to achieve maximum re-usability of my resources and a maintainable structure (for example…
Libor Zapletal
  • 13,752
  • 20
  • 95
  • 182
17
votes
7 answers

Learning C++ Templates

Can anyone recommend any good resources for learning C++ Templates? Many thanks.
Dynite
  • 2,313
  • 5
  • 30
  • 38
17
votes
3 answers

Is casting std::pair const& to std::pair const& safe?

Is it safe (in theory or in practice) to reinterpret_cast a std::pair const & into a std::pair const &, assuming that the programmer hasn't intentionally done something weird like specializing std::pair?
user541686
  • 205,094
  • 128
  • 528
  • 886
17
votes
2 answers

Optimize templates compilation time in c++/gcc

In a large project we have a lot of classes (thousands), and for each of them a special smart pointer type is defined using typedef. This smart pointer type is a template class. When I compile with "gcc -Q" I see that a lot of time is spent…
queen3
  • 15,333
  • 8
  • 64
  • 119
17
votes
3 answers

C++ template-argument dependent decltype in ABI mangled name

Consider the following function: template auto Min(A&& a, B&& b) -> decltype(a < b ? std::forward(a) : std::forward(b)) { return a < b ? std::forward(a) : std::forward(b); } The fragment Min(0, 1)…
Travis Gockel
  • 26,877
  • 14
  • 89
  • 116
17
votes
4 answers

Can a function type be a class template parameter?

The code below is rejected by VC++ 2012 with "error C2207: 'A::bar' : a member of a class template cannot acquire a function type". int Hello(int n) { return n; } template struct A { A(FunctionPtr foo) : bar(foo) …
xmllmx
  • 39,765
  • 26
  • 162
  • 323
17
votes
3 answers

How to pass parameters to PHP template rendered with 'include'?

need your help with PHP templating. I'm new to PHP (I'm coming from Perl+Embperl). Anyway, my problem is simple: I have a small template to render some item, let it be a blog post. The only way i know to use this template is to use 'include'…
Uruloki