templates

calculating factorial using template meta-programming

I do not understand how this piece of code (from Wikipedia) works: template <int N> struct Factorial { enum { value = N * Factorial<N - 1>::value }; }; template <> struct Factorial<0> { enum { value = 1 }; }; // Factorial<4>::value == 24 // Factorial<0>::value == 1 void foo() { int x = Factorial<4>::value; // == 24 i...

Problem using templated predicate in STL algorithms

I have the following piece of code, that gives an error on the first usage form of pred2. I was hoping if someone could explain why this particular usage is incorrect, as I think pred3 usage is similar. #include <algorithm> bool pred1(const int&) { return true; } template<typename T> bool pred2(const T&) { return true; } struct pred3...

Magento email template format date of invoice

Hi, I'm trying to apply the german format of a date to a Magento email. I can get the invoice date with {{var invoice.created_at}} but that gives me "2010-05-21 15:46:24". I would like to have 21.05.2010 and PHP doesn't work in the templates. I'm totally new to Magento so please be patient :-P Greetz Spanky ...

function templates with class template typedef arguments

Hi, the following code is an example of something I'm trying to do in a large project: #include <iostream> #include <vector> // standard template typedef workaround template<typename T> struct myvar {typedef std::vector<T> Type;}; template<typename T> T max(typename myvar<T>::Type& x) // T max(std::vector<T>& x) { T y; y=*x.begin(...

C++ Partial Ordering Fails with 2 Template Parameters

So given the following template functions with partial specialization template<typename T> void foo(vector<T> &in) { cout << "vector" << endl; } template<typename T> void foo(T &in) { cout << "scalar" << endl; } int main(int arc, char *argv[]) { vector<double> a; double b; foo(a); foo(b); return 0; } I h...

interface forwarding from member variable using C++ templates

How do I say: template<typename T> class X { // if T has method x(), define // Y x() { return t.x() } T t; }; ...

Make a Joomla Section Menu Item drill into a Category Blog layout, display issues

I followed the "third option" in the instructions at: http://docs.joomla.org/Make_a_Section_Menu_Item_drill_into_a_Category_Blog_layout and the results are as expected, except... when I drill into a category to see the blog layout... the articles are in a single column for the first article, and then it's two columns after that... and i...

Text only free css template

Hi All, Am developing a web app and creating few screens for it. I want to concentrate on the login and the server side code for now so I just have the bare minimum html required to display the data. But it looks ugly. Are there any free text only stylesheets that I can just include and it will look decent. I plan to work on the desig...

Autosize for Text in Control Template

Hey, I am creating a template for a button. I want the text that is placed inside the button to grow and shrink with the size of the button. My style: <Style x:Key="BigRoundButtonWithNumber" TargetType="{x:Type Button}"> <Setter Property="OverridesDefaultStyle" Value="False"/> <Setter Property="Foreground" Value="White" /> ...

Django view - load template from calling app's dir first

I try to keep a somewhat consistent naming scheme on my HTML templates. I.e. index.html for main, delete.html for delete page and so forth. But the app_directories loader always seems to load the template from the app that's first alphabetically. Is there any way to always check for a match in the calling app's templates directory first...

JSF 2.0 Temlating and injection of MB || CDI bean

Hi everyone! Problem: managed bean not injecting by template. Goal: I wan to decelerate logout button in template. Scenario: I am building j2ee 6 application with jsf 2.0 for web part. template file layout/template.xhtml <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-tr...

unfamiliar with struct/class declaration with template

while going through some of the mili source code I came across a struct declared like this: template <class T, class Pre, class Pos> struct PrePosCaller<T*, Pre, Pos> (from here) The part I'm unfamiliar with is <T*, Pre, Pos>. I understand what the code does and its purpose in this context but I would like to know where it is documen...

Create project or solution-specific item templates for Visual Studio?

I know how to create project or item templates and install them. What I would like is to have item templates that are specific to a single solution. In this case I have an ASP.NET MVC project and I would like to have default templates that inherit from my base Controller class, my base ViewPage`1 class, etc. instead of the default one...

min and perfect forwarding

The min algorithm is normally expressed like this: template <typename T> const T& min(const T& x, const T& y) { return y < x ? y : x; } However, this does not allow constructs of the form min(a, b) = 0. You can achieve that with an additional overload: template <typename T> T& min(T& x, T& y) { return y < x ? y : x; } What ...

inline rendering of template + layout in symfony

I'm trying to process html email by rendering a template and layout inline, and sending the result. I can get a template to render inline, but wrapping it in a layout isn't working. This is what I have so far: $template = new sfPartialView(sfContext::getInstance(), 'email', 'send', 'my_template'); $template->setTemplate('my_template'); ...

I have some circularities in my template class definitions.

I have a matrix class that takes the row and column reference type that can be used to access it as template parameters. Meanwhile, the row and column types are passed the matrix type that they are representing. Is there any way to break this circularity? Here are some demonstrative code snippets: #include "MatrixConcreteType.h" temp...

Sharepoint Designer, web part zone and table column

Hello, I am learning to create a template in sharepoint 2007, using SPD 2007 from a site collection. I've been using some of the template that comes with MS-sharepoint 2007 for my team. But they found a site that they like the look and feel of it. http://ic.buffalostate.edu. How i am going to create a template like that, I do not do co...

C++ template specialization of templated types

I'm looking to help users of some of my templated code by using BOOST_STATIC_ASSERT to let them know that they've used an incompatible type with a simpler compile error message than the monster than is currently produced with an incompatible type. The example is a bit too complex to reproduce here, but hopefully this will capture the es...

Inheritance and storing static class information

I'm trying to set up some stuff with Lua, but the specifics of Lua aren't important for my question. What I would like to be able to do is call a function, say OpenLib<T>(L), and have it get the table name for a particular class (as well as it's table) and register it with Lua. It essentially boils down to this: template <class T> sta...

Please help me understand this syntax (implementing static assert in C++)

This syntax was used as a part of an answer to this question: template <bool> struct static_assert; template <> struct static_assert<true> {}; // only true is defined #define STATIC_ASSERT(x) static_assert<(x)>() I do not understand that syntax. How does it work? Suppose I do STATIC_ASSERT(true); it gets converted to static_a...