Compilation depends on class methods order
Jacob Carlborg
doob at me.com
Thu Dec 19 23:47:48 PST 2013
On 2013-12-20 08:03, kdmult wrote:
> Hi,
>
> Why compilation depends on order of method declarations?
>
> The following test case does not compile.
>
> However, if we change the order of the 'read' methods in class
> InputStream below then compilation will not fail.
>
> Is it a bug?
>
> ---
> module test;
>
> import std.traits : isBasicType;
> import std.typetuple : TypeTuple;
>
> class InputStream {
>
> long read( ubyte* bytes, long len )
> {
> return 0;
> }
>
> void read(T)( ref T val ) if (isBasicType!T)
> {
> read(cast(ubyte*)&val, cast(long)val.sizeof);
> }
>
> }
>
> void main()
> {
> auto input = new InputStream;
>
> foreach (T; TypeTuple!(long, int, short, byte))
> {
> T v;
> input.read(v);
> }
> }
> ---
I'm wondering if that's because the first "read" isn't a template
function. You cannot overload a standard function with a template
function, or has that been fixed?
If that's not the problem it's probably the template constraint. I have
had some problems with that and the "solution" I end up using was to add
the same template constraint to the other function but negate the condition.
--
/Jacob Carlborg
More information about the Digitalmars-d-learn
mailing list