November 29, 2012
Hi!
It would useful for some my project,if operators could be a template,that "return"
type.Something like

alias TypeTuple!(int,char) types;

static assert(types[1] == char) //opIndex

So can I define something like that?
November 29, 2012
Zhenya:

> It would useful for some my project,if operators could be a template,that "return"
> type.

D operators are functions, and D functions return values. And in D types are not values (unlike Python and several other languages), unless you use a Typeinfo or something.

Maybe if you explain better what you are trying to do someone will be able to suggest you an alternative solution. D is not as flexible as Lisp, but it doesn't lack meta-programming/type-processing capabilities.

Bye,
bearophile
November 29, 2012
On 2012-11-29, 17:33, Zhenya wrote:

> Hi!
> It would useful for some my project,if operators could be a template,that "return"
> type.Something like
>
> alias TypeTuple!(int,char) types;
>
> static assert(types[1] == char) //opIndex
>
> So can I define something like that?

This works out of the box. If you want to define your own
TypeTuple-like construct, the answer is most likely going to be no.

-- 
Simen
November 29, 2012
On Thursday, 29 November 2012 at 16:55:01 UTC, bearophile wrote:
> Zhenya:
>
>> It would useful for some my project,if operators could be a template,that "return"
>> type.
>
> D operators are functions, and D functions return values. And in D types are not values (unlike Python and several other languages), unless you use a Typeinfo or something.
>
> Maybe if you explain better what you are trying to do someone will be able to suggest you an alternative solution. D is not as flexible as Lisp, but it doesn't lack meta-programming/type-processing capabilities.
>
> Bye,
> bearophile

Of course I understand,that type is not value in D.I meant that maybe we can declare non-function template operators.For example:

struct MyIntType
{
alias int type;
template opSlice()
{
alias type opSlice;
}
November 29, 2012
Zhenya:

> For example:
>
> struct MyIntType
> {
> alias int type;
> template opSlice()
> {
> alias type opSlice;
> }

As you guess, this is not supported in D.

Bye,
bearophile
November 29, 2012
On Thursday, 29 November 2012 at 21:53:20 UTC, bearophile wrote:
> Zhenya:
>
>> For example:
>>
>> struct MyIntType
>> {
>> alias int type;
>> template opSlice()
>> {
>> alias type opSlice;
>> }
>
> As you guess, this is not supported in D.
>
> Bye,
> bearophile

Thank you,understood(
Top | Discussion index | About this forum | D home