[GiNaC-list] list of list

Sheplyakov Alexei varg at theor.jinr.ru
Sun Feb 4 09:29:33 CET 2007


Hello,

On Sun, Feb 04, 2007 at 02:19:42AM +0800, Jerome BENOIT wrote:
> I have just noticed that:
> 
> lst list;
> list = lst(lst(1,1),lst(2,4),lst(3,9));
> 
> gives a list of list as expected,
> whereas
> 
> lst list;
> list = lst(1,1),lst(2,4),lst(3,9);

Probably you want this:

list = ex(lst(1, 1)), lst(2, 4), lst(3,9);
 
> gives the first list (namely lst(1,1))

Not exactly, your code gives lst(1, 1) as opposed to lst(lst(1, 1)).

> is it a bug ?

No. This is how C++ function overload resolution works. There are several
overloaded instances of operator= in the lst class:

lst& operator=(const lst&);
container_init<ex, std::list> operator=(const ex&);

First one gives the best match (no type conversion form lst
to ex is necessary), so your code basically reads as:

class foo {
	int i;
	public:
	foo();
	foo(int i_);
	foo& operator=(const foo& o);
};

void demo() {
	// lst list;
	foo a; 
	// list = lst(1, 1), lst(2, 4), lst(3, 9);
	a = foo(1), foo(2), foo(3);
}

foo::foo() { i = 0; }
foo::foo(int i_) { i = i_; }
foo& foo::operator=(const foo& o) {
	if (&o != this)
		i = o.i;
	return *this;
}

> or is it a wrong thing to do ? 

There is nothing wrong about list of lists. But the code operating on
such lists will be [probably] somewhat inefficient.

Best regards,
 Alexei

-- 
All science is either physics or stamp collecting.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 827 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/ginac-list/attachments/20070204/d12b048f/attachment.pgp


More information about the GiNaC-list mailing list