Thread overview
container class sample on Tango mainpage can not compile
Jan 05, 2009
Sam Hu
Jan 08, 2009
Sam Hu
Jan 10, 2009
Moritz Warning
Jan 12, 2009
Sam Hu
Jan 12, 2009
Sam Hu
January 05, 2009
Hi,
The sample of Tango container class,Comparators section:
http://www.dsource.org/projects/tango/wiki/ChapterStorage#Comparators
can not compile.I just don't know why.Please help on this.
//dcomp.d
module dcomp;

import tango.util.collection.TreeBag;
import tango.io.Stdout;
import tango.text.Ascii;
import tango.util.collection.model.Comparator;

void testComparator()
{

	auto nameSet=new TreeBag!(char[])(null,new class() Comparator!(char[])
	{
		int compare(char[] first,char[] second)
		{
			return Ascii.icompare(first,second);
		}
	});
	nameSet.addIf("Alice");
	nameSet.addIf("Bob");
	nameSet.addIf("AliCe");
	nameSet.addIf("BoB");
	nameSet.addIf("Alicf");
	nameSet.addIf("BoC");


	foreach(str;nameSet)
		Stdout.formatln("{}",str);
}

int main(char[][] args)
{
	testComparator;
	return 0;
}
//end
compile error message:
D:\Laguage\Dex>dsss build dcomp.d
dcomp.d => dcomp
+ c:\bigd\dsss\bin\rebuild.exe -Idsss_imports\ -I. -S.\ -Ic:\bigd\dsss\include\d
 -Sc:\bigd\dsss\lib\  -Ic:\bigd\dsss\include\d -Sc:\bigd\dsss\lib  -oqdsss_objs\
D  dcomp.d -ofdcomp
dcomp.d(11): class dcomp.testComparator.__anonclass6 base type must be class or
interface, not int delegate(char[], char[])
dcomp.d(11): constructor tango.util.collection.TreeBag.TreeBag!(char[]).TreeBag.
this () does not match parameter types (void*,__anonclass6)
dcomp.d(11): class tango.util.collection.TreeBag.TreeBag!(char[]).TreeBag member
 this is not accessible
dcomp.d(11): Error: cannot implicitly convert expression ((class __anonclass6 :
Object
{
    int compare(char[] first, char[] second)
{
return Ascii.icompare(first,second);
}
    void* this;
}
) , new __anonclass6) of type dcomp.testComparator.__anonclass6 to int delegate(
char[], char[])
dcomp.d(11): Error: expected 4 arguments, not 2
Command c:\bigd\dsss\bin\rebuild.exe returned with code 1, aborting.
Error: Command failed, aborting.

January 08, 2009
Morning,

Anybody can help?

Regards,
Sam
January 10, 2009
On Wed, 07 Jan 2009 19:47:57 -0500, Sam Hu wrote:

> Morning,
> 
> Anybody can help?
> 
> Regards,
> Sam

try this:

auto nameSet=new TreeBag!(char[])(null, (char[] first,char[] second) {
		return icompare(first,second);
	}
);

btw: tango.collection.* is deprecated and will be replaced by tango.container.*, so you might want to use these.
January 12, 2009
Moritz Warning Wrote:

> On Wed, 07 Jan 2009 19:47:57 -0500, Sam Hu wrote:
> 
> > Morning,
> > 
> > Anybody can help?
> > 
> > Regards,
> > Sam
> 
> try this:
> 
> auto nameSet=new TreeBag!(char[])(null, (char[] first,char[] second) {

> 		return icompare(first,second);

> 	}

> );
> 
> btw: tango.collection.* is deprecated and will be replaced by tango.container.*, so you might want to use these.

Thanks so much!!!It works now.
> btw: tango.collection.* is deprecated and will be replaced by tango.container.*, so you might want to use these.

So where can I find another addIf method in the container class or should I implement by myself?

Regards,
Sam
January 12, 2009
Moritz Warning Wrote:

> On Wed, 07 Jan 2009 19:47:57 -0500, Sam Hu wrote:
> 
> > Morning,
> > 
> > Anybody can help?
> > 
> > Regards,
> > Sam
> 
> try this:
> 
> auto nameSet=new TreeBag!(char[])(null, (char[] first,char[] second) {

> 		return icompare(first,second);

> 	}

> );
> 
> btw: tango.collection.* is deprecated and will be replaced by tango.container.*, so you might want to use these.

Thanks so much!!!It works now.
> btw: tango.collection.* is deprecated and will be replaced by tango.container.*, so you might want to use these.

So where can I find another addIf method in the container class or should I implement by myself?

Regards,
Sam