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] |
struct A
{
int a;
double b;
string c;
};
ostream & operator << (ostream & out, struct A const
& op)
{
return out << "{" << op.a << ", " <<
op.b << ", " << op.c << "}";
}
namespace std
{
template <typename T, typename U> struct column_equal;
template <typename T, typename U> binder2nd< column_equal<T,
U> > column_match(U T::* const, U const &);
template <typename T, typename U> struct column_operand
{
friend struct column_equal<T, U>;
friend binder2nd< column_equal<T, U> >
column_match<>(U T::* const, U const &);
U T::* column;
U const & value;
column_operand(U T::* a_column, U const &
a_value):column(a_column), value(a_value) {}
};
template <typename T, typename U> struct column_equal
: public binary_function<T, column_operand<T, U>, bool>
{
bool operator () (T const & a_line, class
column_operand<T, U> const & a_operand) const { return a_line.*a_operand.column
== a_operand.value; }
};
template <typename T, typename U> binder2nd< column_equal<T,
U> > column_match(U T::* const a_column, U const & a_value)
{
return binder2nd< column_equal<T, U> >(column_equal<T,
U>(), class column_operand<T, U>(a_column, a_value));
}
}
int main()
{
using namespace std;
class list<A> table;
table.push_back((class A) {1, 0, "qwerty"
});
table.push_back((class A) {0, 10, "sdsdsd" });
table.push_back((class A) {100, 0, "sd" });
table.push_back((class A) {100, 21, "Hello"});
cout << * find_if(table.begin(), table.end(), column_match(&
A::a, 1)) << endl;
cout << * find_if(table.begin(), table.end(), column_match(&
A::b, 21.0)) << endl;
cout << * find_if(table.begin(), table.end(), column_match(&
A::c, string("sdsdsd") )) << endl;
}
Produces:
listlookup.cpp:40: common_type called with uncommon member types
(compiler error)
Under:
Reading specs from /usr/lib/gcc-lib/i386-linux/2.95.2/specs
gcc version 2.95.2 20000220 (Debian GNU/Linux)
If I remove the friends declarations in struct column_operand, everything works fine. Maybe the syntax is not right.
Thanks.
begin:vcard n:Bouchard;Philippe x-mozilla-html:FALSE org:Corel Linux adr:;;;;;; version:2.1 email;internet:philippeb@corel.com title:Software Engineer x-mozilla-cpt:;0 fn:Philippe Bouchard end:vcard
| Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
|---|---|---|
| Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |