templates

C++ templates and external function declarations.

I have this: template <typename T> class myList { ... class myIterator { ... T& operator*(); } } ... template<typename T> T& myList<T>::myIterator::operator*() { ... } That is giving me the following error: "expected initializer before '&' token". What exactly am I supposed to do? I already tried ad...

Is there a standard template for AS3 documentation?

I've seen it used a couple places: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/ http://developer.yahoo.com/flash/astra-flash/classreference/ Is this just a coincidence or is it somewhere I can grab? I'd love to use it for a new project I'm working on. Thanks! ...

Template syntax

I was reading a book on templates and found the following piece of code: template <template <class> class CreationPolicy> class WidgetManager : public CreationPolicy<Widget> { ... void DoSomething() { Gadget* pW = CreationPolicy<Gadget>().Create(); ... } }; I didn't get the nested templates specified for the CreationPolicy (which is a...

Extending std::list

I need to use lists for my program and needed to decide if I use std::vector or std::list. The problem with vector is that there is no remove method and with list that there is no operator []. So I decided to write my own class extending std::list and overloading the [] operator. My code looks like this: #include <list> template <clas...

New iPhone App - How to Choose which Xcode Template to Use?

In general I'd like to understand which templates to use when, when I'm making new iPhone apps. Could anyone offer some guidelines, tips, rules-of-thumb? Also, how much should I agonize over this? If I start off with the wrong one, can I add the missing pieces manually, is it hard? For reference here are the choices I'm seeing: Nav...

c++ deduction of "non type pointer to function" class template parameters

Consider a template class like: template<typename ReturnType, ReturnType Fn()> class Proxy { void run() { ReturnType ret = Fn(); // ... do something ... } }; // and a functions int fn1() { return 5; } float fn2() { return 5; } This can be instantiated by using: Proxy<int, &fn1> p1; But explicitly declaring th...

Groovy/Grails SimpleTemplateEngine Freezes

I'm using Grails to send a large number of HTML emails. I use the SimpleTemplateEngine to create my email bodies in this fashion: def ccIdToEmailMap = [:] def emailTemplateFile = Utilities.retrieveFile("email${File.separator}emailTemplate.gtpl") def engine = new SimpleTemplateEngine() def clientContacts = ClientContact.list() for(...

Editor templates for defensive programming

Recently I worked on FindBugs warnings about exposing internal state, i.e. when a reference to an array was returned instead of returning a copy of the array. I created some templates to make converting that code easier. Which one did you create to support defensive programming and want to share with the SO crowd? Templates I've create...

Configure velocity to render an object with something other than toString?

Is there a way to configure Velocity to use something other than toString() to convert an object to a string in a template? For example, suppose I'm using a simple date class with a format() method, and I use the same format every time. If all of my velocity code looks like this: $someDate.format('M-D-yyyy') is there some configuratio...

Can't assign a member which is a pointer to a templatized class

My problem is that in my "Widget" class i've the following declaration: MouseEvent* X; In a member function I initialize the pointer with an address the normal way: X = new MouseEvent; Ok, this last line makes the compiler stop at: error C2166: l-value specifies const object All right, a MouseEvent is declared as a typedef t...

C++ Overloading Operator < with an int parameter (comparing to a type that isn't guaranteed to be an int)

Hi, I want to overload operators < and > to allow the searching of an int value inside a BST (which ain't designed to store ints but rather words). For those who are wondering why is this overload being done on the first place please check http://stackoverflow.com/questions/384587/c-im-stuck-filling-this-bst-with-its-proper-values I n...

Simple web page layout and templating in PHP

In the past I've written sites in ASP.NET just to get nice reusable templating via master pages (layouts) and user controls (partials). I'm talking about sites that have no more complicated code in them than simple variable substitution in templates - I'm just using it to keep my HTML organized. It's great to be able to define the basic ...

Vim indentation for c++ templates?

Does anyone have or know about vim plugin/macro/function that indents nicely c++ templates? When I highlight template definition in vim .hpp/.h file and indent it with '=' I get something like this: > template < > class TFilter, > class TParser, > class TConsumer, > class TDataProce...

Unit-testing C++ templates

I've used function and class templates in implementation of my libraries. So far I've just instantiated a template in the library unit-tests (CppUnit), and then proceeded to test it almost like any other normal class or function. Recently I've been planning to add some templates also to the library APIs. Good interface is of course the ...

Registering derived classes in C++

EDIT: minor fixes (virtual Print; return mpInstance) following remarks in the answers. I am trying to create a system in which I can derive a Child class from any Base class, and its implementation should replace the implementation of the base class. All the objects that create and use the base class objects shouldn't change the way th...

Aligning Member Variables By Template Type

Hello I want to align my member variables based on a class template type but I'm not sure if it is actually possible. The following is a (very) simple example of what I'd like to do template<int Align> class MyClass { private: struct MyStruct { // Some stuff } __declspec(align(Align)); __declspec(align(Align)) int myAlign...

GCC Template issue

Visual Studio compiles this code fine, but gcc only lets it compile without the Template operator. With the Template operator it gives the following errors: Line 29: error: expected `;' before "itrValue" class Test { public: Test& operator<<(const char* s) {return *this;} // not implemented yet Test& operator<<(size_t s) {r...

How do you debug Mako templates?

So far I've found it impossible to produce usable tracebacks when Mako templates aren't coded correctly. Is there any way to debug templates besides iterating for every line of code? Edit: Per the comments, it seems switching to Jinja2 might be the best solution. ...

ERB like library for C#

I am looking to find a librray that emulates part of the capabilities of Ruby's ERB library. ie substitute text for variables between <% and %>. I dont need the code execution part that ERB provides but if you know of something that has this I would be super appreciative. ...

Static member variable in template, with multiple dlls

My code is built to multiple .dll files, and I have a template class that has a static member variable. I want the same instance of this static member variable to be available in all dlls, but it doesn't work: I see different instance (different value) in each of them. When I don't use templates, there is no problem: initialize the sta...