templates

Template Specialization of Function inside of a Templated Class

I have a templated class and inside I have a templated function( different template parameters ) and I having issues getting the compiler to call the correct one. Example: template< class Parm1, class Parm2, class Parm3 > class Class { public: void Func( Parm1 arg1, Parm2 arg2 ) { Call<Parm3>( arg1, arg2 ); } protected:...

Does C++ support individual generic methods rather than generic classes?

Important: This question is getting quite long, if this is the first time you're reading this I suggest you start near the bottom as the solution is there in a round about way, but the code is a bit smelly. After reading a tutorial on templates, I was able to change my existing class to support generic types. However, many objects a...

Why does GCC not find my non-template function? ("no matching function for call to...")

In MSVC 2008, I have the following code: class Foo { // Be a little smarter about deriving the vertex type, to save the user some typing. template<typename Vertex> inline void drawVertices( Elements vCount, RenPrim primitiveType, PixMaterial *mtl, Vertex const *vertices) { this->drawVertices(vCount, primitiveType, mtl, ve...

C# generics vs C++ templates - need a clarification about constraints

Duplicate What are the differences between Generics in C# and Java… and Templates in C++? Hi all, I am experienced C++ programmer but quite new to C#. Whats up with those constraints and generics? Why doesn't it work the same as in C++ where constraints are implicit and derived from the instantiations you do to the template cla...

Help storing an intrusive_ptr of a template class in a std::map

I have a small template class of type Locker contained within a boost::intrusive_ptr that I want to store inside a std::map: template <typename T> bool LockerManager<T>:: AddData(const std::string& id, T* pData) { boost::intrusive_ptr<Locker<T> > lPtr(Locker<T>(pData)); // Line 359 - compiles mMap.insert(make_pair(id, lPtr)); /...

Using types defined in template arguments

When using a container class like vector, list, etc., I can use the type of the elements by writing vector<type>::value_type. However, the following code template<class container> void foo(container elementtype b; } fails with the error "expected initializer before ‘elementtype’". Is it possible to infer the element type when th...

C memset seems to not write to every member

I wrote a small coordinate class to handle both int and float coordinates. template <class T> class vector2 { public: vector2() { memset(this, 0, sizeof(this)); } T x; T y; }; Then in main() I do: vector2<int> v; But according to my MSVC debugger, only the x value is set to 0, the y value is untouched. Ive never used si...

Does a Perl module know where it is installed?

Hi Perl programmers, I have started creating a Perl package that contains a default email template. The MANIFEST looks something like: SendMyEmail.pm SendMyEmail/defualt_email.tt Currently I know where the module (and the template) are - but does the module itself know where on disk it is? So could the module find the default temp...

Google App Engine--Dynamically created templates

Hi. I'm trying to build an a simple CRUD admin section of my application. Basically, for a given Model, I want to have a template loop through the model's attributes into a simple table (once I do this, I can actually implement the CRUD part). A possible way to accomplish this is to dynamically generate a template with all the necessary ...

Deriving from a class with operator overloading

I want to create a collection of classes that behave like math vectors, so that multiplying an object by a scalar multiplies each field by that ammount, etc. The thing is that I want the fields to have actual names, instead of being treated as an index. My original idea to implement this was creating a base class Rn with the overloads ...

Accessing a WPF GroupItem text for conversion in a template

I'm customising the appearance of grouping in a ListBox. In ListBox.Resources, I have declared something like (formatting removed): <Style TargetType="{x:Type GroupItem}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type GroupItem}"> <StackPanel Orientation="Vertical"> <!-- ...

Visual Studio - Intercept and change path on creation for solutions and projects

I'm working on an automated process to build a base application to include common libraries and projects, check everything into source control and setup the base build for the solution. Most of the issues I've solved except one. Is it possible to intercept the user given path for the solution and projects and alter that path? In other...

Visual Studio 2008: How to install an item template

I have created an Item Template using the "Export Template" wizard. I opened up the XML file and made a couple of minor changes, then rezipped the package. Then I checked the item template into source control so that everyone on the team can access it if they want. But for the life of me I can't get the template to show up under My Temp...

How do you pass a reference when using a typename as a function argument in C++?

Hi, I have some weird problem with templates. When trying to pass a parameterised iterator it complains that no function can be found. The code snippet is here, forget about the functionality, it's using the reference to the templatized iterator what interests me #include <list> #include <iostream> template<typename T> void print_list...

WPF/Silverlight XAML template for a glass button

It seems like a simple thing - but... I want to create a WPF/Silverlight XAML template for a glass button that contains an image and a label - both the image and the label use template binding so that different images and labels can be specified for each button instance. Any help would be appreciated. David Roh ...

Templated namespaces and typedefs are illeagal -- workarounds?

I have a templated function fct that uses some complex data structure based on the template parameter. It also calls some helper functions (templated on the same type) that are in a separate helpers namespace and use the same complex data structure. Now it gets really ugly because we cannot make one typedef for the complex type that all ...

C++ Multiply defined symbols using a header defined template class.

I'm working on a project with a DLL and an EXE in visual studio 2005. Amongst the code for the DLL is a template for a growable array class: template <class Type> class GArray { Type *p; uint32 len; uint32 alloc; protected: bool fixed; public: /// Constructor GArray(int PreAlloc = 0) { p = 0; len = 0; fixed = false; al...

Is making a function template specialization virtual legal?

In C++, a function template specialization is supposed to act exactly like a normal function. Does that mean that I can make one virtual? For example: struct A { template <class T> void f(); template <> virtual void f<int>() {} }; struct B : A { template <class T> void f(); template <> virtual void f<int>() {} }; int m...

template specialization for static member functions; howto?

I am trying to implement a template function with handles void differently using template specialization. The following code gives me an "Explicit specialization in non-namespace scope" in gcc: template <typename T> static T safeGuiCall(boost::function<T ()> _f) { if (_f.empty()) throw GuiException("Function pointer empty"); { Th...

IE won't display flash-content in a smarty-template (FF works fine)

Hello, since a few days I'm trying to figure out if we can use sIFR (2.0.7) for our shop. After the first testpages were running fine, I tried to implement it to our menu-template-file of the xcart-shop-system. I've written the needed blocks in {literal} parts for smarty and the new menu is looking fine in FireFox 3. Unfortunately our t...