In common.h, define func_lib for function objects. In configure.ac, define HAVE_STD_FUNCTION and HAVE_BOOST_FUNCTION. Include function headers in ndnboost.
diff --git a/libs/functional/factory/test/Jamfile b/libs/functional/factory/test/Jamfile
new file mode 100644
index 0000000..6c4f6eb
--- /dev/null
+++ b/libs/functional/factory/test/Jamfile
@@ -0,0 +1,18 @@
+
+# (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 ]
+ ;
+
diff --git a/libs/functional/factory/test/factory.cpp b/libs/functional/factory/test/factory.cpp
new file mode 100644
index 0000000..4d47f28
--- /dev/null
+++ b/libs/functional/factory/test/factory.cpp
@@ -0,0 +1,36 @@
+/*=============================================================================
+ 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/detail/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; }
+};
+
+int main()
+{
+ int one = 1, two = 2;
+ {
+ sum* instance( ndnboost::factory< sum* >()(one,two) );
+ BOOST_TEST(*instance == 3);
+ }
+ {
+ std::auto_ptr<sum> instance( ndnboost::factory< std::auto_ptr<sum> >()(one,two) );
+ BOOST_TEST(*instance == 3);
+ }
+ return ndnboost::report_errors();
+}
+
diff --git a/libs/functional/factory/test/factory_with_allocator.cpp b/libs/functional/factory/test/factory_with_allocator.cpp
new file mode 100644
index 0000000..b2c6c99
--- /dev/null
+++ b/libs/functional/factory/test/factory_with_allocator.cpp
@@ -0,0 +1,79 @@
+/*=============================================================================
+ 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/detail/lightweight_test.hpp>
+
+#include <cstddef>
+#include <memory>
+#include <boost/shared_ptr.hpp>
+
+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;
+ {
+ ndnboost::shared_ptr<sum> instance(
+ ndnboost::factory< ndnboost::shared_ptr<sum>, counting_allocator<void>,
+ ndnboost::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);
+ {
+ ndnboost::shared_ptr<sum> instance(
+ ndnboost::factory< ndnboost::shared_ptr<sum>, counting_allocator<void>,
+ ndnboost::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 ndnboost::report_errors();
+}
+
diff --git a/libs/functional/factory/test/value_factory.cpp b/libs/functional/factory/test/value_factory.cpp
new file mode 100644
index 0000000..5462ffb
--- /dev/null
+++ b/libs/functional/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/detail/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( ndnboost::value_factory< sum >()(one,two) );
+ BOOST_TEST(instance == 3);
+ }
+ return ndnboost::report_errors();
+}
+