|
Boost-Commit : |
From: daniel_james_at_[hidden]
Date: 2008-04-13 06:44:02
Author: danieljames
Date: 2008-04-13 06:44:01 EDT (Sun, 13 Apr 2008)
New Revision: 44362
URL: http://svn.boost.org/trac/boost/changeset/44362
Log:
Limited support for older compilers.
Added:
sandbox/move/boost/move/
sandbox/move/boost/move/detail/
sandbox/move/boost/move/detail/config.hpp (contents, props changed)
sandbox/move/libs/move/test/no_sfinae_test.cpp (contents, props changed)
Text files modified:
sandbox/move/boost/move.hpp | 76 ++++++++++++++++++++++++++++++++++++++++
sandbox/move/libs/move/test/Jamfile.v2 | 1
sandbox/move/libs/move/test/vector.hpp | 7 +++
3 files changed, 83 insertions(+), 1 deletions(-)
Modified: sandbox/move/boost/move.hpp
==============================================================================
--- sandbox/move/boost/move.hpp (original)
+++ sandbox/move/boost/move.hpp 2008-04-13 06:44:01 EDT (Sun, 13 Apr 2008)
@@ -27,6 +27,7 @@
#include <boost/type_traits/is_same.hpp>
#include <boost/type_traits/is_class.hpp>
#include <boost/utility/enable_if.hpp>
+#include <boost/move/detail/config.hpp>
/*************************************************************************************************/
@@ -38,6 +39,10 @@
/*************************************************************************************************/
+#if !defined(BOOST_MOVE_NO_HAS_MOVE_ASSIGN)
+
+/*************************************************************************************************/
+
template <typename T>
struct class_has_move_assign {
class type {
@@ -65,6 +70,10 @@
/*************************************************************************************************/
+#endif // BOOST_MOVE_NO_HAS_MOVE_ASSIGN
+
+/*************************************************************************************************/
+
/*
REVISIT (sparent_at_[hidden]): This is a work around for Boost 1.34.1 and VC++ 2008 where
boost::is_convertible<T, T> fails to compile.
@@ -95,6 +104,12 @@
T& source;
};
+/*************************************************************************************************/
+
+#if !defined(BOOST_MOVE_NO_HAS_MOVE_ASSIGN)
+
+/*************************************************************************************************/
+
/*!
\ingroup move_related
\brief The is_movable trait can be used to identify movable types.
@@ -108,6 +123,22 @@
/*************************************************************************************************/
+#else // BOOST_MOVE_NO_HAS_MOVE_ASSIGN
+
+// On compilers which don't have adequate SFINAE support, treat most types as unmovable,
+// unless the trait is specialized.
+
+template <typename T>
+struct is_movable : boost::mpl::false_ { };
+
+#endif
+
+/*************************************************************************************************/
+
+#if !defined(BOOST_NO_SFINAE)
+
+/*************************************************************************************************/
+
/*!
\ingroup move_related
\brief copy_sink and move_sink are used to select between overloaded operations according to
@@ -172,6 +203,29 @@
/*************************************************************************************************/
+#else // BOOST_NO_SFINAE
+
+// On compilers without SFINAE, define copy_sink to always use the copy function.
+
+template <typename T,
+ typename U = T,
+ typename R = void*>
+struct copy_sink
+{
+ typedef R type;
+}
+
+// Always copy the element unless this is overloaded.
+
+template <typename T>
+T& move(T& x) {
+ return x;
+}
+
+#endif // BOOST_NO_SFINAE
+
+/*************************************************************************************************/
+
/*!
\ingroup move_related
\brief Iterator pair version of move. Similar to std::copy but with move semantics,
@@ -268,6 +322,10 @@
/*************************************************************************************************/
+#if !defined(BOOST_NO_SFINAE)
+
+/*************************************************************************************************/
+
/*!
\ingroup move_related
\brief Placement move construction, selected when T is_movable is true
@@ -327,6 +385,24 @@
/*************************************************************************************************/
+#else // BOOST_NO_SFINAE
+
+template <typename T>
+inline void move_construct(T* p, const T& x)
+{
+ ::new(static_cast<void*>(p)) T(x);
+}
+
+template <typename I, // I models InputIterator
+ typename F> // F models ForwardIterator
+F uninitialized_move(I f, I l, F r)
+{
+ return std::uninitialized_copy(f, l, r);
+}
+
+#endif
+
+/*************************************************************************************************/
} // namespace boost
/*************************************************************************************************/
Added: sandbox/move/boost/move/detail/config.hpp
==============================================================================
--- (empty file)
+++ sandbox/move/boost/move/detail/config.hpp 2008-04-13 06:44:01 EDT (Sun, 13 Apr 2008)
@@ -0,0 +1,18 @@
+
+// Copyright 2008 Daniel James.
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+#if !defined(BOOST_MOVE_DETAIL_CONFIG_HEADER)
+#define BOOST_MOVE_DETAIL_CONFIG_HEADER
+
+#include <boost/config.hpp>
+
+#if defined(BOOST_NO_SFINAE)
+# define BOOST_MOVE_NO_HAS_MOVE_ASSIGN
+#elif defined(__GNUC__) && \
+ (__GNUC__ < 3 || __GNUC__ == 3 && __GNUC_MINOR__ <= 3)
+# define BOOST_MOVE_NO_HAS_MOVE_ASSIGN
+#endif
+
+#endif
Modified: sandbox/move/libs/move/test/Jamfile.v2
==============================================================================
--- sandbox/move/libs/move/test/Jamfile.v2 (original)
+++ sandbox/move/libs/move/test/Jamfile.v2 2008-04-13 06:44:01 EDT (Sun, 13 Apr 2008)
@@ -1,3 +1,4 @@
import testing ;
project boost/move ;
run main.cpp /boost/unit_test//boost_unit_test_framework ;
+run no_sfinae_test.cpp /boost/unit_test//boost_unit_test_framework ;
Added: sandbox/move/libs/move/test/no_sfinae_test.cpp
==============================================================================
--- (empty file)
+++ sandbox/move/libs/move/test/no_sfinae_test.cpp 2008-04-13 06:44:01 EDT (Sun, 13 Apr 2008)
@@ -0,0 +1,54 @@
+
+
+// Copyright 2008 Daniel James.
+// Distributed under the Boost Software License, Version 1.0. (See accompanying
+// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
+
+// g++ 3.3 (and possibly other compilers) haven't got good enough support
+// for SFINAE to detect movable types, but has enough to implement the
+// functions. So they can be used by specializing boost::is_movable.
+//
+// Is this worth supporting?
+
+#include <iostream>
+
+#include <boost/move.hpp>
+
+#define BOOST_TEST_MAIN
+#include <boost/test/unit_test.hpp>
+#include "./vector.hpp"
+
+struct movable {
+ movable() {}
+ movable(movable const&) {}
+
+ movable(boost::move_from<movable> x)
+ {
+ }
+
+ movable& operator=(boost::move_from<movable> x)
+ {
+ return *this;
+ }
+};
+
+namespace boost
+{
+ template<>
+ struct is_movable< ::movable > : public boost::mpl::true_ {};
+ template<typename T>
+ struct is_movable< ::test_vector<T> > : public boost::mpl::true_ {};
+}
+
+BOOST_AUTO_TEST_CASE(move_test)
+{
+ BOOST_CHECK(boost::is_movable< ::movable >::value);
+
+ test_vector<int> x;
+
+ x.push_back(0);
+ int* ptr = &x[0];
+
+ test_vector<int> y(boost::move(x));
+ BOOST_CHECK_EQUAL(ptr, &y[0]);
+}
Modified: sandbox/move/libs/move/test/vector.hpp
==============================================================================
--- sandbox/move/libs/move/test/vector.hpp (original)
+++ sandbox/move/libs/move/test/vector.hpp 2008-04-13 06:44:01 EDT (Sun, 13 Apr 2008)
@@ -106,11 +106,16 @@
++data_.end_;
}
+#if !defined(BOOST_NO_SFINAE)
+
template <class U>
void push_back(U x, typename boost::move_sink<U, T>::type = 0) {
if(data_.end_ == data_.storage_end_) resize(data_.begin_ ? size() * 2 : 4);
data_.end_ = boost::uninitialized_move(&x, &x + 1, data_.end_);
- }
+ }
+
+#endif
+
private:
void resize(std::size_t new_size) {
array new_data(new_size);
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