templates

ASP.NET MVC2: Can you get ModelMetadata.ContainerType from within a collection?

I'm trying to call DisplayFor and DisplayForModel to iterate an IEnumerable<> with various element types from within a view. I have Templates defined for each element/Model type. What I would like to do is check the ViewData.ModelMetadata.ContainerType from within the Template so that Template can determine if it was called as part of a...

Issue with class template partial specialization

I've been trying to implement a function that needs partial template specializations and fallen back to the static struct technique, and I'm having a number of problems. template<typename T> struct PushImpl<const T&> { typedef T* result_type; typedef const T& argument_type; tem...

extend base.html problem

I'm getting the following error: Template error In template /home/mo/python/django/templates/yoga/index.html, error at line 1 Caught TemplateDoesNotExist while rendering: base.html 1 {% extends "base.html" %} 2 3 {% block main %} 4 <p>{{ page.title }}</p> 5 <p>{{ page.info}}</p> 6 <a href="method/">Method</a> 7 {% endblock...

Odd C++ template behaviour with static member vars

This piece of code is supposed to calculate an approximation to e (i.e. the mathematical constant ~ 2.71828183) at compile-time, using the following approach; e1 = 2 / 1 e2 = (2 * 2 + 1) / (2 * 1) = 5 / 2 = 2.5 e3 = (3 * 5 + 1) / (3 * 2) = 16 / 6 ~ 2.67 e4 = (4 * 16 + 1) / (4 * 6) = 65 / 24 ~ 2.708 ... e(i) = (e(i-1).numer * i + 1) /...

template static classes across dynamic linked libraries

Hello, I have a templated class with a static value, like this: template <class TYPE> class A{ static TYPE value; }; in the code of a dll I assign the static value: code of DLL_1 A<float>::value = 2.0; I wish the value to be shared by all the dlls I'm using, i.e. I want that: code of DLL_2 printf("value on DLL_2 %f",A<flo...

does sfinae instantiates a function body?

I want to detect existence of a specific member function for a class, using the usual SFINAE trick. template<typename T> struct has_alloc { template<typename U,U x> struct dummy; template<typename U> static char test(dummy<void* (U::*)(std::size_t),&U::allocate>*); template<typename U> static char (&test(...))[...

Why aren't template specializations allowed to be in different namespaces?

Hi, Please, see what I am trying to do: #include <iostream> namespace first { template <class T> class myclass { T t; public: void who_are_you() const { std::cout << "first::myclass"; } }; } namespace second { using first::myclass; template <> class myclass <int> { int i, j; public: void who_are_you() const { std...

Add custom template in custom repeater

Hi, I have a class which extends from repeater class. Basically I need a custom repeater which should have this layout:        <HeaderTemplate>        </HeaderTemplate>        <MyTemplate>         </MyTemplate>        <ItemTemplate>        </ItemTemplate>      <FooterTemplate>    </FooterTemplate> Till now I have written this cod...

How to show current file in templates with Django FileFields

Hi, I am kinda stuck, I've been using Django for a while now, but I cant actually seem to find this thing out. And thats weird because it should be a simple thing. I've been googling around and can't seem to find a solution, it maybe because it is a simple thing. The problem is, I have a ModelForm, and it has a FileField, when I rende...

How to ensure class template argument is derived from particular class Foo?

Possible Duplicate: C++ class template of specific baseclass class Base { ... }; class Derived1 : public Base { ... }; class Derived2 : public Base { ... }; class Unrelated { ... }; I want to have a class template ClassTemplate that accepts as parameter only classes Derived1 and Derived2 but not Unrelated, so I can do: C...

No instance of constructor --- Matches Argument List (Templating issue maybe)

Hey S.O. Guys I am currently trying to write a basic wrapper for the cml (http://www.cmldev.net/) math library for a project i am working on. I have a wrapper for the cml vector class which has one private member #ifndef VECTOR3_H_ #define VECTOR3_H_ #include "cml\cml.h" #include <memory> namespace Math { template<typename T> ...

Placing data within an HTML template using ASP.NET

I have an ASP.NET web app that retrieves a JSON collection and outputs the content of the collection, via LINQ to a StringBuilder that has a lot of table and other tags in HTML, with my data pieces interspersed. This is what I mean: sb.AppendFormat(@" <table cellpadding=""0"" class=""TableStyle"" style=""width: 70%; height: 100%;"" ce...

Any way to determine if class implements operator()

I'm trying to find is there's a way to check if a class is a functional because i want to write a template which uses it? Is there an easy way to do this? Or do I just wrap things in a try/catch? Or perhaps the compiler won't even let me do it? ...

How do I add a file to VS2010 template that is not in the project?

I built a new VS2010 project template (based on MVC2, but it's not important). Most of the files are, of course in the project, but there are a few that are not. For example, T4MVC.setting.t4 and instructions.pdf. Although they are not in the project, I would still want to put them in user directory when new project is created. However,...

Calling a function from a derived template class

My base class: //Element.h class Element { public: Element(); virtual ~Element(){}; // not sure if I need this virtual Element& plus(const Element&); virtual Element& minus(const Element&); }; Derived template class: //Vector.h #include "Element.h" template <class T> class Vector: public Element { T x, y, z; public: //constructors...

Template does not save to markup

If found a solution to a related question here http://stackoverflow.com/questions/3079563/designer-problem-with-compositedataboundcontrol. But I now have the strange behavior that I can edit the template, after setting the datasourcecontrol correctly, and put in label controls and edit the bindings correctly like I would expect. That is ...

Class member calls function template with callback function

I'm having trouble passing a callback function from within a class, when calling a template function. Here's a sample code: sortedlist.h #ifndef _sortedlist_h #define _sortedlist_h #include <vector> template <typename ElemType> class SortedList { public: SortedList(int (*compare)(ElemType a, ElemType b)); ~SortedList(); ...

Android App Templates?

Are there Android app templates, similar to the iPhone SDK templates? ...

Custom iterator: how do I keep track of it?

I have this situation: I have a class which keeps track of an array of pointers. I built a custom iterator which loops through this array. My problem is on how to make it threadsafe, especially while incrementing/decrementing? Here is a draft of the relevant parts of what I have: typedef fruit * iterator; class fruits { private: ...

How can I make a variable of the same type as another using templates?

I'd like to create a variable which matches the type of another variable by way of a template such that if the other variable ever changes type to match, the one derived from it via a template also changes its type. How can I do this with templates in C++? The purpose is to ensure that when I read from disk into a temporary variable th...