C++11: unordered maps

The STL ships with a sorted map template class that is commonly implemented as a balanced binary tree. The good thing on this is the fast search average time ( O(log2N) if implemented as a balanced binary tree, where N is the number of elements added into the map) and that when the map is… Continue reading C++11: unordered maps

Advertisements

C++: Smart pointers, part 1

This is the first of several posts I wrote related to smart pointers: Smart pointers unique_ptr More on unique_ptr shared_ptr weak_ptr Memory management in C is too error prone because keeping track of each bunch of bytes allocated and deallocated can be really confusing and stressing. Although C++ has the same manual memory management than… Continue reading C++: Smart pointers, part 1

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: Provide type-safe replacements for functions with variable number of arguments (stdarg.h) Let the user to create instances of n-tuples. Create type-safe… Continue reading C++11: Variadic templates (functions)

Java: Writing a Windows Forms application using Java

I was playing around with IKVM.NET (www.ikvm.net) and I found it very very interesting. IKVM.NET is a Java Virtual Machine implemented on top of .NET; and though this is already kind of weird, the most interesting thing is that inside IKVM, the Java objects of your Java application are first class objects of the CLR.… Continue reading Java: Writing a Windows Forms application using Java

C++: The curiously recurring template pattern

Let's consider the following class: This class will be useful as the base class for implementing several specialized writers (a file writer and a console writer come to my mind right now), for instance: Nice, isn't it? We can use the Writer::write() method to write on any kind of media depending on the subclass we… Continue reading C++: The curiously recurring template pattern

C++: Inheritance on template specialization

When you implement something like: 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". The problem I see with this approach is that you must provide full implementations for the template and for the <char> specialization… Continue reading C++: Inheritance on template specialization