POV-Ray : Newsgroups : povray.off-topic : Adventures with C++ : Re: An actual C++ question Server Time
29 Jul 2024 04:19:25 EDT (-0400)
  Re: An actual C++ question  
From: Kevin Wampler
Date: 23 May 2013 10:44:39
Message: <519e2b57$1@news.povray.org>
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

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.