Chapter 32. Argument-Dependent Return-Type Variance

 

Show me the man that’s never been jealous.

 
 --Lou Reed
 

There’s nothing sexy about a guy in a funny hat, or a programmer who knows Fortran.

 
 --George Frazier

Introduction

Q1:

How do you double a function’s potential return value semantics?

A1:

ARV it!

This chapter looks at how other languages—in this case, Ruby—can influence the idioms of C++, specifically with regard to how a collection may act as both an array and an associative array (also known as a map, hash, or dictionary). This requires that different functions of the same name return different types based on the types of their arguments. Now you’re probably thinking, “Well duh! That’s just overloading.” And so it is. But there’s more to it ...

Get Extended STL, Volume 1: Collections and Iterators now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.