templates

What's the use of the derived class as a template parameter?

What's the purpose of this pattern? What is it called? It looked very strange when I saw it the first time, though I have now seen it many times. template<typename Derived> struct Base { //... }; struct Example : Base<Example> { //... }; ...

What are common Java libraries for converting values into human-friendly strings?

I'm looking for a library of utilities for converting "1234" into "1.2KB" or the date Tue 11:24pm into "2 hours ago". In particular, I'm expecting something vaguely similar to Django's notion of "template tags and filters" (see http://docs.djangoproject.com/en/dev/ref/templates/builtins/?from=olddocs). ...

c++ cli inhert from generic(template) interface

hello, I am writing a wrapper for a class written in C++. I must have an template interface class and inherif a wrapper class for a certain type of variable. this is the code template<typename T> public interface class IDataSeriesW { property T default [int] { T get (int Index); void set (int Index ,T val); } }; publi...

Overloading + operator on generic class in C++

Hi all. I'm trying to overload the + operator in a forest class, a forest being a collection of trees, and the + operator is supposed to combine two forests into one. I have the following code as my class definition: template<typename NODETYPE> class Forest { public: friend Forest& operator+<>(Forest&, Forest&); ...

Creating default templates on Repeater that are overridable by users

I have a webforms control, my:Repeater, that is an asp:Repeater. I want to make a default template, like: <my:Repeater> <HeaderTemplate> My Default Header </HeaderTemplate> <ItemTemplate> My data </ItemTemplate> <FooterTemplate> My Default Footer </FooterTemplate> </my:Repeater> I want this template to be in so...

Call methods on class templatized over enum

Given the following code: enum Fruits{ eApple, eBanana }; template<> struct SomeFruit< eApple > { void eatIt() { // eat an apple }; }; template<> struct SomeFruit< eBanana > { void eatIt() { // eat a banana }; }; Is there a way to call the explicitly specialized eatIt(), for each of Fruits, without having to make each call m...

Conditional table with Mako

I was trying to format lists into tables by using Python nested lists. This is my previous question. So far I could not make it work. I was wondering if Mako templates would be better. Can anyone suggest a solution? Thanks. ...

C++ templates to make several version of function with different constant

Hello Can I use template to create several instantiations of some function, different only in some constant parameter? The number of alternatives for this parameter is fixed. E.g. I want not to rewrite (where upper is in 1..32 in powers of two) funct(param, int upper) { some_loops(..) some_heavy_code_fast_for_const_and_slow_f...

how to template for operator<< for ostream

The following won't compile for me. I'm out of ideas... Any help? template<> inline std::ostream& operator<< <const std::map<std::string, std::string> > (std::ostream& stream, const std::map<std::string, std::string>& some_map) { return stream; } g++ gives me the following error: error: expected initializer before '<' token Edit: ...

friend declaration declares a non-template function

I have a base Class akin to the code below. I'm attempting to overload << to use with cout. However, g++ is saying: base.h:24: warning: friend declaration ‘std::ostream& operator<<(std::ostream&, Base<T>*)’ declares a non-template function base.h:24: warning: (if this is not what you intended, make sure the function template has alread...

Some compiler errors concerning an overloaded operator on a template in c++

Hi all, I have some code with a few errorr I do not understand how to fix at all. I have asked my professor and TA, and consulted the internet with no luck, apart from understanding more precisely what the errors mean. From what I can tell, the compiler is either confusing my overloaded operator with built in operators, or it is not re...

A puzzle for template wizards

I'd like to do the following: const int someInt; const std::vector<int> someIntList; const std::vector<std::vector<int>> someNestedIntList; Marshall(someInt); // trivial case Marshall(someIntList); // difficult case Marshall(someNestedIntList); // difficult case I tried the following: template<std::vector<class Element>> void Marsh...

Custom control not applying template in itemscontrol

I have written a fairly simple timeline control which extends control. It has a generic template that displays correctly when the control is used by itself. I have put the control in an ItemsControl and now no templates are being applied to the timeline (OnApplytemplate() isn't firing). I cannot for the life of me figure out what the pr...

Why am I getting zero?

In this code (ready to compile): #include "stdafx.h" #include <iostream> #include <sstream> using std::cout; template<class T, int first, int second> T make() { T result = T(); std::stringstream interpreter; interpreter << first << '.' << secon...

Django: provide month and year number as parameter in a template for use in template tag

Hi, I am a Django Beginner. I found this Django snippet to show a simple calendar on my web page. The function needed 3 parameters that one can provide within the template as follows: {% load calendar_tag %} <div> <div>Calendar: </div> {% get_calendar for 10 2010 as calendar %} <table> <tr> <th>Mon</th> <th>Tue</th>...

C++ - Undefined reference issues when working with classes

Hello, everyone, I am working on a small project where I use multiple classes. One of those classes is Menu, which has a showContainer method. Here's the class declaration: class Menu { //snip Menu(); Menu(std::string, std::string, int, int); virtual ~Menu(); //snip /** * Visualiza e providencia navegacao p...

Good ways to create step by step creation process in google app engine with django forms

I'm using AppEngine and django forms passing template_values and using base.html with {% extends "base.html" %} this works well in a testing environment when I have one big form for adding entities. I'm good in python, good with the datastore, but my html is weak/OLD I want to have a step by step process for creating datastore entities...

Any Smarty Users out there? Here's a domPDF challenge.

I have a working dynamic content query/echo file that I need to convert to template for use with domPDF. Would someone look at my code that's not executing to see where I'm going wrong? (Btw, the sendPDF.tpl file is in path: /Smarty/mg/templates/ -- sendPDF.php is in /Smarty/mg/ and smartyTEST.php is in my root path) thanks much Allen ...

Function template as a parameter to a class template

<> - read this as a template; I can do this: void f() {} //Here I'm declaring a fnc as a <> param template<void (*fnc)()> struct Factor { }; int main() { Factor<f> fac; return 0; } but I cannot do this: #include <sstream> template<class R, class T> R make_(T first, T second) { std::stringstream interpreter; R resul...

Get Magento config information

I'm trying to get the base url and the media directory from the Magento configuration and I'm trying to use them for a template that has images. I've only gotten as far Mage::getConfig(). I'm not sure what to do next... ...