ML-style Tuple Assignment in Standard C++ -Extending the Multiple Return Value Formalism

  • Authors:
  • Jaakko Jarvi

  • Affiliations:
  • -

  • Venue:
  • ML-style Tuple Assignment in Standard C++ -Extending the Multiple Return Value Formalism
  • Year:
  • 1999

Quantified Score

Hi-index 0.01

Visualization

Abstract

It has been shown previously that tuples can be implemented with templates in standard C++. This article extends the author''s previous work on tuples and multiple return values by defining generic functions and classes to support a kind of a multivalued assignment. The return values of a function returning a tuple can be assigned to separate variables with a single statement. E.g., assuming that foo is a function returning a 3-tuple and that a, b and c are variables of correct type, the expression tie(a, b, c) = foo() assigns the three returned elements to a, b and c. The presented template definitions result in a typesafe and intuitive tuple formalism, resembling the the tuple constructs in ML, for defining and calling functions having multiple return values. The produced code is efficient. Resource consumption of compiling increases to some extent, but hardly significantly on real programs.