[GiNaC-list] extending the symbol

Alexei Sheplyakov varg at theor.jinr.ru
Mon Oct 6 07:55:00 CEST 2008


Hello,

On Sat, Oct 04, 2008 at 09:58:25PM -0400, Krishna Mohan Gundu wrote:

> > Is there a better way to test if a symbol is a vector?

1. I don't think subclassing symbol is a good idea.
2. `vector' is a bad name (because there is std::vector)
3. What's wrong with schoolbook method:

typeid(blah) == typeid(YourVector)

> class symbol_base : class basic
> {
>    ...
>    symbol_base(const std::string & initname, type_info* ti);
>    ...
>    type_info const& get_domain_type() const
>    {
>       return *pti;
>    }
>    ...
> private:
>    type_info const* pti;

symbol is a bit performance (and memory) critical. Adding yet another
8 bytes is not appreciated at all.

> Now things like
>    is_domain_a<real_domain>(e)
>    is_domain_a<vector_domain>(e)
> makes sense.

What's wrong with

typeid(e) == typeid(vector_symbol)

> as friend cannot be a template.

Sure it can. See the example code in the paragraph 14.5.3.1 of the standard,
and this silly program:

$ cat test.cc

template<typename T> class A;
template<typename T> class B;

template<typename T> class A
{
	T i;
	template<typename T1> friend class B;
	public:
	A() : i(0) { }
	A(const T& i_) : i(i_) { }
};

template<typename T> class B
{
	T j;
	public:
	B() : j(0) { }
	B(const T& j_) : j(j_) { }
	template<typename T1> B& operator=(const A<T1>& a)
	{
		j = T(a.i);
		return *this;
	}
	T get_j() const
	{
		return j;
	}
};

int main()
{
	A<int> a(0);
	B<long> b(-1);
	b = a;
	return b.get_j();
}

$ g++ -Wall test.cc
$ ./a.out
$ echo $?
0


> Let me know if you think of any simpler alternatives.

Use already existing code (i.e. clifford class), add whatever functionality
you need. Don't hesitate to ask questions if something goes wrong and/or
you don't understand something, etc.

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/20081006/b2a1a174/attachment.sig 


More information about the GiNaC-list mailing list