Hints

Class template instantiation alias

Py++ has nice feature. If you define typedef for instantiated class template, than Py++ will use it as a Python class name.

For example:

#include <vector>
typedef std::vector< int > numbers;
numbers generate_n(){
    ...
}

Py++ will use “numbers” as Python class name:

using boost::python;
class_< std::vector< int > >( "numbers" )
    ...
;

Py++ will pick up the alias, only in case the class has single “typedef”.

pyplusplus::aliases namespace

The previous approach is “implicit” - Py++ does something behind the scene. Recently (version 0.8.6 ), another approach was introduced:

#include <vector>

namespace pyplusplus{ namespace aliases{
//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    typedef std::vector< int > numbers;

} } //pyplusplus::aliases

The idea is that you create namespace with a special name - pyplusplus::aliases and Py++ automatically picks the class aliases from it. In case you accidentally introduced two or more different aliases to the same class, it will pick the longest one and print a warning. Other advantages of the approach:

  • you are not forced to learn new API
  • you continue to use your favorite editor and familiar language