Questions tagged [templates]

The templates tag is used in multiple contexts: generic programming (especially C++), and data/document generation using template engines. 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 .

49783 questions
1948
votes
17 answers

Why can templates only be implemented in the header file?

Quote from The C++ standard library: a tutorial and handbook: The only portable way of using templates at the moment is to implement them in header files by using inline functions. Why is this? (Clarification: header files are not the only…
MainID
  • 25,722
  • 19
  • 53
  • 70
1206
votes
8 answers

Where and why do I have to put the "template" and "typename" keywords?

In templates, where and why do I have to put typename and template on dependent names? What exactly are dependent names anyway? I have the following code: template // Tail will be a UnionNode too. struct UnionNode :…
MSalters
  • 159,923
  • 8
  • 140
  • 320
593
votes
10 answers

Use 'class' or 'typename' for template parameters?

Possible Duplicate: C++ difference of keywords ‘typename’ and ‘class’ in templates When defining a function template or class template in C++, one can write this: template ... or one can write this: template ... Is there…
Kristopher Johnson
  • 76,675
  • 54
  • 235
  • 299
592
votes
6 answers

Difference of keywords 'typename' and 'class' in templates?

For templates I have seen both declarations: template < typename T > template < class T > What's the difference? And what exactly do those keywords mean in the following example (taken from the German Wikipedia article about templates)? template <…
Mat
  • 9,423
  • 10
  • 40
  • 48
587
votes
13 answers

Storing C++ template function definitions in a .CPP file

I have some template code that I would prefer to have stored in a CPP file instead of inline in the header. I know this can be done as long as you know which template types will be used. For example: .h file class foo { public: template…
Rob
  • 70,036
  • 53
  • 151
  • 189
539
votes
31 answers

Templated check for the existence of a class member function?

Is it possible to write a template that changes behavior depending on if a certain member function is defined on a class? Here's a simple example of what I would want to write: template std::string optionalToString(T* obj) { if…
andy
  • 16,174
  • 9
  • 28
  • 27
518
votes
46 answers

Seeking useful Eclipse Java code templates

You can create various Java code templates in Eclipse via Window > Preferences > Java > Editor > Templates e.g. sysout is expanded to: System.out.println(${word_selection}${});${cursor} You can activate this by typing sysout followed by…
Jon
  • 55,763
  • 30
  • 120
  • 149
468
votes
7 answers

Explanation of

I just stumbled upon something I've never seen before. In the source of Backbone.js's example TODO application (Backbone TODO Example) they had their templates inside a , which contained code that looks like…
Matt
  • 19,783
  • 24
  • 71
  • 113
413
votes
22 answers

How to dynamically change header based on AngularJS partial view?

I am using ng-view to include AngularJS partial views, and I want to update the page title and h1 header tags based on the included view. These are out of scope of the partial view controllers though, and so I can't figure out how to bind them to…
Michael Low
  • 23,431
  • 15
  • 75
  • 115
398
votes
1 answer

C++ template typedef

I have a class template class Matrix { // .... }; I want to make a typedef which creates a Vector (column vector) which is equivalent to a Matrix with sizes N and 1. Something like that: typedef Matrix Vector; Which…
Notinlist
  • 14,748
  • 9
  • 51
  • 92
397
votes
0 answers

Pretty-print C++ STL containers

I would like to have a single template that once and for all takes care of pretty-printing all STL containers via operator<<. In pseudo code, I'm looking for something like this: template
Kerrek SB
  • 428,875
  • 83
  • 813
  • 1,025
385
votes
7 answers

What is the difference between <%, <%=, <%# and -%> in ERB in Rails?

Can some one please describe the usage of the following characters which is used in ERB file: <% %> <%= %> <% -%> <%# %> what's the usage of each one ?
simo
  • 20,548
  • 31
  • 101
  • 188
334
votes
13 answers

Can a class member function template be virtual?

I have heard that C++ class member function templates can't be virtual. Is this true? If they can be virtual, what is an example of a scenario in which one would use such a function?
WannaBeGeek
  • 3,446
  • 3
  • 15
  • 9
313
votes
7 answers

JSP tricks to make templating easier?

At work I've been tasked with turning a bunch of HTML files into a simple JSP project. It's really all static, no serverside logic to program. I should mention I'm completely new to Java. JSP files seem to make it easy to work with common includes…
Scott
  • 4,008
  • 3
  • 19
  • 16
288
votes
28 answers

How can I add reflection to a C++ application?

I'd like to be able to introspect a C++ class for its name, contents (i.e. members and their types) etc. I'm talking native C++ here, not managed C++, which has reflection. I realise C++ supplies some limited information using RTTI. Which additional…
Nick
  • 25,635
  • 12
  • 56
  • 71
1
2 3
99 100