templates

silverlight - reusing components

I am trying to create some reusable components in Silverlight2. The difficulty comes when my components are using templates/styles that are shared with other components. From what I know, in silverlight you can add the style/template in the component itself (not good enough due to duplicate styles) or in the main app file (this does n...

Function template declaration order affects visibility (sometimes).

I'm trying to create a function: template <typename T> void doIt( T*& p ) { if ( !p ) { return; } T& ref = *p; getClassName( ref ); } where the behavior varies according to the type of p passed in. In particular, the version of getClassName called should depend upon the type of p. In the following example, I can successfully ...

DRY Rails Master Templates?

Is there a simple way to define a master template for my whole rails application? If not, what's the best way to reuse my templates so that I'm not copy and pasting the same template into a bunch of layout files? ...

how to avoid hard-coding urls in webapp templates

I'm developing software on google app engine. I'm using the webapp framework. is there any way to avoid hard-coding urls in the html templates? django provides a solution, but I couldn't find one for webapp. thanks in advance.. ...

Sphinx automated image numbering/captions?

Is there a way to automatically generate an image/figure caption using sphinx? I currently have rest-sphinx files I'm converting to html and (latex)pdf using sphinx. I'd like an easy way for users to reference a specific image in the resulting html/pdf files. For example, if a user is refering to the documentation in an email, "In 'Ima...

What is a good tutorial for C++ policy-based class design?

I have just started reading Modern C++ Design Generic programming and Design Patterns Applied and I am wondering if I need to go through some very basic tutorial on policy-based class design before I dive in. Will chapter 1 provide all I need to follow it? I am already experienced with template usage (STL/boost/Poco) and writing templat...

member template specialization and its scope

It appears to me that C++ does not allow member template specialization in any scope other than namespace and global scope (MS VSC++ Error C3412). But to me it makes sense to specialize a base class's primary member template in the derived class because that is what derived classes do - specialize things in the base class. For instance, ...

What is the best way to implement templates in a programming language?

I'm designing a high level, object oriented, garbage collected programming language, and I'm having a problem with how to do templates. I plan on creating a VM-type system, similar to .NET or JVM (but it will use LLVM under the hood). The problem is that I want to have powerful, C++-like templates, but with dynamic linking (so I could re...

isAbstract template and visual studio

The following template will decide if T is abstract with g++. /** isAbstract<T>::result is 1 if T is abstract, 0 if otherwise. */ template<typename T> class isAbstract { class No { }; class Yes { No no[3]; }; template<class U> static No test( U (*)[1] ); // not defined template<class U> static Yes test( ... ); // not d...

How to build a CSS template from scratch

I want to build a CSS template of my imagination: this means from SCRATCH. I want to do it like if I'm doing it with a pen, but just with the mouse. I have no idea about this field (css),that's why I'm asking. Many developers had made fantastic templates that rocks. I want to know how do you create your CSS templates? (if you did) Do y...

how to create complex container in php

I'm creating a container type which has a lot of possible variations on what can be included: title bar search bar form bar tab bar custom bar info bar action/status bar content area Of these, only the content area is required. There are sub-types that would share common sets of bars, but they can also be mixed and matched in arbitra...

What HTML templating options are there in Java as an alternative to doing HTML output from your servlet code?

Given the following Hello World servlet, how could you transfer the Hello World output out of the servlet code and put it in some kind of HTML templating format? I would like to simply call the template from the servlet and have it render the Java variables I refer to in the template - perhaps by referring to the "Hello World" string as ...

how to get the url of the current page in a GAE template

In Google App Engine, is there a tag or other mechanism to get the URL of the current page in a template or is it necessary to pass the url as a variable to the template from the python code? ...

SFINAE with invalid function-type or array-type parameters?

Please consider this code: template<typename T> char (&f(T[1]))[1]; template<typename T> char (&f(...))[2]; int main() { char c[sizeof(f<void()>(0)) == 2]; } I expected it doing SFINAE and chosing the second overload, since substitution of T into T[1] yields void [1]() Which is an invalid type, of course. Adjustment of parameter...

g++ rejects my simple functor with "expected a type, got 'xyz'"

I've been playing about with functors in C++. In particular, I've got a vector of pairs I'd like to sort by the first element of the pair. I started off writing a completely specialised functor (i.e. something like "bool MyLessThan(MyPair &lhs, MyPair &rhs)"). Then, just because this sort of stuff is interesting, I wanted to try writing ...

Derived Functor with any return type and any parameters

I have a class that uses functors as units of work. It accepts a reference to a functor in its Run() method. To allow this class to operate on any functor, all these functors must derive from my base functor class which looks like this: class baseFunctor{ public: virtual void operator()()=0; virtual baseFunctor Clone()=0; }; ...

How does one customize VS 2008 Database Item Templates?

Whereas there is a set of richly informative pages describing Visual Studio templates for code projects (projects and items) in MSDN, there doesn't seem to be a thing for database projects. If I am wrong, please steer me in the right direction. I have VS2008 Professional. Anyway, my question has to do with the new database items. Pre...

Pattern to specialize templates based on inheritance possible?

So, one problem pattern that I keep coming across and don't have a good solution for is how to provide template specializations that are based in what type a template parameter is derived from. For example, suppose I have: template<typename T> struct implementPersist; template<typename T> void persist( T& object ) { implementPersist...

Is there a way to compile-time assert if a variable is a class, struct or a basic type in c++?

I am trying to implement a template class that would be able to tell me if a variable is a class,structure or a basic type. So far I've come with this: template< typename T > class is_class { private: template< typename X > static char ( &i_class( void(X::*)() ) )[1]; // template< typename X > static char ( &i_class...

Is it possible to narrow the friend relationship between classes and functions when multiple template types are involved?

Suppose I represent an image class as: template <typename Pixel> class Image { ... }; I would need my own swap function to prevent extra copying of images, so I would need to make it a friend of Image. If inside Image I write: template <typename T> friend void swap(Image<T>&, Image<T>&); I get what I want, but it makes all swap fu...