Squashed 'third_party/boostorg/functional/' content from commit 7516442

Change-Id: I0e437294bc2af9d32de5022be6ac788cc67244d1
git-subtree-dir: third_party/boostorg/functional
git-subtree-split: 7516442815900430cc9c4a6190354e11bcbe72dd
diff --git a/factory/test/Jamfile b/factory/test/Jamfile
new file mode 100644
index 0000000..c4a06af
--- /dev/null
+++ b/factory/test/Jamfile
@@ -0,0 +1,24 @@
+
+# (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 factory-tests
+    ;
+
+test-suite functional/factory
+    :
+      [ run value_factory.cpp ]
+      [ run factory.cpp ]
+      [ run factory_with_allocator.cpp ]
+      [ run factory_with_std_allocator.cpp ]
+      [ compile-fail factory_with_none_t.cpp ]
+      [ run factory.cpp : : : <define>BOOST_FUNCTIONAL_FACTORY_SUPPORT_NONE_T : none_t_factory ]
+      [ run factory_with_allocator.cpp : : : <define>BOOST_FUNCTIONAL_FACTORY_SUPPORT_NONE_T : none_t_factory_with_allocator ]
+      [ run factory_with_std_allocator.cpp : : : <define>BOOST_FUNCTIONAL_FACTORY_SUPPORT_NONE_T : none_t_factory_with_std_allocator ]
+      [ run factory_with_none_t.cpp : : : <define>BOOST_FUNCTIONAL_FACTORY_SUPPORT_NONE_T : none_t_factory_with_none_t ]
+    ;
+
diff --git a/factory/test/factory.cpp b/factory/test/factory.cpp
new file mode 100644
index 0000000..ef895cf
--- /dev/null
+++ b/factory/test/factory.cpp
@@ -0,0 +1,53 @@
+/*=============================================================================
+    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/functional/factory.hpp>
+#include <boost/core/lightweight_test.hpp>
+
+#include <memory>
+
+class sum
+{
+    int val_sum;
+  public:
+    sum(int a, int b) : val_sum(a + b) { }
+
+    operator int() const { return this->val_sum; }
+};
+
+// Suppress warnings about std::auto_ptr.
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
+int main()
+{
+    int one = 1, two = 2;
+    {
+      sum* instance( boost::factory< sum* >()(one,two) );
+      BOOST_TEST(*instance == 3);
+    }
+#if !defined(BOOST_NO_AUTO_PTR)
+    {
+      std::auto_ptr<sum> instance( boost::factory< std::auto_ptr<sum> >()(one,two) );
+      BOOST_TEST(*instance == 3);
+    }
+#endif
+#if !defined(BOOST_NO_CXX11_SMART_PTR)
+    {
+      std::unique_ptr<sum> instance( boost::factory< std::unique_ptr<sum> >()(one,two) );
+      BOOST_TEST(*instance == 3);
+    }
+#endif
+    return boost::report_errors();
+}
+
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
diff --git a/factory/test/factory_with_allocator.cpp b/factory/test/factory_with_allocator.cpp
new file mode 100644
index 0000000..c1eef65
--- /dev/null
+++ b/factory/test/factory_with_allocator.cpp
@@ -0,0 +1,84 @@
+/*=============================================================================
+    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/functional/factory.hpp>
+#include <boost/core/lightweight_test.hpp>
+
+#include <cstddef>
+#include <memory>
+#include <boost/shared_ptr.hpp>
+
+#ifdef BOOST_MSVC
+// none of the deprecated members of std::allocate are used here
+# pragma warning(disable:4996) // Various members of std::allocator are deprecated in C++17
+#endif
+
+using std::size_t;
+
+class sum 
+{
+    int val_sum;
+  public:
+    sum(int a, int b) : val_sum(a + b) { }
+
+    operator int() const { return this->val_sum; }
+};
+
+template< typename T >
+class counting_allocator : public std::allocator<T>
+{
+  public:
+    counting_allocator()
+    { }
+
+    template< typename OtherT >
+    struct rebind { typedef counting_allocator<OtherT> other; };
+
+    template< typename OtherT >
+    counting_allocator(counting_allocator<OtherT> const& that)
+    { }
+
+    static size_t n_allocated;
+    T* allocate(size_t n, void const* hint = 0l)
+    {
+        n_allocated += 1;
+        return std::allocator<T>::allocate(n,hint);
+    }
+
+    static size_t n_deallocated;
+    void deallocate(T* ptr, size_t n)
+    {
+        n_deallocated += 1;
+        return std::allocator<T>::deallocate(ptr,n);
+    }
+};
+template< typename T > size_t counting_allocator<T>::n_allocated = 0;
+template< typename T > size_t counting_allocator<T>::n_deallocated = 0;
+
+int main()
+{
+    int one = 1, two = 2;
+    {
+      boost::shared_ptr<sum> instance(
+          boost::factory< boost::shared_ptr<sum>, counting_allocator<void>, 
+              boost::factory_alloc_for_pointee_and_deleter >()(one,two) );
+      BOOST_TEST(*instance == 3);
+    }
+    BOOST_TEST(counting_allocator<sum>::n_allocated == 1); 
+    BOOST_TEST(counting_allocator<sum>::n_deallocated == 1);
+    {
+      boost::shared_ptr<sum> instance(
+          boost::factory< boost::shared_ptr<sum>, counting_allocator<void>,
+              boost::factory_passes_alloc_to_smart_pointer >()(one,two) );
+      BOOST_TEST(*instance == 3);
+    }
+    BOOST_TEST(counting_allocator<sum>::n_allocated == 2); 
+    BOOST_TEST(counting_allocator<sum>::n_deallocated == 2);
+    return boost::report_errors();
+}
+
diff --git a/factory/test/factory_with_none_t.cpp b/factory/test/factory_with_none_t.cpp
new file mode 100644
index 0000000..e8a515a
--- /dev/null
+++ b/factory/test/factory_with_none_t.cpp
@@ -0,0 +1,56 @@
+/*=============================================================================
+    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/functional/factory.hpp>
+#include <boost/core/lightweight_test.hpp>
+#include <boost/none_t.hpp>
+
+#include <memory>
+
+class sum
+{
+    int val_sum;
+  public:
+    sum(int a, int b) : val_sum(a + b) { }
+
+    operator int() const { return this->val_sum; }
+};
+
+// Suppress warnings about std::auto_ptr.
+#if defined(__clang__)
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wdeprecated-declarations"
+#endif
+
+int main()
+{
+    int one = 1, two = 2;
+    {
+      sum* instance( boost::factory< sum*, boost::none_t >()(one,two) );
+      BOOST_TEST(*instance == 3);
+    }
+#if !defined(BOOST_NO_AUTO_PTR)
+    {
+      std::auto_ptr<sum> instance(
+              boost::factory< std::auto_ptr<sum>, boost::none_t >()(one,two) );
+      BOOST_TEST(*instance == 3);
+    }
+#endif
+#if !defined(BOOST_NO_CXX11_SMART_PTR)
+    {
+      std::unique_ptr<sum> instance(
+              boost::factory< std::unique_ptr<sum>, boost::none_t >()(one,two) );
+      BOOST_TEST(*instance == 3);
+    }
+#endif
+    return boost::report_errors();
+}
+
+#if defined(__clang__)
+#pragma clang diagnostic pop
+#endif
diff --git a/factory/test/factory_with_std_allocator.cpp b/factory/test/factory_with_std_allocator.cpp
new file mode 100644
index 0000000..2a58a60
--- /dev/null
+++ b/factory/test/factory_with_std_allocator.cpp
@@ -0,0 +1,45 @@
+/*=============================================================================
+    Copyright (c) 2007 Tobias Schwinger
+    Copyright (c) 2017 Daniel James
+
+    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/functional/factory.hpp>
+#include <boost/detail/lightweight_test.hpp>
+
+#include <cstddef>
+#include <memory>
+#include <boost/shared_ptr.hpp>
+
+class sum
+{
+    int val_sum;
+  public:
+    sum(int a, int b) : val_sum(a + b) { }
+
+    operator int() const { return this->val_sum; }
+};
+
+int main()
+{
+    int one = 1, two = 2;
+    {
+      boost::shared_ptr<sum> instance(
+          boost::factory< boost::shared_ptr<sum>, std::allocator<int>,
+              boost::factory_alloc_for_pointee_and_deleter >()(one,two) );
+      BOOST_TEST(*instance == 3);
+    }
+
+    {
+      boost::shared_ptr<sum> instance(
+          boost::factory< boost::shared_ptr<sum>, std::allocator<int>,
+              boost::factory_passes_alloc_to_smart_pointer >()(one,two) );
+      BOOST_TEST(*instance == 3);
+    }
+
+    return boost::report_errors();
+}
+
diff --git a/factory/test/value_factory.cpp b/factory/test/value_factory.cpp
new file mode 100644
index 0000000..331757d
--- /dev/null
+++ b/factory/test/value_factory.cpp
@@ -0,0 +1,29 @@
+/*=============================================================================
+    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/functional/value_factory.hpp>
+#include <boost/core/lightweight_test.hpp>
+
+class sum 
+{
+    int val_sum;
+  public:
+    sum(int a, int b) : val_sum(a + b) { }
+    operator int() const { return this->val_sum; }
+};
+
+int main()
+{
+    int one = 1, two = 2;
+    {
+      sum instance( boost::value_factory< sum >()(one,two) );
+      BOOST_TEST(instance == 3);
+    }
+    return boost::report_errors();
+}
+