1 /*=============================================================================
2 Copyright (c) 2001-2011 Joel de Guzman
4 Distributed under the Boost Software License, Version 1.0. (See accompanying
5 file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 ==============================================================================*/
7 #if !defined(BOOST_SPIRIT_RANGE_FUNCTIONS_MAY_16_2006_0720_PM)
8 #define BOOST_SPIRIT_RANGE_FUNCTIONS_MAY_16_2006_0720_PM
14 #include <boost/integer_traits.hpp>
16 namespace boost { namespace spirit { namespace support { namespace detail
18 template <typename Range>
20 is_valid(Range const& range)
22 // test for valid ranges
23 return range.first <= range.last;
26 template <typename Range>
28 includes(Range const& range, Range const& other)
30 // see if two ranges intersect
31 return (range.first <= other.first) && (range.last >= other.last);
34 template <typename Range>
36 includes(Range const& range, typename Range::value_type val)
38 // see if val is in range
39 return (range.first <= val) && (range.last >= val);
42 template <typename Range>
44 can_merge(Range const& range, Range const& other)
46 // see if a 'range' overlaps, or is adjacent to
47 // another range 'other', so we can merge them
49 typedef typename Range::value_type value_type;
50 typedef integer_traits<value_type> integer_traits;
52 value_type decr_first =
53 range.first == integer_traits::const_min
54 ? range.first : range.first-1;
56 value_type incr_last =
57 range.last == integer_traits::const_max
58 ? range.last : range.last+1;
60 return (decr_first <= other.last) && (incr_last >= other.first);
63 template <typename Range>
65 merge(Range& result, Range const& other)
68 if (result.first > other.first)
69 result.first = other.first;
70 if (result.last < other.last)
71 result.last = other.last;
74 template <typename Range>
77 // compare functor with a value or another range
79 typedef typename Range::value_type value_type;
81 bool operator()(Range const& x, const value_type y) const
86 bool operator()(value_type const x, Range const& y) const
91 bool operator()(Range const& x, Range const& y) const
93 return x.first < y.first;