
Hi, I have been using zip iterators with a BOOST::Test to check that maps contain expected values. After moving some templated code to a header file I found that the code would not compie unless I place a *'using namespace std;' * declaration within one of functions. The compiler is gcc 4.6.2 and 4.4.2. The version of boost is 1.47 and 1.49 The minimum code snippet is as follows: * using namespace std; // without this the next line does not compile!* The error from gcc is: -- View this message in context: http://boost.2283326.n4.nabble.com/zip-iterator-hpp-boost-tuple-requires-a-u... Sent from the Boost - Users mailing list archive at Nabble.com.

On Wed, Feb 29, 2012 at 10:17:43AM -0800, mark pashley wrote:
Hi,
I have been using zip iterators with a BOOST::Test to check that maps contain expected values.
After moving some templated code to a header file I found that the code would not compie unless I place a *'using namespace std;' * declaration within one of functions.
The compiler is gcc 4.6.2 and 4.4.2. The version of boost is 1.47 and 1.49
The minimum code snippet is as follows:
* using namespace std; // without this the next line does not compile!*
The error from gcc is:
-- View this message in context: http://boost.2283326.n4.nabble.com/zip-iterator-hpp-boost-tuple-requires-a-u... Sent from the Boost - Users mailing list archive at Nabble.com. _______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
Hello. Your mail seems to be utterly mangled when recieved by an end user of this list. Do consider looking over your mail agent and its settings if you want anyone to be able to discuss with you. The above is verbatim what my client tells me your mail contains, which is lacking pretty much anything preformatted that Nabble claims your mail contains. -- Lars Viklund | zao@acc.umu.se

Hi Lars, I used nabble.com to pre-format the message, I guess that the pre-formatting is corrupted when sent out to end user's of the list. ... The gist of the problem is that the following template does not compile without the "using namespace std" statement: template <class T> struct MapZipHelperImpl { typedef typename boost::tuple< const T&, const T& > iter_value_type; void operator()( const iter_value_type& iter_value ) { using namespace std; // without this the next line does not compile! typename T::first_type val = iter_value.get<0>().first ; } }; The error is: error: expected primary-expression before ‘)’ token I believe that the "using namespace std;" statement should not be necessary. Is it possible that a header file is missing a std:: qualification and in-advertantly depending on client code to include the "using namespace std;" statement? It took a t of effort to simplify the code that was causing the problem and produce a minimal example. -- View this message in context: http://boost.2283326.n4.nabble.com/zip-iterator-hpp-boost-tuple-requires-a-u... Sent from the Boost - Users mailing list archive at Nabble.com.

On Wed, Feb 29, 2012 at 12:36:04PM -0800, mark pashley wrote:
void operator()( const iter_value_type& iter_value ) { using namespace std; // without this the next line does not compile! typename T::first_type val = iter_value.get<0>().first ; } };
error: expected primary-expression before ‘)’ token
I believe you need to say: iter_value.template get<0>().first The use of 'template' there is akin to the use of 'typename' when it comes to types. The parse otherwise is iter_value.get < 0 > ().first which explains your error rather directly. Without the 'template' keyword, it's interpreted as a member with some less-than and greater-than comparisons. -- Lars Viklund | zao@acc.umu.se

Thankyou Lars & Nathan, the addition of the .template has fixed it. I am still confused as to why the "using" statement appeared to fix/hide the problem, but it is good to know the correct solution. -- View this message in context: http://boost.2283326.n4.nabble.com/zip-iterator-hpp-boost-tuple-requires-a-u... Sent from the Boost - Users mailing list archive at Nabble.com.

Thankyou Lars & Nathan, the addition of the .template has fixed it. I am still confused as to why the "using" statement appeared to fix/hide the problem, but it is good to know the correct solution.
My guess would be that the name lookup process performed by the compiler when resolving the "get" depends on what other things named "get" are in scope. The "using namespace std" function brings std::get into scope which somehow affects the outcome of the name lookup process. C++ is a very hard language for compilers to work with. Even the best compilers just approximate the behaviour prescribed by the C++ standard. Bugs like this one, where the compiler accepts invalid code in some corner cases, naturally get lower priority treatment than bugs where the compiler fails to accept valid code or generates wrong machine code, so they tend to stay around. Regards, Nate

mark pashley
Thankyou Lars & Nathan, the addition of the .template has fixed it. I am still confused as to why the "using" statement appeared to fix/hide the problem, but it is good to know the correct solution.
Are you using Visual Studio? It is the only mainstream compiler I know of that is not implementing two-phase name look-up correctly which can explain could explain some of the roots of your issue. HTH, Philipp Moeller

The gist of the problem is that the following template does not compile without the "using namespace std" statement:
template <class T> struct MapZipHelperImpl { typedef typename boost::tuple< const T&, const T& > iter_value_type;
void operator()( const iter_value_type& iter_value ) { using namespace std; // without this the next line does not compile! typename T::first_type val = iter_value.get<0>().first ; } };
The error is:
error: expected primary-expression before ‘)’ token
The code is incorrect. For me, it doesn't compile even with the "using namespace std". The correct code is: typename T::first_type val = iter_value.template get<0>().first ; Note the added "template" keyword. Older versions of GCC may have been lenient accepting code like this without the "template" keyword, but it has always been incorrect. Regards, Nate
participants (4)
-
Lars Viklund
-
mark pashley
-
Nathan Ridge
-
Philipp Moeller