digitalmars.D.learn - Overloading templates
- Sean Kelly (21/21) Sep 24 2008 I'm inclined to say this isn't possible, but just in case I'm wrong, can...
- Bill Baxter (3/23) Sep 24 2008 Before anyone tries to answer this --Are you still in D2 land?
- Sean Kelly (4/31) Sep 24 2008 I'd prefer something that works with D1 as well, but I'll take what I
- Bill Baxter (23/43) Sep 24 2008 This works in D1 and D2. Requires find!()("abc",'a') as calling
- Sean Kelly (4/50) Sep 25 2008 Weird, that works for me with D1 but not D2. I'm beginning to think tha...
- Sean Kelly (44/44) Sep 25 2008 Okay, it turns out that this works for me in D1 as well:
- Denis Koroskin (4/48) Sep 25 2008 Tango/D1 ought to be frozen and support dropped in favor of Tango/D2 at ...
- Sean Kelly (8/10) Sep 25 2008 Yeah, the issue for me now is finding a way to provide for a smooth tran...
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. Sean
Sep 24 2008
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.Before anyone tries to answer this --Are you still in D2 land? --bb
Sep 24 2008
Bill Baxter wrote:On Thu, Sep 25, 2008 at 10:09 AM, Sean Kelly <sean invisibleduck.org> wrote:I'd prefer something that works with D1 as well, but I'll take what I can get. SeanI'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.Before anyone tries to answer this --Are you still in D2 land?
Sep 24 2008
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
Sep 24 2008
== Quote from Bill Baxter (wbaxter gmail.com)'s articleOn Thu, Sep 25, 2008 at 10:09 AM, Sean Kelly <sean invisibleduck.org> wrote:Weird, that works for me with D1 but not D2. I'm beginning to think that my D2 installation is broken. SeanI'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' ); }
Sep 25 2008
Okay, it turns out that this works for me in D1 as well: template find(alias equals) { size_t find(Buf, Pat)( Buf buf, Pat pat ) { return 0; } } template find(char[] equals = "a == b") { size_t find(Buf, Pat)( Buf buf, Pat pat ) { return 0; } } void main() { find!()( "abc", 'a' ); // compiles in D1 find( "abc", 'a' ); // doesn't compile in D1 } However, it doesn't work in D2. There, basically the only syntax I can find that works is what's used in std.algorithm: size_t find(alias equals = "a == b", Buf, Pat)( Buf buf, Pat pat ) { return 0; } void main() { bool equals(char a, char b) { return a == b; } find( "abc", 'a' ); find!("a == b")( "abc", 'a' ); find!(equals)( "abc", 'a' ); } This is really ideal, but the fact that I can't find any common syntax for D1 and D2 is not. D1 doesn't allow aliasing strings but does seem to support some degree of overloading (even if doing so requires supplying an empty template parameter list), while D2 does allow aliasing strings but I can't get even that shoddy form of overloading to work. I was really hoping to find some way to allow tango.core.Array to use both its current delegate syntax and the new string syntax, but as it stands I don't think this is possible if the code must be portable between D1 and D2. Sean
Sep 25 2008
On Thu, 25 Sep 2008 22:12:16 +0400, Sean Kelly <sean invisibleduck.org> wrote:Okay, it turns out that this works for me in D1 as well: template find(alias equals) { size_t find(Buf, Pat)( Buf buf, Pat pat ) { return 0; } } template find(char[] equals = "a == b") { size_t find(Buf, Pat)( Buf buf, Pat pat ) { return 0; } } void main() { find!()( "abc", 'a' ); // compiles in D1 find( "abc", 'a' ); // doesn't compile in D1 } However, it doesn't work in D2. There, basically the only syntax I can find that works is what's used in std.algorithm: size_t find(alias equals = "a == b", Buf, Pat)( Buf buf, Pat pat ) { return 0; } void main() { bool equals(char a, char b) { return a == b; } find( "abc", 'a' ); find!("a == b")( "abc", 'a' ); find!(equals)( "abc", 'a' ); } This is really ideal, but the fact that I can't find any common syntax for D1 and D2 is not. D1 doesn't allow aliasing strings but does seem to support some degree of overloading (even if doing so requires supplying an empty template parameter list), while D2 does allow aliasing strings but I can't get even that shoddy form of overloading to work. I was really hoping to find some way to allow tango.core.Array to use both its current delegate syntax and the new string syntax, but as it stands I don't think this is possible if the code must be portable between D1 and D2. SeanTango/D1 ought to be frozen and support dropped in favor of Tango/D2 at some point, but it is far from now, I think.
Sep 25 2008
== Quote from Denis Koroskin (2korden gmail.com)'s articleTango/D1 ought to be frozen and support dropped in favor of Tango/D2 at some point, but it is far from now, I think.Yeah, the issue for me now is finding a way to provide for a smooth transition. I'd love to start using some of the more advanced compile-time features, but I've been running into quirks that foils nearly all of these attempts, as this example suggests. I'm coming to the conclusion that users of D1 should really just stick to the basics and worry about making things "D2-like" once they're no longer using D1. Sean
Sep 25 2008