Boost logo

Boost :

From: David Abrahams (dave_at_[hidden])
Date: 2004-11-10 20:55:33


"Peter Dimov" <pdimov_at_[hidden]> writes:

>
> std::map< boost::shared_ptr<void>, int > wpmap;
>
> void write( std::ostream & os, int const & v )
> {
> os << v << ' ';
> }
>
> void write( std::ostream & os, std::string const & v )
> {
> os << v << ' ';
> }
>
> template<class T> void write( std::ostream & os, boost::shared_ptr<T>
> const & pt )
> {
> if( pt )
> {
> int pid = wpmap[ pt ];
>
> if( pid != 0 )
> {
> write( os, pid );
> }
> else
> {
> pid = wpmap.size();

I could be wrong, but don't you need to add 1 here? wpmap starts out
empty, after all.

> wpmap[ pt ] = pid;
> write( os, pid );
> write( os, *pt );
> }
> }
> else
> {
> write( os, 0 );
> }
> }

-- 
Dave Abrahams
Boost Consulting
http://www.boost-consulting.com

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk