Range Utilities for C++0x

Author: Thorsten Ottosen
Contact: thorsten.ottosen@dezide.com
Organizations:Dezide Aps
Date: 2007-04-17
Number:WG21/N2245 and J16/07-0105 (concept-based revision of n2068)
Working Group:Library

Abstract

This paper provides motivation and wording for minimal iterator range utilities.

Table of Contents

Introduction

This document describes a few very handy and often requested utility functions. They are all dependent on the Range concept on which the new for-loop is based.

Among other things, the functions make life easier for users of built-in arrays and give users a uniform way to calculate various iterators.

Basically this paper is a concept-based version of core pieces of n2068.

Wording

24.2 Header <iterator> synopsis

Add the following to the synopsis:

template<Range R>
R::iterator begin( R& r );

template<Range R>
R::iterator end( R& r );

template<Range R>
bool empty( const R& r );

template<Range R>
requires BidirectionalIterator<R::iterator>
reverse_iterator<R::iterator> rbegin( R& r );

template<Range R>
requires BidirectionalIterator<R::iterator>
reverse_iterator<R::iterator> rend( R& r );

template<Range R>
requires RandomAccessIterator<R::iterator>
R::iterator::difference_type size( const R& r );

template<Range R>
R::iterator::difference_type distance( const R& r );

24.3.6 Range utilities

Add the following new section:

template<Range R> R::iterator begin( R& r );

template<Range R> R::iterator end( R& r );

template<Range R> bool empty( const R& r );

template<Range R> requires BidirectionalIterator<R::iterator> reverse_iterator<R::iterator> rbegin( R& r );

template<Range R> requires BidirectionalIterator<R::iterator> reverse_iterator<R::iterator> rend( R& r );

template<Range R> requires RandomAccessIterator<R::iterator> R::iterator::difference_type size( const R& r );

template<Range R> R::iterator::difference_type distance( const R& r );