// Copyright (C) 2003 // Danil G. Shopyrin // // Permission to use, copy, modify, distribute and sell this software // and its documentation for any purpose is hereby granted without fee, // provided that the above copyright notice appear in all copies and // that both that copyright notice and this permission notice appear // in supporting documentation. Danil G. Shopyrin makes no representations // about the suitability of this software for any purpose. // It is provided "as is" without express or implied warranty. #ifndef __one_of_H_ #define __one_of_H_ #pragma once #include namespace boost { namespace _oo { //implementation details template class range_obj { const T& lo; const T& hi; public: inline range_obj( const T& _lo, const T& _hi ) : lo( _lo ), hi( _hi ) {} template bool operator==( V v ) const { return lo <= v && hi >= v; } }; template class suite_obj { InputIterator begin; InputIterator end; public: suite_obj( InputIterator _begin, InputIterator _end ) : begin( _begin ), end( _end ) {} template bool operator==( V v ) { return std::find( begin, end, v ) != end; } }; template class one_of_obj { const T& self; bool ok; public: inline one_of_obj( const T& _t ) : self( _t ), ok( false ) {} template inline one_of_obj& operator %( V v ) { ok = ( ok || v == self ); return *this; } inline operator bool () { return ok; } }; } template _oo::one_of_obj one_of( const T& t ) { return _oo::one_of_obj( t ); } template _oo::range_obj range( const T& _lo, const T& _hi ) { return _oo::range_obj( _lo, _hi ); } template _oo::suite_obj suite( InputIterator _begin, InputIterator _end ) { return _oo::suite_obj( _begin, _end ); } } #endif // __one_of_H_