Skip to content
This repository has been archived by the owner on Apr 4, 2022. It is now read-only.

Multi types #12

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Multi types #12

wants to merge 3 commits into from

Conversation

rouzier
Copy link

@rouzier rouzier commented Jun 5, 2017

Allow 26 different type aliases to be used.

This support the old positional alias syntax

./gengen -o ./btree github.com/joeshaw/gengen/examples/btree string string

Mix of named aliases and positional alias

./gengen -o ./btree github.com/joeshaw/gengen/examples/btree U=string string
./gengen -o ./btree github.com/joeshaw/gengen/examples/btree string U=string

Just aliases

./gengen -o ./btree github.com/joeshaw/gengen/examples/btree T=string U=string

@joeshaw
Copy link
Owner

joeshaw commented Jun 29, 2017

Nice! This is great, thanks for the patch.

I think one nice enhancement might be to not require that the type being replaced be in the generic package, so that a user could use whatever type they wanted. It'd remove the compile-time dependency on gengen and potentially allow people to use richer interfaces than use interface{} as the base generic type. It'd also have the benefit of not needing to define types generic.{A-S,W-Z}. What do you think?

@rouzier
Copy link
Author

rouzier commented Jul 5, 2017

That is a good idea.

Are you thinking something like this?

Before

type T string
type U interface{}

type Map interface {
  Insert(T, U) bool
  Delete(T) bool
}
./gengen -o ./map github.com/rouzier/map/map T=string U=int
or
./gengen -o ./map github.com/rouzier/map/map string int

After

type Map interface {
  Insert(string, int) bool
  Delete(string) bool
}

@joeshaw
Copy link
Owner

joeshaw commented Jul 5, 2017

Yeah, although it'd be nice to still reference other packages. So that you could still do ./gengen -o ./map github.com/rouzier/map/map generic.T=string generic.U=int but maybe that's not that important.

I think the "naked" case does need to reference the generic.T etc. types for backward compatibility, though.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants