Overloading templates

Sean Kelly sean at invisibleduck.org
Thu Sep 25 10:40:04 PDT 2008


== Quote from Bill Baxter (wbaxter at gmail.com)'s article
> On Thu, Sep 25, 2008 at 10:09 AM, Sean Kelly <sean at invisibleduck.org> wrote:
> > I'm inclined to say this isn't possible, but just in case I'm wrong, can someone
> > tell me how to make this code work:
> >
> >    size_t find(Buf, Pat)( Buf buf, Pat pat )
> >    {
> >        return 0;
> >    }
> >
> >    template find( char[] exp )
> >    {
> >        size_t find(Buf, Pat)( Buf buf, Pat pat )
> >        {
> >            return 0;
> >        }
> >    }
> >
> >    void main()
> >    {
> >        find( "abc", 'a' );
> >        find!("a == b")( "abc", 'a' );
> >    }
> >
> > Basically, I want a template function to overload with another template
> > function that I can partially specialize.
> This works in D1 and D2.  Requires find!()("abc",'a') as calling
> syntax, though.  That's the closest I was able to come up with.
> template find()
> {
>     size_t find(Buf, Pat)( Buf buf, Pat pat )
>     {
>         return 0;
>     }
> }
> template find( string exp )
> {
>     size_t find(Buf, Pat)( Buf buf, Pat pat )
>     {
>         return 0;
>     }
> }
> void main()
> {
>     find!()( "abc", 'a' );
>     find!("a==b")( "abc", 'a' );
> }

Weird, that works for me with D1 but not D2.  I'm beginning to think that
my D2 installation is broken.


Sean


More information about the Digitalmars-d-learn mailing list