O'Reilly logo

Extended STL, Volume 1: Collections and Iterators by Matthew Wilson

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required