Question: The backstory.
In VBA in Excel I created a function that calculate the shortest distance between two lines (vectors). This function returns the apparent intersection point, and the actual distance between them.
To make this work I ended up passing out an array, then sorting out what went where afterwards. It works, but is clunky to read and work with.

In C++ i have made a similar function that returns the point in question.

```
struct point3D
{ 
double x,y,z;
}
point3D findIntersect(const vec3& vector1, const vec3& vector2)
{
// Do stuff...
return point;
}

```

The problem:
I want to return the length as well, since it uses parts of the original calculation. However most of the time I only want the point.

Possible solutions I have looked at are:

Write a separate function for the distance. A lot of extra work for when I want both of them.

* Create a custom struct for this one function. *Seems a bit overkill.*
* Return an array like the VBA function did. *Resulting code is not very intuitive, and requires care when using.*
* Using an optional argument as a reference to a variable to store the distance. *Does not work. The compiler does not allow me to change an optional argument.*
* Using an argument list like this `function(const argin1, const argin2, argout&, argout2&)`. *Just ugh! Would require the user to always expect every variable out.*

I have seen examples with pairs, but the they look like they have to be the same data type. I essentially want to return a `point3D`, and a `double`.

Does anyone have a more elegant solution to returning multiple values from a function?

Answer: 
You could use a `std::pair<point3D, double>`. There is also a `std::tuple`, when you need to return more than two values. (Notice there is no such thing as same type for the pair or tuple values, as you mentioned.)
I still think that you can and should create the struct for your code (if your code is not a real time..) Stucts are very common and gives you robastics and flexibility in case you would need to expend your code. To be depends on on these key value pair in you code and then realize after few months that you need to change it in 10 places... :)