templates

Class Template Specialization vs. Function Overloading

Hello, I thought that I wanted to template function specialization, but this stackoverflow article makes me think that I should really by doing function overloading. However, I'm just not seeing how I could achieve what I want. I have been able to achieve the goal with a class template specialization, but I don't like the fact that I h...

Metaprogram for bit counting

I need bit counter utility in C++ that is capable of counting number of the most significant bit in a numeric constant value and present this number as compile-time constant. Just to make everything clear - number of the most significant bit for a set of numeric values: 255 => 8 (11111111b) 7 => 3 (111b) 1024 => 11 (1000000000...

Create class files with T4 template

Hi, I have 82 procedures that create data tables, and i want to iterate through this tables and dynamically create the following classes for each data table: * The data table contain two columns: Id, Desc. e.g. CountryId, CountryDesc. * Each of the bold items in the example class below is dynamically create based on the data table i am u...

Django question

Hello, I have a django app that suppose to display invoices and clients. Now for some reasons When I run the Django sever, for some reasons it only displays the invoice data in invoice_list but cannot displays the clients data in clients_list. The clients data does shows up in another view, but not in invoice_details view. EDIT: I Seem...

C++ - mapping type to enum

Hello! Is is possible to make compilation-time Type -> Enum Series mapping? Illustrating with an example: Let's say, I have some Type and a enumerated value: typedef int Type; enum Enumerated { Enum1, Enum2, Enum3, Enum4 }; and now I somehow state the following: "let's associate Enum1 and Enum4 with type Type (don't know how to im...

Difference between instantiation and specialization in c++ templates

What is the difference between specialization and instantiation in context of C++ templates. From what I have read so far the following is what I have understood about specialization and instantiation. template <template T> struct Struct { T x; }; template<> struct Struct <int> //specialization { //code }; int main() { S...

Template parameters in C++

Suppose I have arbitrary template method, which could receive parameters by value and by const reference (obviously, for trivial types and for objects accordingly). How is this situation handled when writing template function prototypes? I could make something like: template <typename T> void Foo(T value) { // Do something. } temp...

How can i change the default values of the Binding Option in WPF?

In my current project i'm using several textbox controls whose content is filled from objects which are coming from a database. The object uses validation to validate the correct insertion of the text. When i want to show a validation error (i.e. the text has to many characters) i have to add some binding options to the text property li...

Specifiying a templatized class with traits

I have a struct which indicates a trait: template<typename T> struct FooTraits { static const NEbool s_implementsFoo = false; }; And I can specialize it with a class, thus: class Apple {}; template<> struct FooTraits< Apple > { static const NEbool s_implementsFoo = true; }; However currently I cannot use FooTraits if the c...

comparing string literals in c++ templates

I wrote a template function to compare two variables: template <class t> int compare(const t &a, const t &b) { if(a>b) return 1; if (a<b) return -1; return 0; } int main(int argc, const char *argv[]) { cout << compare("hi","world"); return 0; } I get the following error ../src/templates.cpp: In function ‘int main(int...

Kohana 3: How to provide API functions in template/view like WordPress?

I'm working on a project which allows the advanced user to define their own way of showing the information and access some basic API. For example, I provide a show_search_box() function so that the user can call this function in the view file when they want to show the standard search box, or they could call the function with parameters ...

How to include javascript script links to pyrocms page?

I'm using pyrocms to develop a system. I know that, to include style links in header tag '' in a page is by using $this->template->set_metadata(). But how can I include javascript links like that? Any answer is appreciated. ...

Generate static web pages from a template as part of ASP.NET Web application build

I'm building an HTML5 application (with ASP.NET back-end) and i want to develop it in such a way that i can run it locally with all my resources (such js and css) not minified (so i can debug it easily). However when i build the final version i want merge and minify the resources. At the same time i want to create several versions of the...

C++ template work-around

On my C++ project, I recently stumbled upon a little problem: Templates. I declared a class, Data in my header file (which is shared by each .cpp), and gave it a template function. I implemented it in data.cpp. I soon remembered how templates are compiled on the spot, when they are referred to, and this breaks the declaration/implementa...

Const and non-const access resolves to different overloads?

Let me say we have a simple programming task. But for the sake of clarity I start with few code samples. First of all we written a some kind of data container class but for the purposes of task no matter what the class is. We just need it to behave const-correct. class DataComponent { public: const std::string& getCaption() const { ...

How to make new objects draggeble with live

Hello I have an Object like this (reduced form) <script type="text/javascript"> var tables = [ {id : 1, name : "event", attributes: [ { attname : "eventID", PK : true } ] } </script> and i use the microsoft template plugin to create ne HTML <script id="db_tbl_template" type="text/html"> <div...

Do you know a custom tag to increment a value in a Django template?

One very annoying thing with strict MVC is that you can make the smallest processing in template. While it's usually a good practice, in this case it gets in the way: I make a for loop on a queryset of a lot of objects and display some attributes; Attributes are properties, making heavy processing (I don't want to trigger them twice). ...

In C++, how to initialize static member of a private class declared inside a Singleton template ?

Ok, I should simply tell that I want to make a base Singleton class that I can inherit from, and the way I want to achieve that is by a template. In order to avoid memory leaks, I do not use directly a pointer to the instance, but a private class that will handle deleting the pointer. Here is my actual code (not working) : template <t...

Where are some good resources for word templates for programming needs?

For example, I have a wide variety of needs for templates, like in creating project plans, project specifications, requirements etc. But I have never created my own forms before, so it really helps to see other practical/actual examples. Is there a good central resource for ms word templates for programmers/programming? I have just st...

Send order lineitem details via email template in Dynamic CRM 4.0

Hi, How can I send email which is triggered by workflow against an invoice which includes the order details and lineitem details of invoice? Can I add custom data field item to email templates? Sanjay ...