← Back to team overview

dolfin team mailing list archive

Re: shared_ptr should soon be up and running in python

 

For the curious, there's a solution here:

http://www.gotw.ca/gotw/079.htm

but we don't want to do that.

Basically, we would have the syntax
dolfin::shared_ptr<Function>::type
and likely all sorts of trouble with swig to go with it.

See attached file for a full test code I just wrote.

Martin


On Tue, Jan 13, 2009 at 10:02 AM, Johan Hake <hake@xxxxxxxxx> wrote:
> On Tuesday 13 January 2009 08:37:00 Martin Sandve Alnæs wrote:
>> On Tue, Jan 13, 2009 at 12:00 AM, Johan Hake <hake@xxxxxxxxx> wrote:
>> > On Monday 12 January 2009 23:52:15 Anders Logg wrote:
>> >> On Mon, Jan 12, 2009 at 09:28:02PM +0100, Johan Hake wrote:
>> >> > Hello!
>> >> >
>> >> > After some hours chasing a bug I finally got shared_ptr to work in all
>> >> > of the three aspects I mentioned in a previous email. I requires some
>> >> > changes to
>> >> >
>> >> >   dolfin, instant, ufc and ffc.
>> >>
>> >> Nice!
>> >>
>> >> > Most notably we have to change back to boost::shared_ptr.
>> >> > std::tr1::shared_ptr is not supported in swig untill swig 1.3.37. I
>> >> > just replaced all the occurences of std::tr1::shared_ptr with
>> >> > boost::shared_ptr. Probably we can add a typedef/typename in
>> >> > common/shared_ptr.h or something. I couldn't get it to work though.
>> >> > Any comment on this one?
>> >>
>> >> I tried making a typedef a while back without luck.
>> >
>> > Probably the same as I did then. Should I just check it in with all
>> > std::tr1::shared_ptr exchanged with boost::shared_ptr? This will then
>> > also be the case for the shared_ptr types in dolfin_format in ffc.
>> >
>> > Do you Martin have a clue?
>> >
>> >  namespace dolfin {
>> >    typdef shared_ptr boost::shared_ptr
>> >  }
>> >
>> > wont work.
>>
>> Did you mean
>>
>>   namespace dolfin {
>>     typedef boost::shared_ptr shared_ptr;
>>   }
>>
>> ?
>
> Yup :)
>
>> If that was just fast email typing, I'm not quite sure
>> how templates and typedefs work together, if there's
>> something special going on there.
>
> Ok, then I just check in the changes where all std::tr1::shared_ptr are
> changed to boost::shared_ptr.
>
> Johan
>
namespace boost
{
    template<class T>
    class shared_ptr
    {
    public:
        T * p;
    };
}

namespace stdtr1
{
    template<class T>
    class shared_ptr
    {
    public:
        T * p;
    };
}

namespace dolfin
{
    template<class T>
    class shared_ptr
    {
    public:
        // Switch type choice here
        typedef boost::shared_ptr<int> type;
        //typedef stdtr1::shared_ptr<int> type;
    };
}

typedef boost::shared_ptr<int> int_shared_ptr1;
typedef stdtr1::shared_ptr<int> int_shared_ptr2;
typedef dolfin::shared_ptr<int>::type int_shared_ptr3;

int main(int argc, char **argv)
{
    int_shared_ptr1 ip1;
    int_shared_ptr2 ip2;
    int_shared_ptr3 ip3;

    dolfin::shared_ptr<int>::type * ip;
    ip = &ip1;
    //ip = &ip2; // Error! dolfinshared_ptr<T>::type == shared_ptr1<T>, not shared_ptr2<T>.
    ip = &ip3;
}


Follow ups

References