|Re: [eigen] a few updates...|
[ Thread Index |
| More lists.tuxfamily.org/eigen Archives
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] a few updates...
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Wed, 22 Dec 2010 18:33:04 +0000
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:content-type :content-transfer-encoding; bh=4DjeWlVbFUK2Q6usN3rc4ikQPMcGsl4iy03M5p5YzD4=; b=hXIKcDQLt8dRXZLjlTls/S/nQcywrzi7+c3D+ro3/QPsxPxYgSl15upTyOUZdQqmyT VHvnUjxjH3b0Jg+nCxlrd2krL8Hki2yXDdfwAaTAFSDxT2UAv+B2fjrWx0kfeApUXeKT 2wj/RwsBUwXzfC7dKfZa+IwqX6YXqF+psVZuI=
- 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=kX7vL/0G68JYLfTYMugKK9ficXq3keEOQmt1/tvF2+X1ODJm1QsVyLlTXcdaCC7LOb O4TDNUR+ecYTonr/Bgt4qFIrmgrJg4l7vnW+/bvfLiGLjgwjTZX9ZwI98D7sH61ACzlJ 4c5m48m/sFNDg3pa9T/De/Z9TqGBoqXLcThQ0=
2010/12/22 Christoph Hertzberg <chtz@xxxxxxxxxxxxxxxxxxxxxxxx>:
> On 22.12.2010 04:50, Benoit Jacob wrote:
>> * There are 2 remaining places where I haven't fixed
>> const-correctness: the Sparse module (leaving this to Gael) and
>> swap(). I have improved the situation with swap() so that e.g. you
>> can't swap const Matrix's anymore, but there remains a much trickier
>> issue: swapping temporary expression as in:
>> This is incredibly tricky because C++ doesn't allow one to take
>> non-const references to temporaries, so one has to pass const
>> references and const_cast, which loses the information of whether the
>> expression was const in the first place.
>> There are 2 things we can do here:
>> a) leave it there with c++98 and consider using rvalue references in c++0x mode
>> b) actually there is a crazy aspect of c++98 that allows to fix this
>> problem. As I said, the fundamental issue is that C++ doesn't allow
>> one to take non-const references to temporaries... but that's not
>> entirely true, there's one case in which this is allowed: that's when
>> taking a reference to *this. At least insofar as GCC's behavior is
>> compliant with the spec. So, while the API we have for swap() can't be
>> fixed wrt const-correctness within c++98, this different API:
>> xpr1.swap() = xpr2.swap()
>> can be made const-correct, by implementing swap() as returning a
>> SwapWrapper<T>, and implementing swap() const as returning a
>> SwapWrapper<const T>.
> Seriously this looks a bit ugly ...
> Why would you need a SwapWrapper<const T> anyways?
Sorry, you're right, so what I should have written is: only implement
non-const-qualified swap() method, so that calling it on a const
object fails to compile, while still being possible to call it on a
> Another possibility would be:
> c) Pass argument to swap() by value if it is a Map/Block-expression.
I tried that, using a enable-if trick to select abstract expressions
vs. plain objects.
The problem is that that doesn't solve the problem at all. By passing
the expression by value, we completely forget its constness, so we
can't prevent doing
const Expression xpr;
> This should never be more than a pointer and a few integers and would
> hopefully be optimized away in most cases.
> Maybe not with the current implementation, when passing sth such as:
> but that could be fixed when solving "direct access type unification".
> Ideally, if every dimension is known at compile-time, passing by value
> would then boil down to just passing a pointer to where the data starts.
> Dipl.-Inf. Christoph Hertzberg
> Cartesium 0.051
> Universität Bremen
> Enrique-Schmidt-Straße 5
> 28359 Bremen
> Tel: (+49) 421-218-64252