NN – WordPress

January 5, 2008

Installation vs. Portable

Filed under: Uncategorized — by NN @ 9:46 am

There are too options today to distribute your application.
The most popular is some installation executable which does not much but copies or extracts file to the specified directory and sets shortcut.

This is very good, but sometimes you just do not want to install, but use the application without installation.

And there we go to portable applications.

So what the problem ? You now have two applications for the same !!!

Argh..

The solution: Make your program portable and installable at once !:)

January 1, 2008

Boost.TypeTraits

Filed under: boost, c++ — by NN @ 10:11 am

This is very nice library BUT it is compiled very slowly !! Especially if you include <boost/type_traits.hpp>

Beware !

So I had to write my own implementation of is_*** since boost is slow :(

Implicit conversion

Filed under: Uncategorized — by NN @ 9:49 am

Guess what does this do:

#include <iostream>

void f(char) { std::cout << "f(char)"; }
void f(...) { std::cout << "f(...)"; }

int main()
{
  int i = 0;
  f(i);
}

Of course the function f(char) is called !!!!

There are several solutions:
1.

void f(char) { std::cout << "f(char)"; }
template<typename T>
void f(T const&);

2.

template<typename type>
class only
{
public:
    only(type v)
        : v_(v)
    {}

private:
    type v_;

    template<typename other>
    only(other);
};

void f(only<char> c)
{
}

3. The best !

template<class T>
typename ::boost::enable_if< ::boost::is_same<T, char> >::type f(T)
{
  ::std::cout << "f(char)";
}
void f(...)
{
  ::std::cout << "f(...)";
}

Conclusions: C++ is a bad language.

Powered by WordPress.com