|
Boost : |
From: David Abrahams (dave_at_[hidden])
Date: 2002-08-17 13:09:31
From: "Anthony Williams" <anthwil_at_[hidden]>
> Can't we check whether [] returns a reference, somehow? It's not like
we're
> asking "what is the return value?", just is it T& or not, for known T,
> something like:
>
> template<typename T,typename IteratorType>
> struct checkSubscriptReturnIsRefToT
> {
> template<typename V>
> Big check(T& (IteratorType::*)(V));
>
> Small check(...);
>
> static const bool
> result=(sizeof(check(&IteratorType::operator[])==sizeof(Big));
> };
>
> Obviously, we need to cope with const, volatile and const volatile
operator[],
> and versions taking different types of parameter, but I'm sure you can
fill in
> the details.
We've thought about it, and haven't come up with an answer. The details
(like the fact that operator[] might be overloaded, which pretty much rules
out the approach above) are non-trivial. If /you/ can fill in the details,
I'm interested. I've already tried and failed.
-----------------------------------------------------------
David Abrahams * Boost Consulting
dave_at_[hidden] * http://www.boost-consulting.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk