C++0x\'s ranged-for loop has a special exception to handle arrays (FDIS §6.5.4), and there are two functions, std::begin and end, which are overloaded to handle arrays or to sel
I've encountered the same situation while using tuples:
template
auto f(Tuple&& tuple)
-> /* ??? */
{
using std::get;
return get(tuple);
}
which accepts both std::tuple
and boost::tuple
, and accepts both lvalues and rvalues as opposed to template
.
This particular case was solved with a traits class, which is in fact provided by the Standard: std::tuple_element
. As usual with traits classes, the idea is that tuple
is a protocol and anything that want to conform to it will provide a specialization for e.g. tuple_element
. So in my case the solution already existed.
In your case, if you were writing a library, I'd recommend writing (and documenting) such a traits class. In application code or other situations, I'm not so sure.