Madsdyd’s Weblog

March 9, 2009

The magic of C++ templates

Filed under: Uncategorized — Tags: — madsdyd @ 8:57 am

Yesterday I went and wanted to convert a function into a templated function in C++. No big deal, but one of my constructs gave me some problems. I’ll illustrate with an example function, that contains the problem I had

void myfunc( int a ) {
some_class::some_method<some_class>( a );
}

There are good reasons for some_method to be templated with some_class, which has to do with the fact that some_method is static and needs to interface to some C code, that expects static callbacks, and what not.
I wanted to make this work for both some_class, and some_other_class. Here is my first try:

template <class T>
void myfunc( int a ) {
T::some_method<T>( a );
}

This declaration/definition does not work. The compiler wants a primary expression before the first >,and complains about the “,” operator ignoring its first argument.
I was a bit stumped by this, but got some help from ##c++ on irc.freenode.net.
Here is the right way to write it:

template <class T>
void myfunc( int a ) {
T::template some_method<T>( a );
}

Turns out, that when the compiler needs to figure out what some_method is, it can not look in T for help. So, it assumes that some_method is not a templated function, and the first ‘<’ is interprented as operator<. This also explains why it want a primary expression, and why it complains about operator,.

The solution: Let the compiler know that some_method is templated, by inserting “template ” before the method call.

March 7, 2009

Kontact can post to wordpress

Filed under: Uncategorized — madsdyd @ 9:00 pm

Read on userbase.kde.org that kontact can be used to post blog entries, and behold! It works.

March 3, 2009

Exim4 and max size of received messages in kubuntu/debian

Filed under: Uncategorized — Tags: — madsdyd @ 8:24 am

Turns out exim3/4 at some point introduced a max size for messages it wants to receive.

If you have not changed anything, exim will refuse to accept messages larger than 50MB. I need to be able to receive mails larger than this.

Figuring out how to change it under Kubuntu/debian was a bit harder than I thought, but I got some help on irc. First of all, debian allows to configure in two “modes”: split and non-split. This assumes split, which I believe is the default:


sudo echo MESSAGE_SIZE_LIMIT=2000M >> /etc//exim4/conf.d/main/00_exim4-config_localmacrodefs
sudo update-exim4.conf
sudo /etc/init.d/exim4 restart

You can then check that the new size is set with


sudo exim4 -bP message_size_limit

Thanks to valdyn and petemc on irc.freenode.net for helping me out.

Blog at WordPress.com.