templates

c++ pair template struct declaration ambiguity!

In definition of pair class in c++ there are two typedefs. what are they for? there are no use of them in the code! template <class T1, class T2> struct pair { typedef T1 first_type; typedef T2 second_type; T1 first; T2 second; pair() : first(T1()), second(T2()) {} pair(const T1& x, const T2& y) : first(x), second(y) {} t...

Templates, Circular Dependencies, Methods, oh my!

Background: I am working on a framework that generates C++ code based on an existing Java class model. For this reason I cannot change the circular dependency mentioned below. Given: A Parent-Child class relationship Parent contains a list of Children Users must be able to look up the list element type at run-time I've modeled this ...

how to implement is_pointer ?

Hi all. I want to implement is_pointer. I want something like this: template <typename T > bool is_pointer( T t ) { // implementation } // return true or false int a; char *c; SomeClass sc; someAnotherClass *sac; is_pointer( a ); // return false is_pointer( c ); // return true is_pointer( sc ); // return false is_pointer( sac );...

What's the cleanest implementation of this container of typed containers?

I have different types, say A, B, C, that all inherit from some base class Base: class Base { ... }; class A : public Base { ... }; class B : public Base { ... }; class C : public Base { ... }; I need a container, let's call it Master, that holds pointers to objects of types A, B and C. I want the Master container to provide an iterat...

WPF : Conditional templating of textblock

I have a bunch of textblocks in an itemscontrol... I need to know how can I underline the text in the textblock based on whether the text is available in a list in the data model.. Sounds very simple to me...but I have been googling since the past 8 hrs... Can I use datatriggers and valueconverters for this purpose? If yes, then how ca...

When do I have to declare a function used in a template?

Hi @all, I've got (probably) a simple question. When do I have to declare a function used in a template? The following code prints out (using gcc >=4.1): init my A object no init Using gcc 4.0 the following code prints out: init my A object init my string object #include <iostream> #include <string> template<typen...

get Rails3 app name in a template that generates a rails app?

I have a template that generates a rails app. The problem is that in my template scenario I substitute some files, like environment.rb, that need to know rails app name to run things like AppName::Application.initialize!. I could get the app name from the command line arguments, but that's not always possible, since a user could do that:...

Customise default 'New Stored Procedure' SSMS 2008 Template

I am trying to customise the default query which is put in place when you click New Stored Procedure... from the Object Explorer on SQL Server Management Studio 2008. I have found how to change the 'Create Stored Procedure (New Menu)' template from the Template Explorer, however this means I will have to keep opening the template explor...

What is a good way to set up a site template with PHP on IIS6?

I am not very experienced with PHP. I have a site I'm maintaining that is on IIS6 using PHP. Right now it is using include files and querystrings to server up content. For example: http://mysite/index.php?maincontent=services&amp;subcontent=service1&amp;nav=subnav1 We want to change the site so that URLs look more like (for example):...

how to add control to ITemplate

Hi there, I have a custom templated control as follow: How do I programatically add control into the templateOne? thanks ...

map iterator in template function unrecognized by compiler

I have the following code. template<class key,class val> bool has_key(key chkey,std::map<key,val> map){ for (std::map<key,val>::iterator it = map.begin(); #line 13 referenced by gcc it!=map.end(); ++it){ if(chkey == it->first) return true; } return false; } GCC is giving me the following error. objects.hpp: In functio...

Boost.Test output_test_stream fails with templated output operator

I have a class: class foo { private: std::string data; public: foo &append(const char* str, size_t n) { data.append(str,n); } // for debug output template <typename T> friend T& operator<< (T &out, foo const &f); // some other stuff }; template <typename T> T& operator<< (T &out, foo const &f) { return out...

Template subclass pointer problem

In a moment of madness, I decided to write a quadtree C++ template class. I've run into some weird compiler error that I don't understand with regard to subclasses and pointers to templates. I've found some hacky work arounds, but I wondered if anyone could shed some light on why my code wouldn't compile... I'm on Linux, building with...

Django reply form included into question template

if a have a question - answer system, where the answer form is included in the template of questions,(just like facebook post-comments) is there another way to save the comments for every question? how can i take the id of the question? my code: {%include "replies/replies.html"%} #thats in the template where questions are listed the ...

django css file not recognised - wrong configuration?

in my app, i want to use a css file, but the tempalte doesn't 'know' where the file is, though i've configured it as in tutorials: in the urls.py (the urls file in the root of the site, not belonging to an app) (r'^site_media/(?P<path>.*)$', 'django.views.static.serve', {'document_root': settings.STATIC_DOC_ROOT}), in the tem...

C++: strange behaviour with templates and #defines

I have the following definitions: template<typename T1, typename T2> class Test2 { public: static int hello() { return 0; } }; template<typename T> class Test1 { public: static int hello() { return 0; } }; #define VERIFY_R(call) { if (call == 0) printf("yea");} With these, I try to compile the following: VERIFY_R( Test1<int...

[Eclipse] Creating code template that evaluates newly created var

I am writing a lot of unit tests these days. And I want to minimize the amount of typing I have to do. So I have created several Eclipse coding templates. Most of them work fine. But, recently I want to do a bit more advanced stuff. I use EasyMock and when writing expectations , I find myself writing stuff over and over again. I want...

Generating permutations via templates

I'd like a function, or function object, that can generate a permutation of its inputs with the permutation specified at compile time. To be clear, I am not looking to generate all of the permutations, only a specific one. For instance, permute<1,4,3,2>( a, b, c, d ) would return (a,d,c,b). Obviously, it is straightforward to do this ...

Template Binding to background and foreground colors?

I'm building a simple ControlTemplate for a Button. I want to draw a 2 color gradient, and bind the two colors so I don't need to hard code them in the template. But since Background and Foreground are Brushes and not just Colors, I'm not sure this will work. Can anyone tell me if there is a good way to do this? it seems simple enoug...

Drupal main theme template file for any node

How can I switch to a different theme template file for any node that I want? I understand how to create sub-themes like node-recipes.tpl.php for a node that has a path of "recipes". But what I want to have control of the entire base template like page.tpl.php. Can I use some preprocess function in template.php for this? Right now I hav...