how to disable the automatic mapping of std::vector<std::vector<double> > to tuple of tuples in swig python?
Question: Apparently, swig transform automatically `std::vector<std::vector<double> >`
to a tuple of tuples. I want to prevent this, and I want the type to be kept
as is. How can I achieve it? I tried specifying a definition for the type

    
    
    %template(StdVectorStdVectorDouble) std::vector<std::vector<double> >;
    

but apparently it does not work.


Answer: Two techniques:

  1. `%clear` the typemap for the type before the function is processed by SWIG.
  2. Declare the `%template` _after_ the function is processed by SWIG.

### Example 1

    
    
    %module x
    
    %begin %{
    #pragma warning(disable:4127 4211 4701 4706)
    %}
    
    %include <std_vector.i>
    %template(vd) std::vector<double>;
    %template(vvd) std::vector<std::vector<double> >;
    %clear std::vector<std::vector<double> >;
    
    %inline %{
    #include<vector>
    std::vector<std::vector<double> > func()
    {
        std::vector<std::vector<double> > temp;
        std::vector<double> a;
        a.push_back(1.5);
        temp.push_back(a);
        return temp;
    }
    %}
    

### Example 2

    
    
    %module x
    
    %begin %{
    #pragma warning(disable:4127 4211 4701 4706)
    %}
    
    %include <std_vector.i>
    
    %inline %{
    #include<vector>
    std::vector<std::vector<double> > func()
    {
        std::vector<std::vector<double> > temp;
        std::vector<double> a;
        a.push_back(1.5);
        temp.push_back(a);
        return temp;
    }
    
    %}
    
    %template(vd) std::vector<double>;
    %template(vvd) std::vector<std::vector<double> >;
    

### Result (of both)

    
    
    Python 3.3.0 (v3.3.0:bd8afb90ebf2, Sep 29 2012, 10:57:17) [MSC v.1600 64 bit (AMD64)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import x
    >>> x.func()
    <x.vvd; proxy of <Swig Object of type 'std::vector< std::vector< double,std::allocator<double > > > *' at 0x00000000025F6900> >
    

