Skip to content

Adding staticIota to typetuple.d#1440

Closed
monarchdodra wants to merge 6 commits intodlang:masterfrom
monarchdodra:Iota
Closed

Adding staticIota to typetuple.d#1440
monarchdodra wants to merge 6 commits intodlang:masterfrom
monarchdodra:Iota

Conversation

@monarchdodra
Copy link
Collaborator

First attempt for a static Iota.

http://d.puremagic.com/issues/show_bug.cgi?id=4085

std/typetuple.d Outdated
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are all of these parameters aliases instead of integrals?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To accept floats, or chars. For typed output if you want ubyte/int/ulong.

@denis-sh
Copy link
Contributor

You do no follow name convention. The name must be lowercased. staticIota, iotaTuple etc.
I also suggest to use my code from iotaTuple at least as base point as currently you type inference is incorrect.

@denis-sh
Copy link
Contributor

And yes, thanks.

@monarchdodra
Copy link
Collaborator Author

You do no follow name convention. The name must be lowercased. staticIota, iotaTuple etc.

I'm unsure... Iota (as it has been named), returns a type, so the convention is CamelCase...? In particular, it returns a TypeTyple. I think you said that TypeTuple is wrongly named? But at this point, I think it is better to stick to existing convention.

I also suggest to use my code from iotaTuple at least as base point as currently you type inference is incorrect.

Thanks a lot. Very smart. I shamelessly copied most of it.

BTW, mine handles Iota('a', 'g') ^^.

@denis-sh
Copy link
Contributor

I'm unsure... Iota (as it has been named), returns a type, so the convention is CamelCase...? In particular, it returns a TypeTyple. I think you said that TypeTuple is wrongly named? But at this point, I think it is better to stick to existing convention.

You are confused by TypeTuple name. The template defines generic tuple. Particualry, it can be type tuple or expression tuple (see std.traits.isExpressionTuple and std.traits.isTypeTuple docs). In your case it is expression tuple. So I strongly recommend to at least look at my unstd.generictuple sourses.

BTW, mine handles Iota('a', 'g') ^^.

Never tought about such application. )


@andralex, what about finally introduce undocumented GenericTuple and expressionTuple templates just for internal use in Phobos to stop confusing developers?

@monarchdodra
Copy link
Collaborator Author

Allright. staticIota is correct I think. I'll change it. There's also already a private staticIota in typecons I need to get rid of.

@monarchdodra
Copy link
Collaborator Author

Done. It is now called staticIota. It now also checks the types are scalar. I reused the implementation from std.typecons, which has logarithmic depth now, but I fixed some of its bugs ;)

@monarchdodra
Copy link
Collaborator Author

Rebased. Any further input?

@dnadlinger
Copy link
Contributor

Sorry for not seeing this earlier (I'm pretty much out of the loop until end of August), but I'm not sure whether it makes sense to start duplicating all kinds of functionality that already exists as (at least in principle) CTFE-able runtime function‚ just to have it yield a compile-time tuple instead of a range/array.

Wouldn't it make much more sense to offer something like toExpressionTuple!(iota(a, b)) that could be used for other kinds of array/ranges as well?

There might be compiler performance implications to consider, but in general I think keeping things orthogonal is the way to go.

@monarchdodra
Copy link
Collaborator Author

Hum... toExpressionTuple... that's a good idea actually. I'll investigate, but I'm not actually sure where to start :)

@monarchdodra
Copy link
Collaborator Author

I'll investigate, but I'm not actually sure where to start :)

I got it to work. It's actually trivially easy (easier than writing static iota as a matter of fact...) Excellent idea in any case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants