Re: [eigen] std::swap doesn't work on Map |
[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] std::swap doesn't work on Map
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Mon, 5 Apr 2010 20:26:42 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:received:message-id:subject:from:to:content-type :content-transfer-encoding; bh=m5t0U6om4ydwd5vUceT2nYC1y0KndOc0RDxibQmAcws=; b=fqlIBcQYIVhZIc+hR1ykInVL7p+XauwKYexJ0I4wfhfCGQmnChDZkZoY+BxcrD1GQg KgN0UVOaisVMEwSoLAbisaBbzQGCZDUzJeUHNz8GewoSr7SYsJjj8PxZkLFhvD9oAy0h FvzHQGIBy3jbG1tUYWKRAjB6zTYQ9Ah3zAQ2g=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; b=bHoVLPuJlLh7bziKgpqvH665TuTh/jzoVjY1L/l+GU9dCMp+xfkQLLGYqFQWZ3vRSN Ea5/1S9/o/o9FQytQ2JoofMUR2wxQ+dTmHQVvZNWb4kKxtqYC0I6H5fMG5cY8XzCG1jh ZVWjCuzaNEpRSI6farPyacicDJqNVEvYdZ/Po=
Manoj: the outcome of this is that your idea of adding this to a
"known issues" kind of page is the best we can do. We actually have
something like that in the wiki:
http://eigen.tuxfamily.org/index.php?title=Pit_Falls
Benoit
2010/4/5 Manoj Rajagopalan <rmanoj@xxxxxxxxx>:
>
> Shall I file a bug report so this stays on the radar? Or can this be included
> in a "Known Issues" section in the Eigen documentation? Using swap() in my
> program made it buggy and since Eigen was new, I took no chances and
> experimented with just about every construct I was using and discovered this
> behavior. Others can benefit by not having to rediscover this.
>
> Thanks,
> Manoj
>
>
> On Monday 05 April 2010 01:31:19 am joel falcou wrote:
>> Benoit Jacob wrote:
>> > Normally we could consider fixing this by providing a partial template
>> > specialization of std::swap for Eigen types, but the big problem is
>> > that std::swap takes only 1 template parameter and expects both sides
>> > to be of the same type, and this is not always the case with Eigen
>> > swap on expressions. We could still catch the case where both sides
>> > have the same type, but I'm not sure what to do then. If we let that
>> > work, it's awkward that we require both sides to have the same type in
>> > std::swap and not in .swap(). If we want to emit an error, it's hard
>> > to do because of SFINAE (so generating an error there would simply
>> > discard the specialization.). I have to read back the rules of SFINAE,
>> > perhaps it will work to let our std::swap specialization call another
>> > function from where we trigger an error...
>> >
>> > Benoit
>>
>> Look how boost::swap works, there is a simple trick to have your own
>> eigen::swap that behaves correctly
>> without tricky SFINAE. Basically :
>>
>> namespace eigen {
>> namespace details
>> {
>> template<class T1,class T2>
>> void swap( T1& a, T2& b)
>> {
>> using std::swap;
>> swap(a,b);
>> }
>> }
>>
>> template<class T1,class T2>
>> void swap( T1& a, T2& b)
>> {
>> details::swap(a,b);
>> }
>>
>> }
>>
>> the main swap having *two* templates arguments make it more specialized
>> than the ADL found swap for type T1 and T2.
>> Then the using clause in the details::swap bring std::swap in the game
>> if and only if the proper swap can't be found by ADL.
>>
>> Using this swap then behaves like that:
>> if a swap exists in the namespace of T1, it is used.
>> else std::swap is used silently.
>>
>> Now, just tell user to use eigen::swap.
>>
>> Reference here:
>>
>> http://www.boost.org/doc/libs/1_42_0/boost/utility/swap.hpp
>
>
>
>