Boost logo

Boost Users :

From: Dizzy (dizzy_at_[hidden])
Date: 2007-03-29 05:04:34


Hello

I have the following testcase:

#include <string>
#include <iostream>

#include <boost/lambda/lambda.hpp>
#include <boost/bind.hpp>
#include <boost/mem_fn.hpp>

struct A
{
        std::string s1, s2, s3;

        A(std::string const& s1_, std::string const& s2_, std::string const& s3_)
        :s1(s1_), s2(s2_), s3(s3_) {}
};

void eval(bool val) {
        std::cout << "result: " << val << std::endl;
}

int main()
{
        using boost::bind;
        using boost::mem_fn;

        A a1("str1", "str2", "str3");
        A a2("str2", "str1", "str3");

        eval(((bind(&A::s1, _1) < bind(&A::s1, _2)) && (bind(&A::s2, _1) <
bind(&A::s2, _2)))(a1, a2));
}

This errors compiling about operator&& no match found. I am trying to write a
binary predicate (for a sort type algorithm) that should lexicographically
compare the s1 field of the first argument with the corresponding one in the
second argument, then compare the s2 fields similary (in this order).

It does seem to work for the simpler case of just one "<" operation but
doesn't seem to work when using "&&" on the results of "<". I was hoping
there is an overloaded && that works on the functors returned by the
overloaded < version.

Can someone offer a working solution (possibly better looking than this one
heh). Thanks!

PS: For didactic reasons I specifically do not want to write the comparator
manually but using lambda/bind composition and the like

-- 
Mihai RUSU					Email: dizzy_at_[hidden]
GPG : http://dizzy.roedu.net/dizzy-gpg.txt	WWW: http://dizzy.roedu.net
			"Linux is obsolete" -- AST

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net