Sunday, 22 September 2013

Using Templates in C++ Programming

I would describe about using templates in c++.

  1. functions using templates  

  2. classes using templates  

  3. Template Specialization  
    Template Specialization means that specialize your template for some particular type. eg. you define add function for integers to be integers addition but for strings it may be addition. So You need to define it seperately.

Tuesday, 17 September 2013

My Latest Template for Programming Contests

I have learnt few good things about c++.

  • you can directly use this header file, it will precompile all the header files required.

#include <bits/stdc++.h>
using namespace std;

  • struct _ { ios_base::Init i; _() { cin.sync_with_stdio(0); cin.tie(0); } } _;

this is meant for reducing slowness of slowness of iostream in syncing. more on

Precaution: You need to make sure that you do not use scanf and cin statements interchangibly means
one code should exclusively use cin and cout's only if you are using this. Reason is quite obvious.

I have tested the code on codechef. It works great :). Infact slightly faster :)

Here is the link of my latest template: