This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: template problems


> 
> Key Value::key_method()
> 
> if is there and if not, via a global non-member function
> 
> Key key_function(Value)
> 

I understand your idea, but I am not sure whether it can be done with
the templates (I don't know). Simply create a key class and do the
lookup there while inserting;

make_pair( ket_class(data), data )

Maybe such a thing requires the key to be generated before the
insertion.

But better, it really sounds like the set class is more suitable for
your purpose, something like this;

class foo;	// so you have class of data

struct _aux_data_compare
{
    bool operator () (const foo &_x, const foo &_y)
    {
	return ( _x < _y ); // <==== you define this comparison!!!
    }
};

set <foo, _aux_data_compare> my_set;

HTH,
Gokhan


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]