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

Expression contains unexpanded parameter packs

Somehow I don't get how variadic template parameter packs are expanded. What's wrong with thie following code? #include template struct print_one { static void run(const T& t) { std::cout << t << ' '; …
marton78
  • 3,899
  • 2
  • 27
  • 38
17
votes
1 answer

C++ class template is a template: template argument is invalid

I have a problem with a class template. I want the private data in a class to be a vector of vectors of some kind of numeric type, i.e: std::vector > std::vector > > But I want the type of vector…
jtravs
  • 321
  • 1
  • 3
  • 9
17
votes
1 answer

How can I check if a type is an instantiation of a given class template?

Is it possible to check that a type is an instantiation of a particular template? I have a class template where one of the template parameter must be either an instantiation of a particular template, or some other type. For instance, consider this…
Luc Touraille
  • 79,925
  • 15
  • 92
  • 137
17
votes
4 answers

Use of undeclared identifier in C++ with templates and inheritance

The following code cannot compile - use of undeclared identifier. I use GCC and XCode for compilation. Everything is in a single header file. include "MyArray.h" template class MyBase { public: MyBase(); virtual ~MyBase(); void…
user1414745
  • 1,317
  • 6
  • 25
  • 45
17
votes
5 answers

Understanding the benefits of move semantics vs template metaprogramming

I've read some descriptions about move semantics in C++11 and I wonder in what context it could be used. Currently, many C++ math libraries use template metaprogramming to delay evaluation. If M = A + B + C*D, where M, A, B, C and D are matrix,…
Vincent
  • 57,703
  • 61
  • 205
  • 388
16
votes
6 answers

How to iterate an object with Handlebars?

It is easy to iterate an array with Handlebars.js like: {{#each comments}}

{{title}}

{{{{url}}}
{{/each}} and an array like: { comments: [ { url: "http://www.yehudakatz.com", title: "Katz Got Your…
Ferran Basora
  • 3,097
  • 3
  • 19
  • 13
16
votes
2 answers

Specializing a variadic template template parameter on the minimum number of arguments: legal or not?

I have code: #include template class> struct Foo { enum { n = 77 }; }; template class C> struct Foo { enum { n = 99 }; }; template struct A {…
glaebhoerl
  • 7,695
  • 3
  • 30
  • 41
16
votes
4 answers

How can I use template specialization in c++ classes, and why this doesn't compile?

I am working on a XmlWriter class, and I wanted to be able to output attributes or text in most standard data formats (strings, integers, floating point numbers etc). To achieve this, I am using a file stream. For the bool data type, I wanted to…
Tibi
  • 4,015
  • 8
  • 40
  • 64
16
votes
7 answers

CakePHP View including other views

I have a CakePHP application that in some moment will show a view with product media (pictures or videos) I want to know if, there is someway to include another view that threats the video or threats the pictures, depending on a flag. I want to use…
Fernando Barrocal
  • 12,584
  • 9
  • 44
  • 51
16
votes
5 answers

Include .cpp file?

Possible Duplicate: Why can templates only be implemented in the header file? I've been trying around with C++ recently. At the moment I'm trying to program something I'm sure everone has done at least once: A simple LinkedList class. The code is…
haiyyu
  • 2,194
  • 6
  • 22
  • 34
16
votes
1 answer

NodeJS + Express + Handlebars - failed to locate view "index.html"

I have been playing a bit with Node.js. I recently started toying with Express and have been setting up a basic app. I wanted to use Handlebars as my view templating engine, but am hitting a wall - failed to locate view "index.html" I have…
mattezell
  • 607
  • 1
  • 6
  • 13
16
votes
2 answers

Why are template mixins in C++ not more of a mainstay?

I use template mixins in C++ a lot, but I'm wondering why the technique isn't used more. It seems like the ultimate in reuse. This mix of power and efficiency is one of the reasons I really love C++ and can't see myself moving to a JIT…
Jesse Pepper
  • 3,225
  • 28
  • 48
16
votes
2 answers

passing a variable into a jinja import or include from a parent html file

The scenario would be: "you have a variable called person which contains a number of fields like name, address, etc which you want to pass to a partial piece of html" - this solution could be results from a search for customers for…
Jay
  • 2,715
  • 8
  • 33
  • 33
16
votes
3 answers

How can a class inherit from a template based on itself?

While reading an article, I came across the following syntax: template class MyTemplate { T* member; T* method(); // ... } class MyClass : public MyTemplate { // ... } I don't exactly understand how MyClass…
Dan Nestor
  • 2,441
  • 1
  • 24
  • 45
16
votes
5 answers

Run Template in Template (recursion) within underscore.js template engine

I am using backbone.js and underscore.js to build an javascript application. Since hours of reading and trying to run a template within a template like below, it is getting more and more frustrating. My template using the build in underscore.js…