templates

C++ template parameter in array dimension

I have have the following code using templates and array dimension as template non-type parameter template<int n> double f(double c[n]); ... double c[5]; f<5>(c); // compiles f(c); // does not compile should not the compiler to be able to instantiate the second f without explicit template parameter? I am using g++4.1 thanks ...

How to have templated function overloads accept derived classes from different base classes?

I want to be able to define template <class TX> void f(const TX &x){ ... } template <class TY> void f(const TY &x){ ... } where TX must be derived from BaseX and TY must be derived from BaseY (how do I specify this kind of thing?), and I want to be able to call it as f(DerivedX<T>()) It is most important that I can avoid specifying...

What's A QT Or Open Source C++ Template For Ordinal Sorting

Hi, I am looking for a special template class, hopefully either a QT template or a self-contained open source library. This template class is intended to act as a container for a set of objects. Each object in the set has an integer-valued weight function but the weight function itself is arbitrary. It could range uniformly from 10 to ...

Choosing between PHP frameworks and template systems

I have a moderately simple assignment, to create a PHP/PDO site with login functionality and article retrieve/save/edit/search. No tags, nothing else. Is this overkill to use some framework for this? It it a good decision to use custom code + perhaps template system like Smarty for a simple site that will not grow too much? Is there a ...

Template function with dependent type parameters within template class

Hi, I've been trying to do this simple stuff and Visual studio 2008 does not seems to like it. template <class CharType> class SomeClass { public: template <class T1, class T2> static bool SomeOperator(const typename T1::const_iterator& p_Begin1, const typename T1::const_iterator& p_End1, ...

simulate C++ function template instantiation with implicit conversion

I already asked two questions related to what I'm trying to do (one resolved, one of which I will close soon). I know that C++ template instantiation does not allow any implicit conversions (see for example this comment), but I would like to simulate it. Suppose I have the following skeleton code: template <class T> struct Base_A{ ...

Custom template for Visual Studio Service References?

The Setup I want to consume a web service in Visual Studio. I added a service reference, pointing it at a WSDL document. I get a bunch of generated code that works like a champ. The Problem In the Service Reference dialog, I selected "Internal" as the "Access level for generated classes." It appears as though that puts the "interna...

CakePHP same 'view' for multiple functions

I have a Cakephp project the controller has several different methods. function Index() function IndexAuthor() And I want to use the same 'view' (or template, Index.ctp) for both of the methods of the control. ...

BeginEdit of a specific Cell from code behind

Is possibile begin edit of a specific cell from code behind with DataGrid control (WPF Toolkit)? I have to enable the celledittemplate of first cell of selected row after a button action...how can I do? ...

Tutorials about the Silverlight Navigation Application template?

Silverlight's Navigation Application template seems promising, however, I can't seem to find any tutorials (particularly video tutorials). Whatever I did find was from the beta and is inconsistent with the released version. Has anyone seen any non-beta tutorials (particularly video)? ...

Web templating (struts tiles) - best solution to indicate current page?

I would like to indicate the currently chosen page in a shared menu component of a web page in a Struts Tiles project. I can think of some possible solutions check current URL call some Javascript to indicate possibly hooked into the tiles or struts config files and read. I'm sure this problem has been faced many times before. What...

Templates or similar for JavaScript programs in the browser

I've done a lot of server-side HTML programming and used a number of different template languages for producing (X)HTML. This part is very clear to me. But what I'm wondering a bit about is how do people use this in client-side JavaScript programs? I mean, obviously there can be template languages written for JavaScript that work inside...

C++ template partial specialization - specializing one member function only

Hi everybody, Bumped into another templates problem: The problem: I want to partially specialize a container-class (foo) for the case that the objects are pointers, and i want to specialize only the delete-method. Should look like this: The lib code template <typename T> class foo { public: void addSome (T o) { printf ("adding...

Is compiler allowed to ignore inline in case of template specialization?

Hello everybody. Lets say you have simple template function (not class member for the sake of simplicity) with type specific specialization in the same .h file... template <class TYPE> void some_function(TYPE& val) { // some generic implementation } template <> inline void some_function<int>(int& val) { // some int specific ...

What’s An Algorithm or code for the obtaining ordinal position of an element in a list sorted by value in c++

Hi, This is similar to a recent question. I will be maintaining sorted a list of values. I will be inserting items of arbitrary value into the list. Each time I insert a value, I would like to determine its ordinal position in the list (is it 1st, 2nd, 1000th). What is the most efficient data structure and algorithm for accomplishing...

templated operator() overload C++

someone already asked this question, but the thread ended up with the original question not getting answered. suppose you have this: template<size_t i, class f_type> void call_with_i(f_type f); functor_type is either: a) a struct with a method that has the following signature: template<size_t i> operator()() const; or, b) a fun...

How to reduce template arguments?

Here I have functor of the follow kind: template<class T, class Foo, T Foo::*p> struct X { void operator()(Foo & f) { (f.*p) = 12 * (f.*p); // simple example. could be more complex `operator()` } }; And sample struct: struct FF { int m; int r; }; I want to use the functor X, but I don't want to explicitly spec...

How to explain C++ templates to junior developers?

One could break the question into two: how to read and to write templated code. It is very easy to say, "it you want an array of doubles, write std::vector<double>", but it won't teach them how the templates work. ...

Detecting the browser language of choice with PHP

Hello guys, I'm trying to implement this code to have different files to load for german, spanish or english browser languages of choice. The case is that with my spanish IE I still get the english file. <?php if (is_home()) { if (preg_match('/de-DE/i', $_SERVER['HTTP_ACCEPT_LANGUAGE'])) { include(TEMPLATEPATH . '/german-navbar.p...

Can I extract C++ template arguments out of a template class?

Basically, given a template class like this: template< class Value > class Holder { }; I would like to be able to discover the type Value for a given Holder class. I thought that I would be able to make a simple metafunction that takes a template template argument, like this: template< template< class Value > class Holder > class Ge...