templates

Template specialization with a templatized type

I want to specialize a class template with the following function: template <typename T> class Foo { public: static int bar(); }; The function has no arguments and shall return a result based on the type of Foo. (In this toy example, we return the number of bytes of the type, but in the actual application we want to return some me...

Function template in non-template class

Hi, I'm sure that it is possible but I just can't do it, which is: How can I define function template inside non-template class? I tryied something like this: class Stack_T { private: void* _my_area; static const int _num_of_objects = 10; public: /* Allocates space for objects added to stack */ explicit Stack_T(size_t); /* Puts object o...

Creating html templates using PHP

Im learning a lot about how MVC frameworks work by looking around and studying existing ones. It seems that every framework I see has a layout where each method in each controller has its own template file. So there will be a login template, a logout template, register, so on and so on. My question is, how and why would you create a tem...

Elegantly override style of ComboBox's ToggleButton in WPF

I have a question regarding how to elegantly override an arbitrary element deep inside a control's visual tree. I also have attempted to resolve it in a few different ways, but I've run into several problems with each. Usually when I try three different paths and fail at each one I go downstairs, have a coffee, and ask someone smarter ...

I can not get access to pointer to member. Why?

Consider the following code: template<class T, class F> struct X {}; template<class T, class F, T F::* m> struct Y {}; struct Foo { int member; typedef X<int, Foo> x_type; // works well typedef Y<int, Foo, &Foo::member> y_type; // ERROR }; typedef Y<int, Foo, &Foo::member> y_type2; // OK Why does ...

Passing a managed reference to a method taking unmanaged pointer

Is it possible to make this work? template<class T> fun(T * t) { t->someMemberFunc(); } ... somewhere in the code: ManagedType ^ managedP = gcnew ManagedType(); UnmanagedType * unmanagedP = new UnmanagedType(); fun(managedP); ...

How can I get an iterator on a vector of templated objects ?

Hi, I have a very silly problem with the code shown below. The goal is to increment multiple counters at once, and have their value printed after being processed by a provided functor. However g++ complains : test.hpp:32: error: expected `;' before 'it' " I tried to add some typedef, but the error message remains. Here is the code (...

Rails and I18n: localized templates vs localized string

As you probably know, starting from Rails 2.2, Rails is shipped with a simple localization and internationalization backend. By default, you can store the strings you need to translate in the localization files within the config folder. config/locales/en.yml config/locales/it.yml But Rails provides the ability to localize templates a...

Magento - locate specific core files

Hiya, I am familiar with theming and using template hints in the Magento back office to locate .phtml files. What I am not really familiar with are the core files such as app/code/core/Mage/Catalog/Model What I need to do is override a core file like I would a core phtml file by copying it to 'my theme'. I basically want to amend som...

Zen Code + jQuery

Hi, I just read this article at Smashing Magazine (http://www.smashingmagazine.com/2009/11/21/zen-coding-a-new-way-to-write-html-code/) about Zen Code. Maybe there is any jQuery plugin for this? Might be good for json data inserting/templating. ...

Is this code legal in C++

I just found that when it comes to templates this code compiles in g++ 3.4.2 and works unless m() is not called: template <typename T> class C { T e; public: C(): e(0) {}; void m() { e = 0; }; }; Now one may create and use instance C<const int> c; Until c.m() is not called there are no compile errors b...

Is there equivalent of <? extends T> <? super T> in c++?

Is there equivalent of <? extends T> <? super T> in c++? Also, does <? extends T> <? super T> work even if T is an interface in Java? ...

Get session variable value

After I set a session object, how can I access the value of the given object in my templates? ...

Conditionally instantiate a template at run-time.

I have a template class template <class T> class myClass { public: /* functions */ private: typename T::Indices myIndices; }; Now in my main code I want to instantiate the template class depending on a condition. Like : myFunc( int operation) { switch (operation) { case 0: // Ins...

How to use std::transform with templates

I am struggling to find out why I can't get transform to work with a template class. Here's a simplified version of the template class : template<typename T> class base { public : base() : all_() {} ~base() {} public: bool add(T t) { typename vector<T>::iterator itr = lower_bound(all_.begin(), all_.end(), t); i...

c++ templated friend class

Hello all, I'm trying to write an implementation of a 2-3-4 tree in c++. I'm it's been a while since I've used templates, and I'm getting some errors. Here's my extremely basic code framework: node.h: #ifndef TTFNODE_H #define TTFNODE_H template <class T> class TreeNode { private: Tre...

C++ returning nested class with template on base class problem

I am trying to create a list object, with the iterator class nested inside to understand how it works. In some method, I am trying to return an iterator object but it doesn't work. I created an example to show the problem : // CLASS A template <class T> class A { public: class B; A(){} }; // CLASS B template <class T> cla...

Overloading operator<< for a templated class

Hello! I'm trying to implement a method for a binary tree which returns a stream. I want to use the stream returned in a method to show the tree in the screen or to save the tree in a file: These two methods are in the class of the binary tree: Declarations: void streamIND(ostream&,const BinaryTree<T>*); friend ostream& operator<<(ost...

Super basic declaring new templated class objects question

Hello all. I know this is probably a first year question, but I'm having some problems with templates and I haven't found a suitable answer yet. I'm trying to instantiate a new templated class like so: TreeNode <T>newLeft = new TreeNode(root->data[0]); Which is refering to a constructor which looks like: template <class T> //paramert...

Display thumbnails in an object list using Django and django-imagekit

How do I display thumbnails for my item list....also is it possible to display just a specific thumbnail or a random thumbnail? So far I have this in my template: {% for p in item.images.all %} {{ p.get_thumbnail.url }} {% endfor %} ...