Hi,

there are compile problems with std::auto_ptr.
The following code won't compile:

<code>
#include <memory>
#include <sigc++/functors/ptr_fun.h>


void test(std::auto_ptr<int>)
{
}


int main()
{
   std::auto_ptr<int> p;
   sigc::ptr_fun(&test)(p);

   return 0;
}
</code>



If function arguments are passed by value then sigc internally creates a 
const std::auto_ptr& with the type_trait<std::auto_ptr>::take, but 
std::auto_ptr has a copy constructor that takes a nonconst argument:
auto_ptr& operator =(auto_ptr& nonconst);


A way to resolve this problem is to define a specialization of the type 
traits for std::auto_ptr:

namespace sigc
{

template<typename T>
struct type_trait<std::auto_ptr<T> >
{
   typedef std::auto_ptr<T>  type;
   // doesn't work with g++
   //typedef std::auto_ptr_ref<T> pass;
   //typedef std::auto_ptr_ref<T> take;
   typedef std::auto_ptr<T>& pass;
   typedef std::auto_ptr<T>& take;
   typedef std::auto_ptr<T>* pointer;
};


} // namespace sigc



Could this specialization be taken into sigc++?
What do you think?


--
Klaus Triendl
_______________________________________________
libsigc-list mailing list
libsigc-list@gnome.org
http://mail.gnome.org/mailman/listinfo/libsigc-list

Reply via email to