Not only does the reverse adaptor work it can easily address your stated problem.Like this:
template<typename RangeT, typename Cond>
struct conditional_reverse_type_generator
{
typedef typename boost::mpl::if_<
Cond,
boost::reversed_range<RangeT>,
boost::sub_range<RangeT>
>::type type;
};
template<typename Cond, typename RangeT>
inline
typename conditional_reverse_type_generator<RangeT,Cond>::type
conditional_reverse(RangeT& rng)
{
typedef typename conditional_reverse_type_generator<RangeT,Cond>::type result_type;
return result_type(rng);
}
template<typename Cond, typename RangeT>
inline
typename conditional_reverse_type_generator<const RangeT,Cond>::type
conditional_reverse(const RangeT& rng)
{
typedef typename conditional_reverse_type_generator<const RangeT,Cond>::type result_type;
return result_type(rng);
}
I have never had the need for a null adaptor, and this would be the first request. I shall implement one for a later version of Boost since I can see a few use cases. However you need not wait, and I don't think it provides a better solution to your problem.
It is implemented in a detail namespace, but is brought into the boost namespace. This changed from the first versions of Boost.Range with adaptors. By popular demand the return types of the adaptors are now all public documented types.