templates

Help with my PHP template class

I want to separate the output of HTML from my program code in my projects, so I wrote a very simple database class. <?php class Template { private $template; function load($filePath) { if(!$this->template = file_get_contents($filePath)) $this->error('Error: Failed to open <strong>' . $filePath . '</stron...

C++ Pointer to a function which takes an instance of a templated class as argument

I have trouble compiling a class, which has function pointers as member variables. The pointers are to functions which take an instance of a class as argument. Like template<class T, int N> double (*f)(Vector<T,N> v); I get "error: data member 'f' cannot be a member template" Compiler is gcc 4.2. Edit Before using templates I just ...

Best way to manage a header navigation menu from within a template?

I'm looking to put navigation in my GSP template, and I would like to set the active class on the navigation elements for each respective page. What's the best way to do this? I have several .gsp views merging with a single template that looks like this: <div id="bd" role="main"> <div role="navigation" class="yui-g"> <ul id=...

dedicated template for a Drupal module

I have a Drupal module, that I want to present in a clean page - with no headers, menus, footer ect. I think all I need is a version of page.tpl.php that contains HTML page headers and <?php print $content ?> How can I point my module to such a page? ...

What is the proper way to declare a specialization of a template for another template type?

The usual definition for a specialization of a template function is something like this: class Foo { [...] }; namespace std { template<> void swap(Foo& left, Foo& right) { [...] } } // namespace std But how do you properly define the specialization when the type it's specialized on is itself a template? Here's...

C++ "delayed" template argument

hello. Is there direct way to do the following: template < class > struct f {}; template < class F > void function() { F<int>(); //for example // ? F template <int>(); } function < f >(); I have workaround by using extra class around template struct. I am wondering if it's possible to do so directly. Thanks ...

Button template with image and text in wpf

Hello, I want to create buttons with images and text inside. For example, i would use different images and text for buttons like 'Browse folders' and 'Import'. One of the options would be to use a template. I had a look at simliar question http://stackoverflow.com/questions/1933127/creating-an-imagetext-button-with-a-control-template ...

what is the difference between Template Explicit Specialization and ordinary function?

template <class T> void max (T &a ,T &b) {}//generic template #1 template<> void max(char &c, char &d) {} //template specializtion #2 void max (char &c, char &d) {}//ordinary function #3 what is difference between 1 ,2, and 3? ...

templated method on T inside a templated class on TT : Is that possible/correct.

I have a class MyClass which is templated on typename T. But inside, I want a method which is templated on another type TT (which is unrelated to T). After reading/tinkering, I found the following notation: template <typename T> class MyClass { public : template<typename TT> void MyMethod(const TT & param) ; } ; For st...

Client side templating with unknown variables

Our company has an intranet consisting of several e-mail templates filled with variables (like [[NAME]], [[PROJECT]] and so on). I was thinking of implementing some sort of client side templating to make it easier to replace these variables with actual values. The problem is that among all the client side template solutions I've located...

Type to use as template parameter to compare double values

I got this n-dimensional point object: template <class T, unsigned int dimension> class Obj { protected: T coords[dimension]; static const unsigned int size = dimension; public: Obj() { }; Obj(T def) { for (unsigned int i = 0; i < size; ++i) coords[i]=def; }; Obj(const Obj& o) { for (unsigned int i = 0; i < size; ++i...

What are the disadvantages of using templates?

Some of the disadvantages would be its syntax is complex compiler generates extra code ...

Templates, Function Pointers and C++0x

One of my personal experiments to understand some of the C++0x features: I'm trying to pass a function pointer to a template function to execute. Eventually the execution is supposed to happen in a different thread. But with all the different types of functions, I can't get the templates to work. #include <functional> int foo(void) {re...

How do explicit template instantiations affect what the linker can find?

See the following code and please clear my doubts. As ABC is a template, why does it not show an error when we put the definition of the ABC class member function in test.cpp? If I put test.cpp code in test.h and remve 2, then it works fine. Why? . // test.h template <typename T> class ABC { public: void foo( T& ); void b...

Extending class template

How would I do to extend a template class, for example vector? The below code does not work. The compiler whines about 'Vector' not being a template. template <typename T> class Vector<T> : public std::vector<T> { public: void DoSomething() { // ... } }; ...

Run Custom Error using SubSonic

When I run the custom tool to create the cs files for SubSonic all the templates now inject a letter g to the top of the cs files. To get this to compile I need to remove the g from the ActiveRecord.cs, Struts.cs, Context.cs and StoredProcedures.cs. Anyone else run into this? I am using MySQL. Thanks! ...

gcc problem with explicit template instantiation?

It is my understanding that either a declaration or typedef of a specialization ought to cause a template class to be instantiated, but this does not appear to be happening with gcc. E.g. I have a template class, template class Foo {}; I write class Foo<double>; or typedef Foo<double> DoubleFoo; but after compilation th...

Using member variables inherited from a templated base class (C++)

I'm trying to use member variables of a templated base class in a derived class, as in this example: template <class dtype> struct A { int x; }; template <class dtype> struct B : public A<dtype> { void test() { int id1 = this->x; // always works int id2 = A<dtype>::x; // always works int id3 = B::...

Better way to write an object generator for an RAII template class?

I would like to write an object generator for a templated RAII class -- basically a function template to construct an object using type deduction of parameters so the types don't have to be specified explicitly. The problem I foresee is that the helper function that takes care of type deduction for me is going to return the object by ...

MVC2 EditorTemplate for DropDownList

I've spent the majority of the past week knee deep in the new templating functionality baked into MVC2. I had a hard time trying to get a DropDownList template working. The biggest problem I've been working to solve is how to get the source data for the drop down list to the template. I saw a lot of examples where you can put the sour...