SWIG wrapping C++ for Python: translating a list of strings to an STL vector of STL strings

后端 未结 2 1820
清歌不尽
清歌不尽 2020-12-31 16:01

I would like to wrap a C++ function with SWIG which accepts a vector of STL strings as an input argument:

#include 
#include 
#         


        
2条回答
  •  爱一瞬间的悲伤
    2020-12-31 16:09

    You need to tell SWIG that you want a vector string typemap. It does not magically guess all the different vector types that can exist.

    This is at the link provided by Schollii:

    //To wrap with SWIG, you might write the following:
    
    %module example
    %{
    #include "example.h"
    %}
    
    %include "std_vector.i"
    %include "std_string.i"
    
    // Instantiate templates used by example
    namespace std {
       %template(IntVector) vector;
       %template(DoubleVector) vector;
       %template(StringVector) vector;
       %template(ConstCharVector) vector;
    }
    
    // Include the header file with above prototypes
    %include "example.h"
    

提交回复
热议问题