Tzu-Chien Chiu wrote:
Any boost library can make me write the expression like
int x = 3; if ( x in list(3, 5, 6, 7) ) { ... }
I don't know about the boost libraries, but I quickly sketched out
something you might be interested in, based on something I saw on one of
the news groups. All you have to do is to write a binary predicate
functor with bool operator()(int,<whatever your list type is>). It's
untested, but a quick syntax check with g++ 3.4.2 works fine.
Usage will be
if (x <in> list(3,5,6,7) ) { ... }
I hope that's more or less what you're after; I don't know if you want
that list type/function as well.
The code itself is attached. Be sure to fix the template parameter in
the unnamed namespace..
David Hall
template <class F>
struct operator_t
{
operator_t(F f=F()): f(f) {}
F f;
};
// Make a binary predicate functor that takes two arguments that iterates over your list...
namespace
{
operator_t<YOU FILL IN HERE> in;
}
namespace detail
{
template