Why have forward container declaration in boost/functiona/detail/container_fwd.hpp?

Hello - I am migrating our code base from boost 1.33.1 to 1.34.1. Some changes in boost/functional is causing compilation issues. The hash.hpp in 1.33 does include std container header files. In 1.34.1, however, forward declaration is added as following: #if (defined(__GLIBCXX__) && defined(_GLIBCXX_DEBUG)) \ || BOOST_WORKAROUND(__BORLANDC__, > 0x551) \ || BOOST_WORKAROUND(__DMC__, BOOST_TESTED_AT(0x842)) \ || (defined(__SGI_STL_PORT) || defined(_STLPORT_VERSION)) #include <deque> #include <list> #include <vector> .... #else namespace std { ... template <class T, class Allocator> class list; template <class T, class Allocator> class vector; template <class Key, class T, class Compare, class Allocator> class map; ... } I am working on Darwin with gcc 4.0.1, and the #if test is not true, so we fall through the #else path, with only forward declaration. If my code does not include standard container headers explicitly, it will not compile with boost 1.34.1. Of course the easy fix is to add the standard container header in my code instead of depending on boost to pull it in. What is the reason behind this change? Thanks for explanations. Yingwei

On Nov 8, 2007 2:19 AM, Yingwei Zhang <ywz@powerset.com> wrote:
Hello -
I am migrating our code base from boost 1.33.1 to 1.34.1. Some changes in boost/functional is causing compilation issues. The hash.hpp in 1.33 does include std container header files. In 1.34.1, however, forward declaration is added as following:
If you need the container headers you should include them, not rely on a third party header including it. In fact in this case conatainer_fwd IMHO does exactly the right thing. It forwards declare std containers when he thinks it is safe to do so. If It can't it includes them. Forward declaring standard containers without including the headers is something that comes handy very often. HTH, -- gpd

Giovanni Piero Deretta wrote:
On Nov 8, 2007 2:19 AM, Yingwei Zhang <ywz@powerset.com> wrote:
Hello -
I am migrating our code base from boost 1.33.1 to 1.34.1. Some changes in boost/functional is causing compilation issues. The hash.hpp in 1.33 does include std container header files. In 1.34.1, however, forward declaration is added as following:
If you need the container headers you should include them, not rely on a third party header including it. In fact in this case conatainer_fwd IMHO does exactly the right thing. It forwards declare std containers when he thinks it is safe to do so. If It can't it includes them. Forward declaring standard containers without including the headers is something that comes handy very often.
And is also not legal or portable IIRC because an implementation is allowed to add extra template parameters to a type as long as they have defaults and these would break your forward declarations. IMO all standard headers should have corresponding fwd headers like the legacy iosfwd header, but since they don't AFAIK the only legal and portable way to get the type of a standard container is to include its header. Thanks, Michael Marcin

On Nov 8, 2007 8:55 PM, Michael Marcin <mmarcin@method-solutions.com> wrote:
[...] And is also not legal or portable IIRC because an implementation is allowed to add extra template parameters to a type as long as they have defaults and these would break your forward declarations.
It is techinically illegal, but in practice it works almost everywhere. When it doesn't work (for example libstdc++ in debug mode) you can fall back to including the standar headers. Also I think that there has been a defect report and now implementations are no longer allowed to add defaulted parameters to containers, but I'm not really sure about that.
IMO all standard headers should have corresponding fwd headers like the legacy iosfwd header, but since they don't AFAIK the only legal and portable way to get the type of a standard container is to include its header.
Writing compiler specific workaround and optimizations is IMHO all fine, as long as you have a safe and portable fallback. In this case the optimization is for compile time and the fallback is completely portable. -- gpd

Giovanni Piero Deretta wrote:
On Nov 8, 2007 2:19 AM, Yingwei Zhang <ywz@powerset.com> wrote:
Hello -
I am migrating our code base from boost 1.33.1 to 1.34.1. Some changes in boost/functional is causing compilation issues. The hash.hpp in 1.33 does include std container header files. In 1.34.1, however, forward declaration is added as following:
If you need the container headers you should include them, not rely on a third party header including it. In fact in this case conatainer_fwd IMHO does exactly the right thing. It forwards declare std containers when he thinks it is safe to do so. If It can't it includes them. Forward declaring standard containers without including the headers is something that comes handy very often.
That's exactly the reasoning. There was a fair amount of demand for this change. And I this is the first time anyone has been against it (and it's quite a long time since it was introduced). It's also worth noting that if in the future you used the standard C++ <functional> header instead you'd need to include the container headers as well. Unfortunately, the error messages are often confusing. Also, code that works on some platforms won't work on others - this also applies to the standard headers. I think this is part of the C++ condition. Daniel
participants (4)
-
Daniel James
-
Giovanni Piero Deretta
-
Michael Marcin
-
Yingwei Zhang