
On 5/24/07, Peder Holt <peder.holt@gmail.com> wrote:
2007/5/24, Minmin Gong <gongminmin@yeah.net>: [...] 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