summaryrefslogtreecommitdiffstats
path: root/src/boost/libs/functional/forward
diff options
context:
space:
mode:
Diffstat (limited to 'src/boost/libs/functional/forward')
-rw-r--r--src/boost/libs/functional/forward/index.html15
-rw-r--r--src/boost/libs/functional/forward/test/Jamfile17
-rw-r--r--src/boost/libs/functional/forward/test/forward_adapter.cpp135
-rw-r--r--src/boost/libs/functional/forward/test/lightweight_forward_adapter.cpp135
4 files changed, 302 insertions, 0 deletions
diff --git a/src/boost/libs/functional/forward/index.html b/src/boost/libs/functional/forward/index.html
new file mode 100644
index 00000000..18030298
--- /dev/null
+++ b/src/boost/libs/functional/forward/index.html
@@ -0,0 +1,15 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
+<html>
+ <head>
+ <meta http-equiv="refresh" content="0; URL=doc/html/index.html">
+ </head>
+ <body>
+ Automatic redirection failed, click this
+ <a href="doc/html/index.html">link</a> &nbsp;<hr>
+ <p>© Copyright Tobias Schwinger, 2009</p>
+ <p>Distributed under the Boost Software License, Version 1.0. (See
+ accompanying file <a href="../../../LICENSE_1_0.txt">
+ LICENSE_1_0.txt</a> or copy at
+ <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
+ </body>
+</html>
diff --git a/src/boost/libs/functional/forward/test/Jamfile b/src/boost/libs/functional/forward/test/Jamfile
new file mode 100644
index 00000000..9169456d
--- /dev/null
+++ b/src/boost/libs/functional/forward/test/Jamfile
@@ -0,0 +1,17 @@
+
+# (C) Copyright Tobias Schwinger
+#
+# Use modification and distribution are subject to the boost Software License,
+# Version 1.0. (See http:/\/www.boost.org/LICENSE_1_0.txt).
+
+import testing ;
+
+project forward-tests
+ ;
+
+test-suite functional/forward
+ :
+ [ run forward_adapter.cpp ]
+ [ run lightweight_forward_adapter.cpp ]
+ ;
+
diff --git a/src/boost/libs/functional/forward/test/forward_adapter.cpp b/src/boost/libs/functional/forward/test/forward_adapter.cpp
new file mode 100644
index 00000000..0c5e0c36
--- /dev/null
+++ b/src/boost/libs/functional/forward/test/forward_adapter.cpp
@@ -0,0 +1,135 @@
+/*=============================================================================
+ Copyright (c) 2007 Tobias Schwinger
+
+ Use modification and distribution are subject to 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).
+==============================================================================*/
+
+#include <boost/config.hpp>
+
+#ifdef BOOST_MSVC
+# pragma warning(disable: 4244) // no conversion warnings, please
+#endif
+
+#include <boost/core/lightweight_test.hpp>
+#include <boost/functional/forward_adapter.hpp>
+
+#include <boost/type_traits/is_same.hpp>
+
+#include <boost/blank.hpp>
+#include <boost/noncopyable.hpp>
+
+#include <memory>
+
+template <class Base = boost::blank>
+class test_func : public Base
+{
+ int val;
+public:
+ test_func(int v) : val(v) { }
+
+ template<class B>
+ test_func(test_func<B> const & that)
+ : val(that.val)
+ { }
+
+ template<class B> friend class test_func;
+
+ int operator()(int & l, int const & r) const
+ {
+ return l=r+val;
+ }
+ long operator()(int & l, int const & r)
+ {
+ return -(l=r+val);
+ }
+ char operator()(int& l, int& r)
+ {
+ return l=r+val;
+ }
+
+ template <typename Sig>
+ struct result
+ {
+ typedef void type;
+ };
+
+ // ensure result_of argument types are what's expected
+ // note: this is *not* how client code should look like
+ template <class Self>
+ struct result< Self const(int&,int const&) > { typedef int type; };
+
+ template <class Self>
+ struct result< Self(int&,int const&) > { typedef long type; };
+
+ template <class Self>
+ struct result< Self(int&,int&) > { typedef char type; };
+};
+
+enum { int_, long_, char_ };
+
+int type_of(int) { return int_; }
+int type_of(long) { return long_; }
+int type_of(char) { return char_; }
+
+int main()
+{
+ {
+ using boost::is_same;
+ using boost::result_of;
+ typedef boost::forward_adapter< test_func<> > f;
+
+ // lvalue,rvalue
+ BOOST_TEST(( is_same<
+ result_of< f(int&, int) >::type, long >::value ));
+ BOOST_TEST(( is_same<
+ result_of< f const (int&, int) >::type, int >::value ));
+ // lvalue,const lvalue
+ BOOST_TEST(( is_same<
+ result_of< f(int&, int const &) >::type, long >::value ));
+ BOOST_TEST(( is_same<
+ result_of< f const (int&, int const &) >::type, int >::value ));
+ // lvalue,lvalue
+ BOOST_TEST(( is_same<
+ result_of< f(int&, int&) >::type, char >::value ));
+ // result_of works differently for C++11 here, so compare
+ // with using it against test_func.
+ BOOST_TEST(( is_same<
+ result_of< f const (int&, int&) >::type,
+ result_of< test_func<> const (int&, int&)>::type >::value ));
+ }
+
+ {
+ using boost::noncopyable;
+ using boost::forward_adapter;
+
+ int x = 0;
+ test_func<noncopyable> f(7);
+ forward_adapter< test_func<> > func(f);
+ forward_adapter< test_func<noncopyable> & > func_ref(f);
+ forward_adapter< test_func<noncopyable> & > const func_ref_c(f);
+ forward_adapter< test_func<> const > func_c(f);
+ forward_adapter< test_func<> > const func_c2(f);
+ forward_adapter< test_func<noncopyable> const & > func_c_ref(f);
+
+ BOOST_TEST( type_of( func(x,1) ) == long_ );
+ BOOST_TEST( type_of( func_ref(x,1) ) == long_ );
+ BOOST_TEST( type_of( func_ref_c(x,1) ) == long_ );
+ BOOST_TEST( type_of( func_c(x,1) ) == int_ );
+ BOOST_TEST( type_of( func_c2(x,1) ) == int_ );
+ BOOST_TEST( type_of( func_c_ref(x,1) ) == int_ );
+ BOOST_TEST( type_of( func(x,x) ) == char_ );
+
+ BOOST_TEST( func(x,1) == -8 );
+ BOOST_TEST( func_ref(x,1) == -8 );
+ BOOST_TEST( func_ref_c(x,1) == -8 );
+ BOOST_TEST( func_c(x,1) == 8 );
+ BOOST_TEST( func_c2(x,1) == 8 );
+ BOOST_TEST( func_c_ref(x,1) == 8 );
+ }
+
+ return boost::report_errors();
+}
+
+
diff --git a/src/boost/libs/functional/forward/test/lightweight_forward_adapter.cpp b/src/boost/libs/functional/forward/test/lightweight_forward_adapter.cpp
new file mode 100644
index 00000000..b89c92ad
--- /dev/null
+++ b/src/boost/libs/functional/forward/test/lightweight_forward_adapter.cpp
@@ -0,0 +1,135 @@
+/*=============================================================================
+ Copyright (c) 2007 Tobias Schwinger
+
+ Use modification and distribution are subject to 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).
+==============================================================================*/
+
+#include <boost/config.hpp>
+
+#ifdef BOOST_MSVC
+# pragma warning(disable: 4244) // no conversion warnings, please
+#endif
+
+#include <boost/core/lightweight_test.hpp>
+#include <boost/functional/lightweight_forward_adapter.hpp>
+
+#include <boost/type_traits/is_same.hpp>
+
+#include <boost/blank.hpp>
+#include <boost/noncopyable.hpp>
+
+#include <memory>
+
+template <class Base = boost::blank>
+class test_func : public Base
+{
+ int val;
+public:
+ test_func(int v) : val(v) { }
+
+ template<class B>
+ test_func(test_func<B> const & that)
+ : val(that.val)
+ { }
+
+ template<class B> friend class test_func;
+
+ int operator()(int & l, int const & r) const
+ {
+ return l=r+val;
+ }
+ long operator()(int & l, int const & r)
+ {
+ return -(l=r+val);
+ }
+ char operator()(int & l, int & r)
+ {
+ return l=r+val;
+ }
+
+ template <typename Sig>
+ struct result
+ {
+ typedef void type;
+ };
+
+ // ensure result_of argument types are what's expected
+ // note: this is *not* how client code should look like
+ template <class Self>
+ struct result< Self const(int&,int const&) > { typedef int type; };
+
+ template <class Self>
+ struct result< Self(int&,int const&) > { typedef long type; };
+
+ template <class Self>
+ struct result< Self(int&,int&) > { typedef char type; };
+};
+
+enum { int_, long_, char_ };
+
+int type_of(int) { return int_; }
+int type_of(long) { return long_; }
+int type_of(char) { return char_; }
+
+int main()
+{
+ {
+ using boost::is_same;
+ using boost::result_of;
+ typedef boost::lightweight_forward_adapter< test_func<> > f;
+ typedef boost::reference_wrapper<int> ref;
+ typedef boost::reference_wrapper<int const> cref;
+
+ // lvalue,rvalue
+ BOOST_TEST(( is_same<
+ result_of< f(ref, int) >::type, long >::value ));
+ BOOST_TEST(( is_same<
+ result_of< f const (ref, int) >::type, int >::value ));
+ // lvalue,const lvalue
+ BOOST_TEST(( is_same<
+ result_of< f(ref, cref) >::type, long >::value ));
+ BOOST_TEST(( is_same<
+ result_of< f const (ref, cref) >::type, int >::value ));
+ // lvalue,lvalue
+ BOOST_TEST(( is_same<
+ result_of< f(ref, ref) >::type, char >::value ));
+ // result_of works differently for C++11 here, so compare
+ // with using it against test_func.
+ BOOST_TEST(( is_same<
+ result_of< f const (ref, ref) >::type,
+ result_of< test_func<> const (int&, int&) >::type >::value ));
+ }
+ {
+ using boost::noncopyable;
+ using boost::lightweight_forward_adapter;
+
+ int v = 0; boost::reference_wrapper<int> x(v);
+ test_func<noncopyable> f(7);
+ lightweight_forward_adapter< test_func<> > func(f);
+ lightweight_forward_adapter< test_func<noncopyable> & > func_ref(f);
+ lightweight_forward_adapter< test_func<noncopyable> & > const func_ref_c(f);
+ lightweight_forward_adapter< test_func<> const > func_c(f);
+ lightweight_forward_adapter< test_func<> > const func_c2(f);
+ lightweight_forward_adapter< test_func<noncopyable> const & > func_c_ref(f);
+
+ BOOST_TEST( type_of( func(x,1) ) == long_ );
+ BOOST_TEST( type_of( func_ref(x,1) ) == long_ );
+ BOOST_TEST( type_of( func_ref_c(x,1) ) == long_ );
+ BOOST_TEST( type_of( func_c(x,1) ) == int_ );
+ BOOST_TEST( type_of( func_c2(x,1) ) == int_ );
+ BOOST_TEST( type_of( func_c_ref(x,1) ) == int_ );
+ BOOST_TEST( type_of( func(x,x) ) == char_ );
+
+ BOOST_TEST( func(x,1) == -8 );
+ BOOST_TEST( func_ref(x,1) == -8 );
+ BOOST_TEST( func_ref_c(x,1) == -8 );
+ BOOST_TEST( func_c(x,1) == 8 );
+ BOOST_TEST( func_c2(x,1) == 8 );
+ BOOST_TEST( func_c_ref(x,1) == 8 );
+ }
+
+ return boost::report_errors();
+}
+