|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r67288 - trunk/boost/optional
From: andrey.semashev_at_[hidden]
Date: 2010-12-17 16:12:58
Author: andysem
Date: 2010-12-17 16:12:56 EST (Fri, 17 Dec 2010)
New Revision: 67288
URL: http://svn.boost.org/trac/boost/changeset/67288
Log:
Refs #4987. Added forward declaration of namespace-scope swap for boost::optional, this should fix GCC compilation errors. Also swap implementation now uses Boost.Utility.Swap to make use of the workarounds for some broken compilers. If it breaks for your compiler, let me know in the mentioned ticket.
Text files modified:
trunk/boost/optional/optional.hpp | 143 ++++++++++++++++++---------------------
1 files changed, 65 insertions(+), 78 deletions(-)
Modified: trunk/boost/optional/optional.hpp
==============================================================================
--- trunk/boost/optional/optional.hpp (original)
+++ trunk/boost/optional/optional.hpp 2010-12-17 16:12:56 EST (Fri, 17 Dec 2010)
@@ -18,24 +18,25 @@
#include <new>
#include <algorithm>
-#include "boost/config.hpp"
-#include "boost/assert.hpp"
-#include "boost/type.hpp"
-#include "boost/type_traits/alignment_of.hpp"
-#include "boost/type_traits/has_nothrow_constructor.hpp"
-#include "boost/type_traits/type_with_alignment.hpp"
-#include "boost/type_traits/remove_reference.hpp"
-#include "boost/type_traits/is_reference.hpp"
-#include "boost/mpl/if.hpp"
-#include "boost/mpl/bool.hpp"
-#include "boost/mpl/not.hpp"
-#include "boost/detail/reference_content.hpp"
-#include "boost/none.hpp"
-#include "boost/utility/addressof.hpp"
-#include "boost/utility/compare_pointees.hpp"
-#include "boost/utility/in_place_factory.hpp"
+#include <boost/config.hpp>
+#include <boost/assert.hpp>
+#include <boost/type.hpp>
+#include <boost/type_traits/alignment_of.hpp>
+#include <boost/type_traits/has_nothrow_constructor.hpp>
+#include <boost/type_traits/type_with_alignment.hpp>
+#include <boost/type_traits/remove_reference.hpp>
+#include <boost/type_traits/is_reference.hpp>
+#include <boost/mpl/if.hpp>
+#include <boost/mpl/bool.hpp>
+#include <boost/mpl/not.hpp>
+#include <boost/detail/reference_content.hpp>
+#include <boost/none.hpp>
+#include <boost/utility/swap.hpp>
+#include <boost/utility/addressof.hpp>
+#include <boost/utility/compare_pointees.hpp>
+#include <boost/utility/in_place_factory.hpp>
-#include "boost/optional/optional_fwd.hpp"
+#include <boost/optional/optional_fwd.hpp>
#if BOOST_WORKAROUND(BOOST_MSVC, == 1200)
// VC6.0 has the following bug:
@@ -98,7 +99,7 @@
namespace boost_optional_detail
{
template <class T, class Factory>
- void construct(Factory const& factory, void* address)
+ inline void construct(Factory const& factory, void* address)
{
factory.BOOST_NESTED_TEMPLATE apply<T>(address);
}
@@ -110,6 +111,9 @@
class in_place_factory_base ;
class typed_in_place_factory_base ;
+// This forward is needed to refer to namespace scope swap from the member swap
+template<class T> void swap ( optional<T>& x, optional<T>& y );
+
namespace optional_detail {
// This local class is used instead of that in "aligned_storage.hpp"
@@ -615,7 +619,7 @@
void swap( optional & arg )
{
// allow for Koenig lookup
- using boost::swap ;
+ using boost::swap;
swap(*this, arg);
}
@@ -914,79 +918,63 @@
bool operator >= ( none_t x, optional<T> const& y )
{ return !( x < y ) ; }
-//
-// The following swap implementation follows the GCC workaround as found in
-// "boost/detail/compressed_pair.hpp"
-//
namespace optional_detail {
-// GCC < 3.2 gets the using declaration at namespace scope (FLC, DWA)
-#if BOOST_WORKAROUND(__GNUC__, < 3) \
- || BOOST_WORKAROUND(__GNUC__, == 3) && __GNUC_MINOR__ <= 2
- using std::swap;
-#define BOOST_OPTIONAL_STD_SWAP_INTRODUCED_AT_NS_SCOPE
-#endif
-
- template<bool use_default_constructor> struct swap_selector;
+template<bool use_default_constructor> struct swap_selector;
- template<>
- struct swap_selector<true>
- {
+template<>
+struct swap_selector<true>
+{
template<class T>
static void optional_swap ( optional<T>& x, optional<T>& y )
{
- bool hasX = x;
- bool hasY = y;
+ const bool hasX = !!x;
+ const bool hasY = !!y;
- if ( !hasX && !hasY )
- return;
+ if ( !hasX && !hasY )
+ return;
- if( !hasX )
- x = boost::in_place();
- else if ( !hasY )
- y = boost::in_place();
+ if( !hasX )
+ x = boost::in_place();
+ else if ( !hasY )
+ y = boost::in_place();
- // GCC > 3.2 and all other compilers have the using declaration at function scope (FLC)
-#ifndef BOOST_OPTIONAL_STD_SWAP_INTRODUCED_AT_NS_SCOPE
- // allow for Koenig lookup
- using std::swap ;
-#endif
- swap(*x,*y);
+ // Boost.Utility.Swap will take care of ADL and workarounds for broken compilers
+ boost::swap(x.get(),y.get());
- if( !hasX )
- y = boost::none ;
- else if( !hasY )
- x = boost::none ;
+ if( !hasX )
+ y = boost::none ;
+ else if( !hasY )
+ x = boost::none ;
}
- };
+};
- template<>
- struct swap_selector<false>
- {
+template<>
+struct swap_selector<false>
+{
template<class T>
static void optional_swap ( optional<T>& x, optional<T>& y )
{
- if ( !x && !!y )
- {
- x = *y;
- y = boost::none ;
- }
- else if ( !!x && !y )
- {
- y = *x ;
- x = boost::none ;
- }
- else if ( !!x && !!y )
- {
- // GCC > 3.2 and all other compilers have the using declaration at function scope (FLC)
- #ifndef BOOST_OPTIONAL_STD_SWAP_INTRODUCED_AT_NS_SCOPE
- // allow for Koenig lookup
- using std::swap ;
- #endif
- swap(*x,*y);
- }
+ const bool hasX = !!x;
+ const bool hasY = !!y;
+
+ if ( !hasX && hasY )
+ {
+ x = y.get();
+ y = boost::none ;
+ }
+ else if ( hasX && !hasY )
+ {
+ y = x.get();
+ x = boost::none ;
+ }
+ else if ( hasX && hasY )
+ {
+ // Boost.Utility.Swap will take care of ADL and workarounds for broken compilers
+ boost::swap(x.get(),y.get());
+ }
}
- };
+};
} // namespace optional_detail
@@ -995,10 +983,9 @@
template<class T> inline void swap ( optional<T>& x, optional<T>& y )
{
- optional_detail::swap_selector<optional_swap_should_use_default_constructor<T>::value>::optional_swap(x, y);
+ optional_detail::swap_selector<optional_swap_should_use_default_constructor<T>::value>::optional_swap(x, y);
}
} // namespace boost
#endif
-
Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk