templates

is it possible to have templated classes within a template class?

template <class M, class A> class C { std::list<M> m_List; ... } Is the above code possible? I would like to be able to do something similar. Why I ask is that i get the following error: Error 1 error C2079: 'std::_List_nod<_Ty,_Alloc>::_Node::_Myval' uses undefined class 'M' C:\Program Files\Microsoft Visual Studio 9.0\VC\include...

Can I nest Templates in a Web User Control?

I want to do something like this: <MyTemplate> <span><%# Container.Title %></span> <MySubTemplate> <span><%# Container.Username %></span> </MySubTemplate> </MyTemplate> Assuming I have a list of Titles that each have a list of Usernames.. If this is a correct approach how can I do this or what is a better way? ...

Any lightweight templating solutions in Java with support for conditional formatting?

I'm using MessageFormat to format some addresses with a template like this: "{0}\n{1}\n{2}\n{3}, {4} {5}" where 0 = street 1 1 = street 2 2 = street 3 3 = city 4 = state 5 = zip Most of these fields are optional when captured. How do I avoid having an empty line when for instance, there is not street 3? I could use a template lik...

Django - How to do tuple unpacking in a template 'for' loop

In my views.py, I'm building a list of two-tuples, where the second item in the tuple is another list, like this: [ Product_Type_1, [ product_1, product_2 ], Product_Type_2, [ product_3, product_4 ]] In plain old Python, I could iteration the list like this: for product_type, products in list: print product_type for product...

How to precompute array of values?

Is there a way to pre-compute an array of values based on templates? In the following example I would like the 'powers_of_2' array to have 256 values computed at compile-time if that is possible without having to type all of the values. #include <iostream> using namespace std; template <int X, char Y> struct power { enum { value = ...

How to overcome GCC restriction "could not convert template argument '0' to 'Foo*'"?

Suppose I have code like this: template<class T, T initial_t> class Bar { // something } And then try to use it like this: Bar<Foo*, NULL> foo_and_bar_whatever_it_means_; GCC bails out with error (on the above line): could not convert template argument '0' to 'Foo*' I found this thread: http://gcc.gnu.org/ml/gcc-help/2007...

Variadic templates

C++0x will allow template to take an arbitrary number of arguments. What is the best use of this feature other than implementing tuples ? ...

Syntax error whenever I put Python code inside a Django template

I'm trying to do the following in my Django template: {% for embed in embeds %} {% embed2 = embed.replace("&lt;", "<") %} {{embed2}}<br /> {% endfor %} However, I always get an invalid block or some syntax error when I do anything like that (by that I mean {% %} code inside a loop). Python doesn't have {} to si...

How to populate a WPF grid based on a 2-dimensional array

I have a 2-dimensional array of objects and I basically want to databind each one to a cell in a WPF grid. Currently I have this working but I am doing most of it procedurally. I create the correct number of row and column definitions, then I loop through the cells and create the controls and set up the correct bindings for each one. ...

ASP.NET Templating

We're building a text templating engine out of a custom HttpModule that replaces tags in our HTML with whole sections of text from an XML file. Currently the XML file is loaded into memory as a string/string Dictionary so that the lookup/replace done by the HttpModule can be performed very quickly using a regex. We're looking to expand...

Passing Parameter to struts2 component

I am attempting to create a struts2 component using freemarker. I created a ftl file with code like this: <script type="text/javascript" src="${parameters.library?default('')}"></script> Which is expecting a parameter named library to be passed to the component. If the parameter is absent then it defaults to a blank string. On my JSP...

Is there a way to do a C++ style compile-time assertion to determine machine's endianness?

I have some low level serialization code that is templated, and I need to know the system's endianness at compiletime obviously (because the templates specializes based on the system's endianness). Right now I have a header with some platform defines, but I'd rather have someway to make assertions about endianness with some templated ...

Struts - Loading result-templates (like JSP) from JAR-Files

How can I define it in the struts framework, when I would like to load templates (JSP, ZUL etc.) from different JAR-Files? ...

What is wrong with this inheritance?

I just don't get it. Tried on VC++ 2008 and G++ 4.3.2 #include <map> class A : public std::multimap<int, bool> { public: size_type erase(int k, bool v) { return erase(k); // <- this fails; had to change to __super::erase(k) } }; int main() { A a; a.erase(0, false); a.erase(0); // <- fails. can't find base class' function?! ...

Template specialization based on inherit class

I want to make this specialized w/o changing main. Is it possible to specialize something based on its base class? i hope so. -edit- I'll have several classes inheriting SomeTag. I dont want to write the same specialization for each of them. class SomeTag {}; class InheritSomeTag : public SomeTag {}; template <class T, class Tag=T> s...

automatic class templates?

Is there a way to have the compile deduce the template parameter automatically? template<class T> struct TestA { TestA(T v) {} }; template<class T> void TestB(T v) { } int main() { TestB (5); } Test B works fine, however when i change it to TestA it will not compile with the error " use of class template requires template a...

QuickStart basic layout/template for web development?

I'm looking for a quick start or template, or something, to get a web site's basic layout done quickly and looking fairly professional, and then let me do the coding. I don't want a CMS, as this is for a highly customised reporting application, but I need something like frame header and two columns and frame footer. I can design the pr...

How can I profile template performance in Template::Toolkit?

What's the best method for benchmarking the performance of my various templates when using Template::Toolkit? I want something that will break down how much cpu/system time is spent processing each block or template file, exclusive of the time spent processing other templates within. Devel::DProf, for example, is useless for this, sin...

How to overload operator<< that doesn't take or return ostream

Original Question I am writting a logging class where the goal is to be able to do this: // thread one Logger() << "Some string" << std::ios::hex << 45; // thread two Logger() << L"Some wide string" << std::endl; Currently my Logger header looks something like this: #pragma once; #include <ostream> class Logger { public: Log...

Missing "Export Template" option in Visual Studio 2005

Hi, I am trying to learn & create Visual Studio templates and as per this MSDN article, The simplest type of template to create is an item template. To do so, simply open a project that includes the file you want to use as a template and then chooses File | Export Template to run the Export Template Wizard Now, the pr...