templates

Templates: instantiating from (and refering to) non-typed parameter at runtime?

I developed a generic "Unsigned" class, or really a class template Unsigned<size_t N> that models after the C (C++) built-in unsigneds using the amount of uint8_ts as a parameter. For example Unsigned<4> is identical to a uint32_t and Unsigned<32> would be identical to a uint256_t -- if it existed. So far I have managed to follow most i...

C++ Templates - Specifying a container type and that containers element type that it holds

I want to be able to create a function where I specify a parameter to have both a templated container and a templated element type for that container. Is this possible? I get "error C2988: unrecongnizable template declaration/definition" among others. Here is the function in question. template<class Iter, class Elem> void readIntoP(...

Passing an iterator to a function

Looking through the source code of a binary tree,I find the following function: //definition of BTR,in case you'd want to know template< class Type> struct BTR { // The item saved to that specifiec position into the tree Type value; // Points to the left leaf BTR<Type>* left; // Points to the right leaf ...

How to check that template's parameter type is integral?

In the description of some std template function I saw something like: if the template parameter is of integral type, the behavior is such and such. otherwise, it is such and such. How can I do a similar test? Perhaps dynamic_cast? Since the function I write is for my personal use I can rely on myself to supply only correct para...

Overloaded [] operator on template class in C++ with const / nonconst versions

Whew, that was a long title. Here's my problem. I've got a template class in C++ and I'm overloading the [] operator. I have both a const and a non-const version, with the non-const version returning by reference so that items in the class can be changed as so: myobject[1] = myvalue; This all works until I use a boolean as the templa...

SWIG2 template return type namespace not detected

Hi there. I'm swigging to Java. I'm trying to get a templated member func to use some templated return type, which i have to give a name of course (since otherwise SWIG would not create the needed source). test.i is like: %module Test %{ #include <vector> namespace ns { class C { public: template <class T> void doit(con...

Multiple Grails scaffolding templates in one application

Hello, I'm creating a DB web application with grails for my company and found myself in the need to change the default scaffolding templates. So far so good, everything gets generated with the modified templates (controllers, views, ..). Now, however, I get a request to create some "composite screens" with functionalities and a layout...

midlet application

I have to generate random number between 1 to 10 and compare the highers number and lower numbers. if the random number is high then display on the screen otherwise goto wrong screen shown text box, score, if the random number is low compare to lower num then display on the lower screen.here we have to increment score with 5 for every co...

How do I use DisplayFor() for objects that are not directly part of my model in asp .net mvc 2?

I'm sure I'm missing something pretty simple here. I've created a custom DateTime display template. This works fine when using: <%= Html.DisplayFor(x=>x.DateTimeProperty) %> However, I have a situation where I am iterating over objects in the Model in a for loop while inside a partial control. I want a DateTime property to use the dis...

Factory pattern and class templates in C++

I have a hierarchy of class templates. At the top of the hierarchy is an abstract base class (interface). I won't know which concrete implementation to instantiate until runtime, so it seems like the perfect situation to use the factory pattern. However, virtual member function templates are not allowed in C++. How can I achieve a le...

Latex: Different pages with different margins

Hello everybody! I'm making a latex template for a document type to use at work. For that document, I have two different "commands" one to make the title page; and other to make the rest of the document. The margins that I need in the title page are different from the ones in the rest of the document. Because of that I have some "\setl...

Modifying Joomla Main Menu's submenu using template override

Hi, I would like to achieve the following in my Joomla template's main menu: <ul class="topmenu"> <li><a class="nav_link" id="active" href="#">Home</a></li><span class="separator"></span> <li><a class="nav_link" href="#">About Us</a></li><span class="separator"></span> <li><a class="nav_link" href="#">Ser...

Need help fixing expensive website template

Hello All, I bought this website template from dreamtemplate and the copyright text displays on the center of the page ontop of the main body content! I had not changed any code at all. It was like that when I extracted the files. I looked at the code and couldn't find anything wrong, but I guess that doesn't say much since I had to buy...

Partially specialize template member function

Hello, I have a template class which looks like the following: template <template <class TypeT> class PoolT=pool_base> struct pool_map { public: template <typename U> struct pool { typedef PoolT<U> type }; public: template <typename T, size_t S=sizeof(T)> T& get( size_t index ); private: pool<uint8_t>::type pool8_; pool<ui...

Why can't templates take function local types?

In C++ it's OK to have a funcction that takes a function local type: int main() { struct S { static void M(const S& s) { } }; S s; S::M(s); } but not OK to have a template that does: template<typename T> void Foo(const T& t) { } int main() { struct S { } s; Foo(s); // Line 5: error: no matching function for call to 'Foo(...

Magento - How to pull a configurable product view into a template

I have a template file under the 'page' directory. This template has been assigned to be a category's 'Page Layout' through the backend. In this template I have a configurable product object. The following pulls in the view, but all it has in it is the product's name and short description. $prod = /* get product object here */; $layo...

String functions in MediaWiki template?

One of the more interesting "programming languages" I've been stuck with lately is MediaWiki templates. You can do a surprising amount of stuff with the limited syntax they give you, but recently I've run into a problem that stumps me: using string functions on template arguments. What I'd like to do (somewhat simplified) is: {{myTemp...

Spooky Custom Template Filter?

Hi Folks, I was having trouble trying to iterate on a template on two dimensions at the same time. The basic situation is explained here: http://www.djangobook.com/en/2.0/chapter04/ ( in the apples, bananas indices example ) >>> from django.template import Template, Context >>> t = Template('Item 2 is {{ items.2 }}.') >>> c = Contex...

Use template template class argument as parameter

Modern C++ Design gives the following example: template <class T> struct EnsureNotNull { static void Check(T*& ptr) { if (!ptr) ptr = GetDefaultValue(); } }; template < class T, template <class> class CheckingPolicy = EnsureNotNull, template <class> class ThreadingModel > class SmartPtr : public CheckingPol...

Can I use a SFINAE test in a control flow statement?

I have an SFINAE test for checking if an class has a function. The test works correctly, but I get compiler errors when I try to use it in an if statement. //SFINAE test for setInstanceKey() template <typename K> class HasSetInstanceKey { template <typename C> static char test( typeof(&C::setInstanceKey) ); template <typen...