
In a nutshell, I want to use ranges to unify several different ways of representing
"strings" in the program. This includes subranges of an existing sequence, so for
consistancy a "fixed" sized container does not need a nul termination but can fill the
container completely. The point here is that I want to treat arrays differently from
pointers, which is unlike boost::as_literal.
The idea is that I can apply a pre-conditioning function to any supported type, and get a
iterator_range back out. Here is an example of a trivial function to test it out, that
just returns the length:
namespace internal {
template <typename RangeT>
size_t Strlen (RangeT s)
{
return boost::size(s);
}
}
template <typename T>
size_t Strlen (T s)
{
return internal::Strlen (internal::as_literal(s));
}
For a more complex function, every argument that is meant to be a generalized "string"
will be so-wrapped, and pass on to the underlying internal form which expects that they
are all Ranges.
The conditioning needed is almost the same as boost::as_literal, so I copied and modified
that:
template <typename CharT>
inline boost::iterator_range<CharT> measure_fixed (CharT* p, std::size_t capacity)
{
// The deduced CharT will include the const if called on a const array.
Char* found= std::find (p, p+capacity, CharT(0));
// the find algorithm naturally does what I want, returning the same 'end' if not
found.
return boost::iterator_range<CharT> (p, found);
}
// Copied directly from Boost: pointers and containers
template< class Range >
inline boost::iterator_range