|
Boost : |
From: Giovanni Piero Deretta (gpderetta_at_[hidden])
Date: 2007-05-24 09:15:42
On 5/24/07, Peder Holt <peder.holt_at_[hidden]> wrote:
> 2007/5/24, Minmin Gong <gongminmin_at_[hidden]>:
> [...]
> On GCC we use the native typeof mechanism, so your code is actually
> translated into this:
>
> int main() {
> std::vector<int> v;
> typedef typeof(boost::type_of::ensure_obj(v))::type type;
> }
>
> The simpler:
> typedef typeof(v)::type type;
>
> fails to compile as well, so this is a shortcomming in the compiler.
Well, vector has no 'type' type. Anyways, It fail)s for 'iterator' too:
std::vector<int> v;
typedef typeof(int)::iterator type;
> Unfortunately there is little we can do to fix this in Boost.Typeof.
This works though (at least with gcc 4.1.2):
#include <vector>
template<typename T>
struct identity {
typedef T type;
};
int main() {
std::vector<int> v;
typedef identity<typeof(v)>::type::iterator type;
}
So BOOST_TYPEOF could include 'identity' in its expansion.
It might fail with more complex expression as I heard that gcc doesn't
like much typeof in template parameters (but never tested it).
gpd
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk