[C++-sig] Py++ and a std::vector of shared_ptrs

Joseph Lisee jlisee at gmail.com
Wed Nov 21 19:19:27 CET 2007


Hello,

I am trying to wrap a std::vector<boost::shared_ptr<MyType> >, and Py++ will
have none of it.  I am using indexing suite version 2, and telling Py++ to right
the module as multiple files.  I exclude everything at the global namespace
level then I find the namespace_t that corresponds to the "sample" namespace and
 include all of it.  When I attempt to compile the resulting files I get the
following error:

Here is the compile error (with lots of "instantiated here", before this):
/opt/ram/local/include/boost-1_34_1/boost/python/suite/indexing/value_traits.hpp
:56:
error: no match for ‘operator<’ in ‘((const
boost::shared_ptr<samples::A>*)p1)->boost::shared_ptr<T>::operator* [with T =
samples::A]() < ((const
boost::shared_ptr<samples::A>*)p2)->boost::shared_ptr<T>::operator* [with T =
samples::A]()’
scons: ***
[build/wrappers/samples/generated/vector_less_boost_scope_shared_ptr_less_sample
s_scope_A_grate__comma_std_scope_allocator_less_boost_scope_shared_ptr_less_sam
ples_scope_A_grate___grate___grate_.pypp.os]
Error 1

That error appears only why I try to wrap the "funcVectorShared" function,
without that function the code compile and works fine.

Here is the code the generates it:

SharedPtrVector.h:

#ifndef RAM_TEST_SHAREDPTRVECTOR_H
#define RAM_TEST_SHAREDPTRVECTOR_H

// STD Includes
#include <vector>

// Library Includes
#include <boost/shared_ptr.hpp>

namespace samples
{

class A
{
};

boost::shared_ptr<A> func();

std::vector<A> funcVector();
    
std::vector<boost::shared_ptr<A> > funcVectorShared();

}

#endif // RAM_TEST_SHAREDPTRVECTOR_H


SharedPtrVector.cpp:

#include "include/SharedPtrVector.h"

namespace samples
{

boost::shared_ptr<A> func()
{
    return boost::shared_ptr<A>(new A());
}

std::vector<A> funcVector()
{
    std::vector<A> items;
    items.push_back(A());
    items.push_back(A());
    return items;
}
    
std::vector<boost::shared_ptr<A> > funcVectorShared()
{
    std::vector<boost::shared_ptr<A> > items;
    items.push_back(boost::shared_ptr<A>(new A()));
    items.push_back(boost::shared_ptr<A>(new A()));
    return items;
}

}




More information about the Cplusplus-sig mailing list