This is the mail archive of the gcc-bugs@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]

templates; ice


Hi

following code is illegal but crashes 19980604 sources anyway


#include <iostream.h>
#include <list.h>
#include <algorithm>
#include <string>

using namespace std;

struct employee
{
public:
	string	name;
	int	age;	
	
	employee(string name, int age):
		name(name),
		age(age)
	{
		
	}
};


template<class T, class M, M T::*member>
class mem_eq
{
private:
	M	value;

public:
	mem_eq(const M& xvalue):
		value(xvalue)
	{
		
	}
	
	bool operator()(T& t)
	{
		return t.*member == value;
	}
	
};


typedef mem_eq<employee, string, &employee::name> emp_name;
typedef mem_eq<employee, int, &employee::age> emp_age;


ostream& operator<<(ostream& ostr, const employee& cl)
{
	return ostr << "name=" << cl.name << " age=" << cl.age;
}


int
main()
{
	list<employee>	l;
	
	l.push_back(employee("john", 50));
	l.push_back(employee("niall", 21));
	l.push_back(employee("nero", 23));
	
	cerr << *find_if(l.begin(), l.end(), mem_eq(&employee::name, "niall")) << endl;
	cerr << *find_if(l.begin(), l.end(), mem_eq(&employee::ago, 23)) << endl;
}


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