|
![](/i/fill.gif) |
On 5/23/2013 7:14 AM, scott wrote:
>
> boost::shared_ptr<std::vector<Foo>> _foo(new std::vector<Foo>());
>
> I don't see how the >> is ambiguous at all in this statement. Seems to
> me like lazy/bad parser design if this trips it up.
>
It's not quite so cut and dry as you might guess. For example:
#include <iostream>
using std::cout;
using std::endl;
int _foo(int i) {
return i;
}
namespace std {
static const int vector = 7;
}
namespace boost {
static const int shared_ptr = 5;
}
int main(int argc, char** argv) {
int Foo = 3;
cout << (boost::shared_ptr<std::vector<Foo>> _foo(NULL)) << endl;
return 0;
}
If you run this program it should print "1" (at least in MSVC), which is
the result of treating < and >> and the less-than and bit-shift
operators. Of course you couldn't write "new std::vector<Foo>()" in
this scheme, but it does show that it's hard to tell what's a template
and what's not at a purely syntatic level.
In any case, the C++11 standard does allow
"boost::shared_ptr<std::vector<Foo>> _foo(new std::vector<Foo>()); " and
the most recent version of GCC supposedly supports this. You can read a
bit more about it here:
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2005/n1757.html
Post a reply to this message
|
![](/i/fill.gif) |