std.typecons wrap interface with NVI

Matthew Dudley pontifechs at gmail.com
Sat Feb 1 17:19:21 PST 2014


This is the general outline of what I'm trying to do:



import std.typecons; //wrap

import std.stdio;


interface FooBar
{
public:
	void foo();
	void bar();

	final void both() // NVI
		{
			foo();
			bar();
		}
}

class Baz
{
public:
	void foo() { writeln("foo"); }
	void bar() { writeln("bar"); }
}

void main()
{
	auto baz = new Baz();
	auto foobar = baz.wrap!(FooBar)();
	// causes this wall-o-text error -- http://pastebin.com/Pa5dHQtN
	// Which at the end says:

	// /usr/local/Cellar/dmd/2.064.2/import/std/typecons.d(2779): 
Error: static assert  "Source Baz does not have structural 
conformance to (FooBar)"

}


I'm still learning D, but this seems like it should work. If I 
explicitly implement FooBar in Baz, everything's groovy, but this 
isn't. Is this a bug in wrap or am I misunderstanding the 
intention of wrap or NVI?

Also as a side note, if I use an abstract class instead of an 
interface, things explode in similarly large wall-o-text fashion. 
Is there a reason for abstract classes aren't or can't be used 
for wrap?



More information about the Digitalmars-d-learn mailing list