Sorting out the relationships between pairs of iterators, values, and references

  • Authors:
  • Krister Åhlander

  • Affiliations:
  • Department of Information Technology, Uppsala University, Uppsala, Sweden

  • Venue:
  • GPCE'05 Proceedings of the 4th international conference on Generative Programming and Component Engineering
  • Year:
  • 2005

Quantified Score

Hi-index 0.00

Visualization

Abstract

Motivated by a wish to sort an array A while simultaneously permuting another array B, iteration over array pairs (A,B) is considered. Traditional solutions to this problem require an adaption of either the algorithm or of the data structure. The generic programming approach described in this paper involves the construction of an iterator adaptor: an iterator pair. The different approaches are implemented in C++ and compared with respect to flexibility and performance. Our design is also compared with another iterator-based design. When examining our solution, we identify the relationship between a reference type and a value type as an independent abstraction. We find that a valid “reference type” to a value type T is not necessarily T&. The reference pair developed in this paper serves as an example of a reference type which refers to a standard value pair without being a standard reference. Our understanding of the relationships between iterator pairs, value pairs, and reference pairs, makes our design simpler than the alternative. It is argued that a recognition of these relationships is useful in many other generic programming contexts as well.