Subject: Re: [Boost-bugs] [Boost C++ Libraries] #3996: Enable use of BOOST_FOREACH over const-ref of noncopyable ptr_containers
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-06-25 01:03:29
#3996: Enable use of BOOST_FOREACH over const-ref of noncopyable ptr_containers
--------------------------------------------------------+-------------------
Reporter: Kazutoshi Satoda <k_satoda@â¦> | Owner: nesotto
Type: Patches | Status: new
Milestone: Boost 1.43.0 | Component: ptr_container
Version: Boost 1.42.0 | Severity: Problem
Resolution: | Keywords: BOOST_FOREACH is_noncopyable
--------------------------------------------------------+-------------------
Comment (by eric_niebler):
1) A type !ThirdParty is defined in !ThirdParty.h. The user can't edit
this file because it's not hers. It does not specialize is_noncopyable
because it knows nothing about BOOST_FOREACH.
2) A user creates her own !ThirdPartyForEach.h that #includes
!ThirdParty.h and specializes is_noncopyable. Where ever she wants to use
!ThirdParty together with BOOST_FOREACH, she includes !ThirdPartyForEach.h
3) In Unit1.cpp, the user instantiates ptr_vector<!ThirdParty>. She
includes !ThirdParty.h instead of !ThirdPartyForEach.h because in this
translation unit she is not using BOOST_FOREACH.
4) In Unit2.cpp, she also instantiates ptr_vector<!ThirdParty>. She *does*
include !ThirdPartyForEach.h in this translation unit because it uses
BOOST_FOREACH.
5) Undefined behavior.
The problem stems from the fact that the user cannot possibly know that
she needs to include !ThirdPartyForEach.h EVEN IN TRANSLATION UNITS THAT
DON'T USE BOOST_FOREACH. This is a recipe for ODR violations.
Contrast this with my suggested solution. is_noncopyable will *only* be
instantiated in the translation units that actually use BOOST_FOREACH. In
these source files, it's natural to expect people to include the header
that correctly implements the foreach hooks.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/3996#comment:4> 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:03 UTC