templates

Difference between member functions for a template class defined inside and outside of the class

Is there a difference between defining member functions for a template class inside the class declaration versus outside? Defined inside: template <typename T> class A { public: void method() { //... } }; Defined outside: template <typename T> class B { public: void method(); }; template <typename T> void B<...

In Jinja2, how can I use macros in combination with block tags?

I'm a front end developer, and I've been trying to get a hang on using Jinja2 effectively. I want to tweak a current site so it has multiple base templates using inheritance, it fully uses block tags to substitute content and override it, and uses macros to support passing of arguments. My base template contains this code (edited for si...

Why isn't $vars['node'] available in preprocess_page for some content types?

I am currently using drupal 6 for a site I'm working on. I have a MYTHEME_preprocess_page() function that adds a few variables to the page.tpl.php template from the taxonomy and from a cck field. It was working correctly for a bit, and then the $vars['node'] is empty, but only for 2 content types. The 'node' variable is available to the ...

How to fix 'expected primary-expression before' error in C++ template code?

Here's yet another VC9 vs. GCC 4.2 compile error problem. The following code compiles fine with VC9 (Microsoft Visual C++ 2008 SP1) but not with GCC 4.2 on Mac: struct C { template< typename T > static bool big() { return sizeof( T ) > 8; } }; template< typename X > struct UseBig { static bool test() { return X...

Favorite C++ template hack

Templates are both the blessing and curse of C++. Someone hates them, someone loves them. For those of you are in the latter group, whats your favorite template "hack", and what does it do? I'll start with my personal favorite, the "friender". This template allowes access to protected members - which I very frequently use for unittestin...

Detecting unset variables in Django templates

As a long time PHP developer, I'm used to the idea of setting the error level for my application to warn me when I am using an uninitialized variable. I was wondering if a similar feature exists in Django, where I can detect at run-time that I am using a variable in my template that was not explicitly passed to the template via the view...

Is the following C++ code equiv? (in a smart pointer implementation)

Code 1: template<class T> const PtrInterface<T>* PtrInterface<T>::newRef() const { PtrInterface<T>* me = (PtrInterface<T>*) this; ++me->references_; //++this->references_; return this; } Code 2: template<class T> const PtrInterface<T>* PtrInterface<T>::newRef() const { //PtrInterface<T>* me = (PtrInterface<T>*) this; //+...

Disable the Row according the Checkbox in Gridview.

I have gridview with a checkbocx templatefiled as first column. I want to disables the current row if user unchecks the checkbox. How to do this? ...

Default parameters of struct templates

I have a template struct tree_parse_info declared as follows: template < typename IteratorT, typename NodeFactoryT, typename T > struct tree_parse_info { // ... }; The compiler allows the follows code: tree_parse_info<> m_info; Why does this code compile even though we do not have default template parameters for the ...

Ambiguous overload accessing argument-less template functions with variadic parameters

Yeah, the title can scare babies, but it's actually quite straightforward. I am trying to store a function pointer to a specialized template function, namely boost::make_shared (boost 1.41), as illustrated: boost::shared_ptr<int> (*pt2Function)() = boost::make_shared<int>; However, it won't compile (GCC 4.4.1) due to the fact that bo...

Eclipse: Java class templates

In Eclipse 3.5, under Windows -> Preferences -> Java > Editor -> Templates, I can add code templates. However, these templates can only contain snippets which I can insert into an existing Java class. Is it possible to create templates for whole Java classes, which I can add for example using File -> New -> My-Java-Class? ...

Using Templated Classes and Functions in a Shared Object/DLL

I am working on a fairly significantly-sized project which spans many shared libraries. We also have significant reliance on the STL, Boost and our own template classes and functions. Many exported classes contain template members and exported functions contain template parameters. Here is a stripped-down example of how I do library e...

URL to date-based generic view in django template?

Is there an easy way to get the URL to a Django date-based generic view (specifically object_detail) from a template? Given a URL conf like this url(r'^posts/(?P<year>\d\d\d\d)/(?P<month>\d\d)/(?P<day>\d\d)/(?P<slug>[\w-]+)$', 'date_based.object_detail', detail_info, name='blog-post-detail') My understanding is that I would need to d...

boost::intrusive_ptr constructor ambiguity using a class' 'this' pointer

The offending code: template<typename T> class SharedObject { public: typedef boost::intrusive_ptr<T> Pointer; typedef boost::intrusive_ptr<T const> ConstPointer; inline Pointer GetPointer() { return Pointer(this); //Ambiguous call here } inline ConstPointer GetPointer() const { return ConstPointer(this); } ... ...

Creating a library of template functions

I've been developing a library of mostly template functions and managed to keep things organized (to some extent) in the following manner: // MyLib.h class MyLib { template<class T> static void Func1() { } template<class T> static void Func2() { } }; And obviously calls would be made like this: MyLib::Func1(); As y...

Filtering Search Results with Wordpress

Hi, I'm trying to setup a Search Results page with two columns. First column will present results from all categories except one (Galleries), and the Second column will present only the Galleries category. query_posts() simply resets my results. This is what I got so far. Broken: <?php $s = get_query_var('s'); ...

Check if C++0x parameter pack contains a type

I was wondering if C++0x provides any built-in capabilities to check if a parameter pack of a variadic template contains a specific type. Today, boost:::mpl::contains can be used to accomplish this if you are using boost::mpl::vector as a substitute for variadic templates proper. However, it has serious compilation-time overhead. I suppo...

Selecting an explicit specialization of a class based on a derived type

Hi I'm having problems selecting the correct version of a templated class which has an explicit specialization. I'm wanting to select a specialization using a derived class of the class used to specialize. The scenario is: #include <stdio.h> class A {}; class B: public A {}; template<typename T> class Foo { public: int FooBar(vo...

Using Function Templates

I have created a structure of different data types and i want to return each type of data. does this can be done using a function template which takes a different data argument not included in structure or no arguments? I have something like this, struct mystruct{ int _int; char _c; string _str }; In function template(int i) { my...

Any RAII template in boost or C++0x

Is there any template available in boost for RAII. There are classes like scoped_ptr, shared_ptr which basically work on pointer. Can those classes be used for any other resources other than pointers. Is there any template which works with a general resources. Take for example some resource which is acquired in the beginning of a scope ...