Subject: [Boost-bugs] [Boost C++ Libraries] #4565: Stream operator overload for thread::id fails because thread::id::print() is not const.
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-08-18 17:29:49
#4565: Stream operator overload for thread::id fails because thread::id::print()
is not const.
-------------------------------------------------------+--------------------
Reporter: David Larsson <david.larsson@â¦> | Owner: anthonyw
Type: Bugs | Status: new
Milestone: To Be Determined | Component: thread
Version: Boost 1.44.0 | Severity: Problem
Keywords: |
-------------------------------------------------------+--------------------
In Boost 1.44.0 the implementation of `operator<<( basic_stream &,
thread::id const & )` changed when `BOOST_NO_MEMBER_TEMPLATE_FRIENDS` is
defined to call a new member function `print()`. However,
`thread::id::print()` is not `const`, so the following (admittedly silly)
code fragment will not compile:
{{{
std::cout << thread::current_thread::id() << std::endl;
}}}
On VC8 it fails with the error ''boost/thread/detail/thread.hpp(473) :
error C2662: 'std::basic_ostream<_Elem,_Traits>
&boost::thread::id::print<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits>
&)' : cannot convert 'this' pointer from 'const boost::thread::id' to
'boost::thread::id &'''.
The fix should be trivial - simply add a `const` modifier to
`boost::id::print`. On a related note, it seems a bit strange that the
public method `print()` only is defined for legacy compilers that have
`BOOST_NO_MEMBER_TEMPLATE_FRIENDS`. It should be private or exist for all
compilers. Finally, the code that failed is a workaround that is enabled
for VC8 and earlier, but the stream operator worked for `thread::id` on
VC8 before the workaround in Boost 1.43. Is it really necessary to define
`BOOST_NO_MEMBER_TEMPLATE_FRIENDS` for VC8 (VS2005)?
Thanks for a great library,
''/ David''
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/4565> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:04 UTC