Q about template for matching arrays
Bill Baxter
dnewsgroup at billbaxter.com
Wed Jan 31 23:55:44 PST 2007
I'd like to write a template function something like:
T foo(T,S)(S x)
that takes arrays of various kinds and returns an element of the base
type (well really something derived from the base type, but that part's
easy).
The trick is that what I'd really like is for it be able to be used in
all of the following ways:
// IFTI
foo(3) // T=int S=int
foo([3]) // T=int S=int[]
foo([[3]]) // T=int S=int[][]
foo([[[3]]]) // T=int S=int[][][]
... etc
// Base type explicit
foo!(float)(3) // T=float S=float
foo!(float)([3]) // T=float S=float[]
foo!(float)([[3]]) // T=float S=float[][]
... etc
It's easy if you say you have to call it like foo!(float[][])([[3]]),
but that's annoying.
Any bright ideas?
--bb
More information about the Digitalmars-d-learn
mailing list