[ Thread Index |
Date Index
| More lists.tuxfamily.org/eigen Archives
]
- To: eigen@xxxxxxxxxxxxxxxxxxx
- Subject: Re: [eigen] FFT update
- From: Benoit Jacob <jacob.benoit.1@xxxxxxxxx>
- Date: Sun, 24 Jan 2010 02:03:03 -0500
- 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:message-id:subject:from:to:content-type :content-transfer-encoding; bh=si4NEcoYNV7lLJpiF5BxXqTiSHjNI3SBitAFbMRrzWA=; b=deGDDog/vhDD9zDxzrkrm5CKT7PVwUoVVzl+Hfm+aGq2gAD3Qt9AkJ+9MJYlj+0Cda 6tYRGLY9/cUndmAF3/6AxxLWzjnk9n0da4gp75FrW2ABGkEEL3qyM14nDVFZm7ryHG6O Z7kbVYaja6fpVHPGW1OE/ugobWBr/63HEQU1I=
- 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=C/v825nuuOLg9VPbsZ7ySVNdE1rYiUw87U1mLTu9dnX8HF3qHCtPTY2ps355Jt19uq zPnIhvBGax3jwWD4lIqiFKVg7QwJHS3nkunWmKFxPlQznq4lETdEYDTMP1YrH6bQEMPS RZxaPvOsb2LSXVrPyxL6ErwdxpRlSPDZXxP2I=
2010/1/24 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
> 2010/1/23 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
>> By the way, this "ReturnByValue::coeff() crashes by infinite
>> recursion" thing is really ugly, I wonder how to fix it!!
>>
>> C++0x at last brings the ability to remove a base class function from
>> a derived class... I wonder how to implement that idea in C++98. Is
>> that enable_if?
>
> Forget enable_if, forget C++0x, forget boost, i'm your new idol.
>
> If we want to make sure that using ReturnByValue::coeff() generates an
> error at compile time without generating an error until it's actually
> used, we can define a class:
>
> class Unusable
> {
> // implement copy ctor/operator as private to disable them
> Unusable(const Unusable&) {}
> void operator=(const Unusable&) {}
> };
>
> We then let ReturnByValue::coeff() return that:
>
> class ReturnByValue
> {
> ...
> Unusable coeff(int, int) { return Unusable(); }
> ...
> };
>
> The result is that when the user does e.g.
> x = retval.coeff(i);
> or
> x = retval.coeff(i) + 123;
> he gets compilation errors.
>
> Just doing
> retval.coeff(i);
> doesn't give an error, but that should be optimizable as just a NOP anyway.
>
> With this, i go to bed full^Wproud of myself.
Ah, this needed a little adjustment. Doing
Unusable coeff(int, int) { return Unusable(); }
was already copying a Unusable object, the return value of that
method. While the trick still worked with GCC, it was probably
fragile, and the error wasn't very explicit.
Here is a much better variant:
const Unusable& coeff(int) const { return *reinterpret_cast<const
Unusable*>(this); }
Now this method is really not using any Unusable constructor/operator.
The error message when I do:
float x = rotate(v).coeff(0);
is now just:
returnbyvalue.cpp: In function ‘int main()’:
returnbyvalue.cpp:122: error: cannot convert ‘const
Eigen::Unusable’ to ‘float’ in initialization
ok to commit?
Benoit
>
> Benoit
>
>>
>> Benoit
>>
>> 2010/1/23 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
>>> Hi,
>>>
>>> Here's an example: see attached file.
>>> Enjoy!!
>>> Benoit
>>>
>>> 2010/1/22 Benoit Jacob <jacob.benoit.1@xxxxxxxxx>:
>>>> ok let me write an example...
>>>>
>>>> 2010/1/22 Jitse Niesen <jitse@xxxxxxxxxxxxxxxxx>:
>>>>> On Fri, 22 Jan 2010, Benoit Jacob wrote:
>>>>>
>>>>>> Our "policy" is now:
>>>>>> - try to return by value, optimizing with the ReturnByValue class,
>>>>>> wherever possible;
>>>>>> - otherwise you can just use references.
>>>>>
>>>>> Can somebody please explain how to use the ReturnByValue class?
>>>>> Or should I just extrapolate from the source code?
>>>>> I could not find any documentation.
>>>>>
>>>>> Jitse
>>>>>
>>>>>
>>>>>
>>>>
>>>
>>
>