Boost logo

Boost :

From: fkoh_at_[hidden]
Date: 2001-07-05 21:01:41


I propose additions to the compose library to allow

(iterator_proxy<int>()>4) && (iterator_proxy<int>()<7)

as another way of writing

compose_f_gx_hx(logical_and<bool>(),bind2nd(greater<int>(),4),bind2nd
(less<int>(),7))

Any interest in this. The code below illustrates this:
    
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include "print.hpp"
#include "compose.hpp"
using namespace std;
using namespace boost;

template<typename A, typename B>
compose_f_gx_hx_t<logical_and<bool> ,A,B> operator&&(const A & a,
const B & b)
{
  return compose_f_gx_hx(logical_and<bool>(),a,b);
}

template<typename T>
struct iterator_proxy {
  typedef T return_type;
};

template<typename A, typename B>
binder2nd<greater<A::return_type> > operator>(const A & a, const B &
b)
{
  return bind2nd(greater<A::return_type>(),b);
}

template<typename A, typename B>
binder2nd<less<A::return_type> > operator<(const A & a, const B & b)
{
  return bind2nd(less<A::return_type>(),b);
}

template<typename A, typename B>
compose_f_gx_hx_t<logical_or<bool> ,A,B> operator||(const A & a,
const B & b)
{
  return compose_f_gx_hx(logical_or<bool>(),a,b);
}

template<typename A, typename B>
binder2nd<greater_equal<A::return_type> > operator>=(const A & a,
const B & b)
{
  return bind2nd(greater_equal<A::return_type>(),b);
}

template<typename A, typename B>
binder2nd<less_equal<A::return_type> > operator<=(const A & a, const
B & b)
{
  return bind2nd(less_equal<A::return_type>(),b);
}

template<typename A, typename B>
binder2nd<equal_to<A::return_type> > operator==(const A & a, const B
& b)
{
  return bind2nd(equal_to<A::return_type>(),b);
}

int main()
{
    vector<int> coll;

    for (int i=1; i<=9; ++i) {
        coll.push_back(i);
    }
    PRINT_ELEMENTS(coll);

    vector<int>::iterator pos;

    pos = remove_if (coll.begin(),coll.end(),iterator_proxy<int>()
>4&&iterator_proxy<int>()<7);

    coll.erase(pos,coll.end());

    PRINT_ELEMENTS(coll);
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk