December 04, 2007
On Tue, 04 Dec 2007 11:18:56 +0900, Bill Baxter wrote:

> You'll have to make it. A little static if template like
> 
> template Ret(T) {
>     static if (is(T==Currency)) { alias real Ret; }
>     else { alias Currency Ret; }
> }

I almost go it right. Yes this works. There has got to be a better way!

-- 
Derek
(skype: derek.j.parnell)
Melbourne, Australia
4/12/2007 2:04:43 PM
December 04, 2007
Derek Parnell wrote:
> On Tue, 04 Dec 2007 11:23:18 +0900, Bill Baxter wrote:
> 
>> I think in D2 you should be able to use typeof(return) to remove the need for the extra helper template, Ret.
>> Totally untried though.
>>
>> // ------------------------
>> typeof(return) opDiv(T)(T pFactor)
>> // ------------------------
>> {
>>   static if(is(T == Currency))
>>     return  mData / pFactor.mData;
>>   else
>>     return  this.mData / pFactor;
>> }
>>
>> --bb
> 
> Nope. "typeof(return) must be inside a function"
> 

Dang.  I had high hopes for that new feature to clean things up.

--bb
December 04, 2007

Derek Parnell wrote:
> On Tue, 04 Dec 2007 11:18:56 +0900, Bill Baxter wrote:
> 
>> You'll have to make it. A little static if template like
>>
>> template Ret(T) {
>>     static if (is(T==Currency)) { alias real Ret; }
>>     else { alias Currency Ret; }
>> }
> 
> I almost go it right. Yes this works. There has got to be a better way!

You think that's bad; try doing it for a matrix library where the return type depends on the input types which contain a mix of scalars, vectors, matrices and transforms (special matrices which have an implicit final row.)

Hopefully the promised overloading upgrades will help with this.

	-- Daniel
December 04, 2007
Daniel Keep wrote:
> 
> Derek Parnell wrote:
>> On Tue, 04 Dec 2007 11:18:56 +0900, Bill Baxter wrote:
>>
>>> You'll have to make it. A little static if template like
>>>
>>> template Ret(T) {
>>>     static if (is(T==Currency)) { alias real Ret; }
>>>     else { alias Currency Ret; }
>>> }
>> I almost go it right. Yes this works. There has got to be a better way!
> 
> You think that's bad; try doing it for a matrix library where the return
> type depends on the input types which contain a mix of scalars, vectors,
> matrices and transforms (special matrices which have an implicit final row.)
> 
> Hopefully the promised overloading upgrades will help with this.
> 
> 	-- Daniel

Here's my take:
http://www.dsource.org/projects/openmeshd/browser/trunk/OpenMeshD/OpenMesh/Core/Geometry/MatrixT.d

Look for "MultReturnType".  :-)

I could try to make it more generic but just getting it to work with a specific vector type and matrix type was annoying enough for me.

--bb
December 04, 2007
Reply to Derek,

> On Tue, 4 Dec 2007 00:57:59 +0000 (UTC), BCS wrote:
> 
>> you can't have a template and non-template by the same name
>> 
> Yeah, I guess so. But why?
> 
>> here is the nasty solution, ther might be a better one, but this
>> should work.
>> 
>> // ------------------------
>> Ret!(T) opDiv(T)(T pFactor)
>> // ------------------------
>> {
>> Ret!(T) temp;
> Ummm ... what is 'Ret!' and where can it be found?
> 

sorry, I forgot that part, but Bill got it spot on.


December 04, 2007
Reply to Daniel,

> Derek Parnell wrote:
> 
>> On Tue, 04 Dec 2007 11:18:56 +0900, Bill Baxter wrote:
>> 
>>> You'll have to make it. A little static if template like
>>> 
>>> template Ret(T) {
>>> static if (is(T==Currency)) { alias real Ret; }
>>> else { alias Currency Ret; }
>>> }
>> I almost go it right. Yes this works. There has got to be a better
>> way!
>> 
> You think that's bad; try doing it for a matrix library where the
> return type depends on the input types which contain a mix of scalars,
> vectors, matrices and transforms (special matrices which have an
> implicit final row.)
> 
> Hopefully the promised overloading upgrades will help with this.
> 
> -- Daniel
> 

this would be a nice place to have auto:


auto Fn(A, B, C)(A a, B b, C c)
{
/// lots-o-logic

  return ret; // return type defined here.
}


December 04, 2007
BCS wrote:
> Reply to Daniel,
> 
>> Derek Parnell wrote:
>>
>>> On Tue, 04 Dec 2007 11:18:56 +0900, Bill Baxter wrote:
>>>
>>>> You'll have to make it. A little static if template like
>>>>
>>>> template Ret(T) {
>>>> static if (is(T==Currency)) { alias real Ret; }
>>>> else { alias Currency Ret; }
>>>> }
>>> I almost go it right. Yes this works. There has got to be a better
>>> way!
>>>
>> You think that's bad; try doing it for a matrix library where the
>> return type depends on the input types which contain a mix of scalars,
>> vectors, matrices and transforms (special matrices which have an
>> implicit final row.)
>>
>> Hopefully the promised overloading upgrades will help with this.
>>
>> -- Daniel
>>
> 
> this would be a nice place to have auto:
> 
> 
> auto Fn(A, B, C)(A a, B b, C c)
> {
> /// lots-o-logic
> 
>   return ret; // return type defined here.
> }

Yeh, that does look more in line with D than sticking a typeof(return) out front.

--bb
1 2
Next ›   Last »