[GiNaC-list] Maps and sets of symbols?
Sheplyakov Alexei
varg at theor.jinr.ru
Wed Sep 14 19:02:27 CEST 2005
On Thu, Sep 15, 2005 at 01:08:45AM +1000, John Pye wrote:
> I _really_ wanted to use
>
> std::map<symbol, symbol>
>
> What's a better idea then?
You can define ordering as
struct symbol_is_less
{
inline const bool operator()(const symbol& a, const symbol& b)
{
return ex_is_less()(a, b);
}
};
and use
std::map<symbol, symbol, symbol_is_less>
Here is a simple example:
#include <iostream>
#include <iterator>
#include <map>
#include <ginac/ginac.h>
using namespace std;
using namespace GiNaC;
struct symbol_is_less
{
inline const bool operator()(const symbol& x, const symbol& y)
{
return ex_is_less()(x, y);
}
};
typedef map<symbol, symbol, symbol_is_less> ssmap;
int main(int argc, char** argv)
{
symbol x("x");
symbol y("y");
symbol z("z");
symbol t("t");
ssmap foo;
foo[x] = z;
foo[y] = t;
for (ssmap::const_iterator i=foo.begin(); i!=foo.end(); ++i)
cout << i->first << " ==> " << i->second << endl;
return 0;
}
Is this good enough for your purpose?
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: 189 bytes
Desc: Digital signature
Url : http://www.cebix.net/pipermail/ginac-list/attachments/20050914/71fc5eb6/attachment.pgp
More information about the GiNaC-list
mailing list