templates

Typedefs and template specialization

Consider this code: typedef int type1; typedef int type2; template <typename> struct some_trait; template <> struct some_trait<type1> { static const int something=1; }; template <> struct some_trait<type2> { static const int something=2; }; It fails because what the compiler sees is two specializations of some_trait<int>. ...

Unused template functions in shared library

Hello I have a template function in a shared library written in C++(the function is not called anywhere in the library, so it shouldn't be generated, am i wrong?) [g++, Linux] I try to use this template function in the application but compiler gives link error.I searched the function using objdump but I can not see the function in the ...

Django Template Headings

Is there a way in Django templates to show a heading for a field (name of the field) only if the field has a value. For instance if one of the fields was called Year Established it might look something like this. Year Established: 1985 But if the field was empty then it wouldn't show Year Established like this. Year Estabished: I k...

How to idiomatically call C++ functions based on variable value?

Suppose I have a data type enum TreeTypes { TallTree, ShortTree, MediumTree }. And I have to initialize some data based on one particular tree type. Currently I have written this code: int initialize(enum TreeTypes tree_type) { if (tree_type == TallTree) { init_tall_tree(); } else if (tree_type == ShortTree) { ...

C++ templates and object code instantiation

With this question I'd like to better understand how C++ templates system works with regards to this question. As far as I know, template-based classes and functions are usually placed into header files. This is due to the technical issue of managing generic data types, which characterstics are unknown in principle. As soon as they are ...

How do I select a member variable with a type parameter?

Hi, I have a cache object that caches a number of different types of objects, as illustrated below: class Cache { public: ObjectTable<ObjTypeA> m_objACache; ObjectTable<ObjTypeB> m_objBCache; ObjectTable<ObjTypeC> m_objCCache; }; The (horrible) way I'm currently using the cache at the moment is directly accessing the cache...

cleaning up heavy use of template parameters

I have a set of classes in a logging framework used by project A and B. I am refactoring the framework so it can be used in project B and C. The refactoring mainly consists of giving everything template parameters: project A might run on an embedded device with poor/no STL implemenatation, while B and C just run on a pc, but B is single ...

How to mock templated methods using Google Mock ?

I am very new to Google Mock and to StackOverflow, sorry in advance if my question is not well posed. I am trying to mock a templated method. Here is the class containing the method to mock : class myClass { public: virtual ~myClass() {} template<typename T> void myMethod(T param); } How can I mock the method myMethod u...

How to escape liquid template tags?

This sounds very easy, however I couldn't find it anywhere in the docs. How can I write {% this %} in a liquid template, without it being processed by the engine? ...

How to distinguish Mouse.Clicks from different part of a control

If I have a Control with template like this: <Style x:Key="HomeButtonStyle" TargetType="{x:Type Control}" > <Setter Property="Template"> <Setter.Value> <ControlTemplate> <StackPanel VerticalAlignment="Top"> <Rectangle Width="20" Height="50" x:Name="PART_Rectangle" /> ...

Number of permissible active iterators into a vector

For example is the following valid? std::vector<int> vec(5, 0); std::vector<int>::const_iterator it1(vec.begin()); std::vector<int>::const_iterator it2(vec.begin()); //Use it1 and it2 like they don't know about each other. Is there a special name for a container that permits multiple active iterators? ...

Unit tests for HTML Output?

This may be a dumb question, but do you make unit tests for the HTML output of your PHP functions/scripts? I try to keep my HTML and my PHP separate - i.e. HTML includes with placeholders, and functions for certain recurring elements (tabular data / any sort of looped output) - but I'm not sure how to go about verifying this. Is there ...

Using c++ template an argument to an objective-c method.

How can I use a c++ template as an a parameter to an objective-c method? essentially I want to do something like this: template<typename T> - (void)method:(T)arg but that doesn't work. according to this document this is possible however it does not provide any examples. Does anyone know how tot do this? ...

Use different sets of functions based on template parameters (C++ traits?)

I have defined a class in C++ which holds an array of scalars of type T for which I want to define operators like sin, cos, etc. For defining the meaning of sin applied on an object of this class I need to know the meaning of sin applied on the single scalar type T. This means I need to use appropriate math libraries (corresponding to th...

"unresolved external symbol" on template specialization for array of char

I have something like this in my code: template <typename T> struct A { void Print(); }; template <> struct A<char*> { void Print() { printf("Char*!\n"); } }; template <typename T> void DoSomething(T& lol) { A<T> a; a.Print(); } int main() { char a[5]; DoSomething(a); } And this produces the following linker error: err...

SFINAE: some failures more equal than others?

I'm trying to use SFINAE to distinguish a class that has a member called 'name'. I set things up in what seems to be the standard pattern but it's not working -- instead of silently ignoring the 'failed' substitution, the compiler produces an error. I'm sure I've run up against some template substitution rule, I'd be grateful if someon...

C++ meta-programming doxygen documentation

I am documenting some code which uses meta-programming heavily, for example: template<rysq::type A, rysq::type B, rysq::type C, rysq::type D, class Transform> struct Kernel<meta::braket<A,B,C,D>, Transform, typename boost::enable_if< quadrature<meta::braket<A,B,C,D>, Transform> >::type> : Eri <Transf...

Rails response.format fallback?

A rails app has some files end with .mobile.erb, which is for iPhone. There is before_filter which set request.format = :mobile by check the request.user_agent. My question is below: If some_action.mobile.erb doesn't exist. How to fallback to some_action.html.erb rather than an error page. ...

Different types of authors in Wordpress?

I want to make a website about illustrated books. There are two different kind of authors for a book: writers and illustrators For each writer I want to make a page that lists the books for that writer. The path would be: http://mysite.com/writers/EdgarAllanPoe http://mysite.com/writers/OscarWilde etc The same for each illustrator: ...

Mako or Jinja2 ?

I didn't find a good comparison of jinja2 and Mako. What would you use for what tasks ? I personnaly was satisfied by mako (in a pylons web app context) but am curious to know if jinja2 has some nice features/improvements that mako doesn't ? -or maybe downsides ?- ...