templates

Is it possible to overload a template class?

I found that template method could be overloaded, can I do the same on template classes? If 2 template classes match a template class instantiation, we can use the parameter type in the constructor to deduce which one to use. template <typename T> class A{ A(T){} }; template <typename T> class A{ A(T*){} }; int main(){ A<int*> ...

Simple C++ template definition problem.

I'm new to C++. Here is the code: template <class T> typename lw_slist { // .... some code private: typedef struct _slist_cell { _slist_cell *next; T data; } slist_cell; lw_slist::slist_cell *root; }; Give this compilation error: error C4430: missing type specifier - int ...

C++ - Operating on a string before runtime.

I have a string: B<T>::B() [with T = int] Is there any way I can get B<T> [with T = int] from this before run time somehow? :) EDIT: Simplifying: Is there any way to get X & Y separately from a static string XY defined as a preprocessor macro in any form before runtime? ...

XSL Use a specific template inside another one

Hello, I've got some problems with XSL : is it possible to use a template from another one, when it uses an apply-templates to print childs ? I don't want to use current node, but really create a new element matching the template. Example of what I'm searching : XML file : <root> <toto name="foo"> <b>hello</b> </toto> </root>...

How to output unsigned/signed char or <cstdint> types as integers with << in C++

Background: I have template stream operators (e.g. operator << (ostream &, std::vector <T>)) (that output container elements that may possibly be of some 8-bit integer type, (e.g. unsigned char, int_least8_t, et cetera). Problem: Default is that these types are output as char (ASCII). I only used char (or wchar_t or whatever) for ASCI...

Why default argument cannot be specified for an explicit template specialization?

The below code couldn't pass the compilation, what's the consideration for this compiler error? template<class T> void f(T t) {}; template<> void f<char>(char c = 'a') {} Error message: Default arguments are not allowed on an explicit specialization of a function template ...

Determination of type in function template

Hi all! I would like to ask you for an advice about function template. I have a function that adds some data into buffer. But I need also to add an information about data type into the buffer. The type of data is a following enum: enum ParameterType { UINT, FLOAT, DOUBLE }; And I need to create a function template from funct...

Not repeating types used as template parameters

Given the code below is there a nicer way to right it that doesn't repeat typename std::iterator_traits<T>::iterator_category twice? template<class T, class T2> struct foo : bar< foo<T, T2>, typename std::conditional< std::is_same<typename std::iterator_traits<T>::iterator_category, //R...

two nearly identical calls, one works one fails.

I have these template functions for use inline on device with cuda template <class T> __device__ inline T& cmin(T&a,T&b){return (a<b)?(a):(b);}; template <class T> __device__ inline T& cmax(T&a,T&b){return (a>b)?(a):(b);}; In the code I have cmin(z[i],y[j])-cmax(x[i],z[j]) for int arrays x,y,and z. I get the error: error: no ...

Template in a Template -- accessing contained type from a template type

I was trying to write a templatized quicksort function. The thought in my head was that I would write a quicksort that can operate on any data structure that has a subscript operator and an order relation on the objects contained within it, so I could do things like quicksort<deque<int> >(); quicksort<vector<string> >(); etc. I star...

In Django's template engine, how do I display a datetime object in a meaningful way?

{{ p.date }} is displayed as: Date: 2010-10-29 21:56:39.226000 How do I make changes to how that's displayed? ...

C++ casting of templated class

Hello, I have a question about templates. I would like to have a templated class that contains, say, an array of either float's or double's. I can write a clone() function that duplicates it. No problem. However, I would like to have another function called cast() that does a translation back and forth between double and float. This ha...

When should I use escape and safe in Django's template system?

If I have a box where people put comments, and then I display that comment like this...should I escape? {{ c.title }} ...

How do you find the "main" picture of a website, given the URL?

Let's say you're given http://nytimes.com How would you pull out the "main" image? The reason I'm asking is because Flipboard is able to grab the main image from a website, just using the URL. You could parse out all the image tags. But then what? ...

Odd error message when instantiating a template class

Hi all, I am getting an error I do not understand. There was even a similar question asked on SO that I found, but the fix given is already in my code. I am getting an error in this line: ForestNode<NODETYPE> foo = new ForestNode<NODETYPE> ForestNode(bar); that reads : \project 4\forest.h|85|error: expected ',' or ';' before 'Fores...

Beginner template compile error - Having trouble passing function as arg

Hello everyone, Most of my classes have lists as private data members. As such, most of them also have adder/remover public members. I noticed I was writing basically the same thing for each of the adders, so I thought I'd turn it into a template. Here's what I've got: template <class N, class I> void add(N element, std::list<N> & con...

Nested dictionaries and Django template.

When there is a dictionary: menu = {'title': 'Link1', 'children': {'title': 'Child of Link1', 'children': #etc..} } How would one iterate over it so that the output becomes: <ul> <li>Link1 <ul> <li>Child of Link 1 <ul> <li>Grandchild of Link 1 ...

Custom django template tag issue on AppEngine

So I have beating my head against the wall on this. I feel like I have interpretted the docs and examples I found, but this just won't seem to go away. Here is the tag code: from google.appengine.ext import webapp register = webapp.template.create_template_register() def test_tag(): return "TEST!" register.simple_tag(test_tag...

How declare return type as inner class of template typename?

How declare this: template<typename T> (T::ABC)& get(); it gives error: error: expected constructor, destructor, or type conversion before ‘&’ token ...

C++ template class

#ifndef ECORE_H #include "../database.h" #define ECORE_H Database *base_provider; // ecore.h: error: expected initializer before ‘*’ token template <class S, class T> class ecore { // error: expected class-name before ‘{’ token public: ~ecore(void){delete base_provider;}; ecore(vo...