C++11: C++-style listener list

Consider you want to create a class where you can register a set of listeners to be notified when something occurs. For example, this is a class that performs some task and you want to be notified when the task has been completely executed. See this code in Java:
Continue reading “C++11: C++-style listener list”

C++11: Variadic templates (functions)

A very interesting C++0x feature are the “variadic templates” that, in short, are template classes and functions with a variable number of parameterized types. They can be useful to do several things, for example:
Continue reading “C++11: Variadic templates (functions)”

C++: ‘auto’

The new standard of C++ is being released and it exposes a lot of features. Starting this post, I will write about such new features, how they are used and their benefits.

Some bits of history: The last published C++ standard is called C++03 and was published, oh surprise!, in 2003. Since such day, a lot of compilers implemented the features described by that standard. The standard committee continued to work on the next standard and they codenamed it C++0x. The ‘x’ meant it should have been published between 2003 and 2009 but it was not released in such dates; so, the people started to joke saying the ‘x’ means TEN in roman notation or the same Bjarne Stroustrup joked on it saying the ‘x’ stands for any hexadecimal value ;)
Continue reading “C++: ‘auto’”

C++: Inheritance on template specialization

When you implement something like:

/* 1 */ template <typename T> class MyClass { ... }; //template class for every T

/* 2 */ template <> class MyClass<char> { ... };  //template class full specialization for T=char

You are saying the C++ compiler: “Please, use the first template for all the MyClass<T> instances with any T except for the MyClass<T> instances where T = char”.
Continue reading “C++: Inheritance on template specialization”

C++: First message

#include <iostream>
#include <string>

using namespace std;

int main()
{
  string greeting = "Ifmmp!xpsme\"";
  
  for (string::const_iterator i = greeting.begin(); i != greeting.end(); ++i)
       cout << static_cast<char>((*i) - 1);
  
  cout << endl;
  return 0;
}

Hello, in this blog I want to publish some interesting information about C++ and other related topics (object oriented programming, generic programming, etc.); the idea is having this information useful and very accurate; so, since I am a fan of these topics but I am far from being an expert on them, I want you all to help me to improve the accuracy of every post I will write; therefore, your comments and suggestions will be really appreciated and will let me make the content of this blog better and better every day. Welcome and thank you for reading me.