Played around a bit, try this. It only defines is_in (which wraps
'std::find(rhs.begin(), rhs.end(), lhs) != rhs.end()' ),
but should be easily generalisable to any operation, say:
if(x vec) {while(int i vec) cout << i;}
(I don't know if you could do the last one, or what syntax would be
better suited, but you get the idea)
#include <vector>
#include <algorithm>
namespace boost { namespace infix {
namespace detail {
template
struct binder
{
explicit binder(LhsT& _lhs)
: lhs(_lhs)
{}
template <typename RhsT>
typename Operator::template sig::type
operator > (const RhsT& rhs)
{ return Operator::apply(lhs, rhs);
}
// SFINAE version of the above using ::result_type
// ...
private:
LhsT& lhs;
};
// lots of other things
}
struct is_in_operator
{ template
static bool
apply(const ValueT& val, const Cont& cont)
{ return std::find
( cont.begin()
, cont.end()
, val
) != cont.end();
}
template
struct sig
{ typedef bool type;
};
} is_in;
// Lots of other infix operators
template
detail::binder
operator < (LhsT& lhs, Operator rhs)
{ return detail::binder(lhs);
}
}}
int main()
{ using namespace boost::infix;
std::vector<int> vec;
int val = 6;
vec.push_back(4);
vec.push_back(7);
vec.push_back(6);
return val vec;
}