Boost logo

Boost Users :

Subject: Re: [Boost-users] Caching the iterator of async_resolve()?
From: Gavin Lambert (gavinl_at_[hidden])
Date: 2013-12-17 18:31:27

On 18/12/2013 11:44, Quoth Kaspar Fischer:
> Just to be on the safe side: I assume that I can cache the iterator
> returned by async_resolve
> <>'s
> handler, correct?

I'm not an expert, but I would be surprised if that were safe. You
should probably iterate it and save the resulting objects from within
your handler only.

> The fact that it's a forward iterator suggests so...

I don't know why you think that follows. The iterator type just tells
you what the interface is, not what the lifetime of the underlying
collection is.

In this case, it's possible that the collection has the same lifetime as
the socket, or of the iterators (which would make caching it somewhat
safe) but I would think it far more likely that it has the lifetime of
the resolve operation itself instead (which would make caching it
unsafe, as it would be deleted as soon as the handler returns).

Boost-users list run by williamkempf at, kalb at, bjorn.karlsson at, gregod at, wekempf at