templates

Problems Expanding an Array in C++

I'm writing a simulation for class, and part of it involves the reproduction of organisms. My organisms are kept in an array, and I need to increase the size of the array when they reproduce. Because I have multiple classes for multiple organisms, I used a template: template <class orgType> void expandarray(orgType* oldarray, int& numit...

error: expected constructor, destructor, or type conversion before '(' token

include/TestBullet.h:12: error: expected constructor, destructor, or type conver sion before '(' token I hate C++ error messages... lol ^^ Basically, I'm following what was written in this post to try to create a factory class for bullets so they can be instantiated from a string, which will be parsed from an xml file, because I don't...

Overwriting a range of bits in an integer in a generic way

Given two integers X and Y, I want to overwrite bits at position P to P+N. Example: int x = 0xAAAA; // 0b1010101010101010 int y = 0x0C30; // 0b0000110000110000 int result = 0xAC3A; // 0b1010110000111010 Does this procedure have a name? If I have masks, the operation is easy enough: int mask_x = 0xF00F; // 0b1111000000001...

perl TemplateToolkit - Can't locate object method "new" via package

Hi, I have inherited a web project that is perl based and I'm attempting to set up a local testing server so changes can be made internally to the project. The server architecture Ubuntu 9.10 php 5.2.10 mysql 5.1.37 perl 5.10.0-24ubuntu4 All the dependent modules and packages are installed such as DateTime.pm, TemplateToolkit.pm but r...

creating a design in wpf using stackpanel and reusing it?

I want to create a design using Stackpanel in XAML pad in WPF and then embed images on it using .cx file. But I am getting some error using Styles. <Style x:Key="TopPanelDesign" TargetType="{x:Type StackPanel}"> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type StackPan...

C++ Template Class Constructor with Variable Arguments

Is it possible to create a template function that takes a variable number of arguments, for example, in this Vector< T, C > class constructor: template < typename T, uint C > Vector< T, C >::Vector( T, ... ) { va_list arg_list; va_start( arg_list, C ); for( uint i = 0; i < C; i++ ) { m_data[ i ] = va_arg( arg_list, T...

How to access a named element in a control that inherits from a templated control

Hello this is similar to http://stackoverflow.com/questions/2620165/how-to-access-a-named-element-of-a-derived-user-control-in-silverlight with the difference is inheriting from a templated control, not a user control. I have a templated control called MyBaseControl Xaml:- <Style TargetType="Problemo:MyBaseControl"> <Setter Pr...

any template engine similar to freetemplate for c#

what im looking its a template engine like freemarker (with select case directive) for writing a generator in c#. ...

C++ Templates: implicit conversion, no matching function for call to ctor

template<class T> class test { public: test() { } test(T& e) { } }; int main() { test<double> d(4.3); return 0; } Compiled using g++ 4.4.1 with the following errors: g++ test.cpp -Wall -o test.exe test.cpp: In function 'int main()': test.cpp:18: error: no matching functi...

C++: get const or non-const reference type from trait

I am writing a functor F which takes function of type void (*func)(T) and func's argument arg. template<typename T> void F(void (*func)(T), WhatTypeHere? arg) { func(arg); } Then functor F calls func with arg. I would like F not to copy arg, just to pass it as reference. But then I cannot simply write "void F(void (*func)(T), T&)"...

Xcode custom project template creates only references to files

Hi, I tried to create a custom project template for setting up unit testing. The problem is that when i create a new project based on this template it creates references to the template files : When i edit a file, it changes my template files instead of my actual project files ! When i delete my template, files from my actual project ...

C++ template and pointers

I have a problem with a template and pointers ( I think ). Below is the part of my code: /* ItemCollection.h */ #ifndef ITEMCOLLECTION_H #define ITEMCOLLECTION_H #include <cstddef> using namespace std; template <class T> class ItemCollection { public: // constructor //destructor void insertItem( const ...

ASP.NET MVC 2 : How to call DisplayFor for each item in a collection ?

I have property in my model which is a collection type (List). I'd like to call for each item in this collection Html.DisplayFor or Html.EditorFor. How can I do this ? EDIT It's not a strong-typed view. It's a templated view. There is only ViewData.ModelMetadata. ...

C++: How to require that one template type is derived from the other

In a comparison operator: template<class R1, class R2> bool operator==(Manager<R1> m1, Manager<R2> m2) { return m1.internal_field == m2.internal_field; } Is there any way I could enforce that R1 and R2 must have a supertype or subtype relation? That is, I'd like to allow either R1 to be derived from R2, or R2 to be derived from R...

m.find(...) == m.end() - which is used, iterator or const_iterator

std::map find/end both provides const_iterator and iterator, e.g. iterator end (); const_iterator end () const Out of curiosity,if I have a std::map , which will be called/compared here, an iterator or a const_iterator ? : if(m.find(key) != m.end()) { ... } And should I care ? ...

Templates --> How to decipher, decide if necessary and create?

Hi All, I have a few classes in a project that I inherited that are really old, last I knew they compiled with CodeWarrior 8. I am now in XCode 3.2 Here is an example of what I struggle with: template <class registeredObject> typename std::vector<registeredObject>::iterator FxRegistry<registeredObject>::begin(void) { return mRegi...

Compile time type determination in C++

A coworker recently showed me some code that he found online. It appears to allow compile time determination of whether a type has an "is a" relationship with another type. I think this is totally awesome, but I have to admit that I'm clueless as to how this actually works. Can anyone explain this to me? template<typename BaseT, typenam...

Just introducing myself to TMPing, and came across a quirk

I was just trying to learn the syntax of the beginner things, and how it worked when I was making this short bit of code in VS2008. The code below works in adding numbers 1 to 499, but if I add 1 to 500, the compiler bugs out giving me: fatal error C1001: An internal error has occurred in the compiler. And I was just wondering why that...

How do you compare two unknown numbers to see if they're equal in a special case template?

Here, is my code. Just trying to wrap my head around some of the basic things you can do with TMP. I'm trying to supply two numbers with which the compiler will add up that range of numbers. I'm just not sure how to write the syntax for the "constraint" template. template < int b, int e > struct add { enum { sum = add< b + 1, e >::s...

CodeIgniter - the right way to create "block" elements on web page

Hello. I've been searching for a solutions for this problem a while but haven't seen any "valid mvc" solution for this. I hope I can explain my problem clearly enough for you guys. I need to create a dynamic block of HTML on my website. (eg. a block containing user's latest blog comments). I have a template view file (a file containing...