style.qbk 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. [/
  2. Copyright 2010 Neil Groves
  3. Distributed under the Boost Software License, Version 1.0.
  4. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. /]
  6. [section:style_guide Terminology and style guidelines]
  7. The use of a consistent terminology is as important for __ranges__ and range-based algorithms as it is for iterators and iterator-based algorithms. If a conventional set of names are adopted, we can avoid misunderstandings and write generic function prototypes that are [*/self-documenting/].
  8. Since ranges are characterized by a specific underlying iterator type, we get a type of range for each type of iterator. Hence we can speak of the following types of ranges:
  9. * [*/Value access/] category:
  10. * Readable Range
  11. * Writeable Range
  12. * Swappable Range
  13. * Lvalue Range
  14. * [*/Traversal/] category:
  15. * __single_pass_range__
  16. * __forward_range__
  17. * __bidirectional_range__
  18. * __random_access_range__
  19. Notice how we have used the categories from the __new_style_iterators__.
  20. Notice that an iterator (and therefore an range) has one [*/traversal/] property and one or more properties from the [*/value access/] category. So in reality we will mostly talk about mixtures such as
  21. * Random Access Readable Writeable Range
  22. * Forward Lvalue Range
  23. By convention, we should always specify the [*/traversal/] property first as done above. This seems reasonable since there will only be one [*/traversal/] property, but perhaps many [*/value access/] properties.
  24. It might, however, be reasonable to specify only one category if the other category does not matter. For example, the __iterator_range__ can be constructed from a Forward Range. This means that we do not care about what [*/value access/] properties the Range has. Similarly, a Readable Range will be one that has the lowest possible [*/traversal/] property (Single Pass).
  25. As another example, consider how we specify the interface of `std::sort()`. Algorithms are usually more cumbersome to specify the interface of since both [*/traversal/] and [*/value access/] properties must be exactly defined. The iterator-based version looks like this:
  26. ``
  27. template< class RandomAccessTraversalReadableWritableIterator >
  28. void sort( RandomAccessTraversalReadableWritableIterator first,
  29. RandomAccessTraversalReadableWritableIterator last );
  30. ``
  31. For ranges the interface becomes
  32. ``
  33. template< class RandomAccessReadableWritableRange >
  34. void sort( RandomAccessReadableWritableRange& r );
  35. ``
  36. [endsect]