Wednesday, April 11, 2007

Template - Specialization

For creating a specialized template:

// Generalized template : A must
template
class Generic
{
public:
Generic (T& value, C& constant)
{
std::cout << "Generic::Ctor " <<>
std::cout << "Value: " <<>
<< "Constant: " <<>
}
~Generic ()
{
std::cout << "Generic::Dtor" <<>
}
};

// Fully specialized template class
template <>
class Generic
{
public:
Generic (float& value, double& constant)
{
std::cout << "Generic::Ctor " <<>
std::cout << "Value: " <<>
<< "Constant: " <<>
}
~Generic ()
{
std::cout << "Generic::Dtor " <<>
}
};

// Partial specialization template class
template
class Generic
{
public:
Generic (T& value, int& constant)
{
std::cout << "Generic::Ctor "
<< "Value: " <<>
<< "Constant: " <<>
}
~Generic ()
{
std::cout << "Generic::Dtor " <<>
}
};

int
main ()
{
float f1 = 5.5f;
int i1 = 5;
double d1 = 3.3;

Generic temp1 (f1, d1); // fully specialized
Generic temp (f1, i1); // Partial specialization

return 0;
}

To find and replace across many files, following perl command will do your job faster and cleaner. This command just search for the string "this" replace the string with "that" across all files with the extension "*.sav", along with that it saves the original files with the extension "*.bak"

perl -pi.bak -e 's/this/that/' *.sav