Welcome to Web-News
A Web-based News Reader
Subject Re: Overloading templates
From Bill Baxter <wbaxter@gmail.com>
Date Thu, 25 Sep 2008 15:32:22 +0900
Newsgroups digitalmars.D.learn

On Thu, Sep 25, 2008 at 10:09 AM, Sean Kelly <sean@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' );
}

--bb

Recent messages in this thread
 
-# Overloading templates Sean Kelly 24-Sep-2008 09:09 pm
.-# Re: Overloading templates Bill Baxter 24-Sep-2008 09:33 pm
.|\# Re: Overloading templates Sean Kelly 24-Sep-2008 11:32 pm
.-# Re: Overloading templates (Current message) Bill Baxter 25-Sep-2008 02:32 am
..-# Re: Overloading templates Sean Kelly 25-Sep-2008 01:40 pm
...-# Re: Overloading templates Sean Kelly 25-Sep-2008 02:12 pm
....-# Re: Overloading templates Denis Koroskin 25-Sep-2008 05:01 pm
.....\# Re: Overloading templates Sean Kelly 25-Sep-2008 05:11 pm