Update of /cvsroot/boost/boost/boost/utility
In directory sc8-pr-cvs3.sourceforge.net:/tmp/cvs-serv14241

Modified Files:
        in_place_factory.hpp typed_in_place_factory.hpp 
Log Message:
- overloads apply for array construction
- adds support for zero arguments
- lets apply return the result of the new-expression
- revises the preprocessing code


Index: in_place_factory.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/utility/in_place_factory.hpp,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- in_place_factory.hpp        23 Sep 2004 17:03:54 -0000      1.6
+++ in_place_factory.hpp        26 Jun 2007 23:07:25 -0000      1.7
@@ -1,4 +1,5 @@
 // Copyright (C) 2003, Fernando Luis Cacciola Carballal.
+// Copyright (C) 2007, Tobias Schwinger.
 //
 // Use, modification, and distribution is subject to the Boost Software
 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,50 +10,79 @@
 // You are welcome to contact the author at:
 //  [EMAIL PROTECTED]
 //
-#ifndef BOOST_UTILITY_INPLACE_FACTORY_25AGO2003_HPP
-#define BOOST_UTILITY_INPLACE_FACTORY_25AGO2003_HPP
+#ifndef BOOST_UTILITY_INPLACE_FACTORY_04APR2007_HPP
+#ifndef BOOST_PP_IS_ITERATING
 
 #include <boost/utility/detail/in_place_factory_prefix.hpp>
 
-#include <boost/type.hpp>
-
 namespace boost {
 
 class in_place_factory_base {} ;
 
-#define BOOST_DEFINE_INPLACE_FACTORY_CLASS(z,n,_) \
-template< BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n),class A) > \
-class BOOST_PP_CAT(in_place_factory, BOOST_PP_INC(n) ) : public 
in_place_factory_base \
-{ \
-public: \
-\
-  BOOST_PP_CAT(in_place_factory, BOOST_PP_INC(n) ) ( 
BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_INC(n),A,const& a) ) \
-    : \
-    BOOST_PP_ENUM( BOOST_PP_INC(n), 
BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT, _ ) \
-  {} \
-\
-  template<class T> \
-  void apply ( void* address BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T) ) const \
-  { \
-    new ( address ) T ( BOOST_PP_ENUM_PARAMS( BOOST_PP_INC(n), m_a ) ) ; \
-  } \
-\
-  BOOST_PP_REPEAT( BOOST_PP_INC(n), 
BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL, _) \
-} ; \
-\
-template< BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n),class A) > \
-BOOST_PP_CAT(in_place_factory, BOOST_PP_INC(n) ) < BOOST_PP_ENUM_PARAMS( 
BOOST_PP_INC(n), A ) > \
-in_place ( BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_INC(n),A, const& a) ) \
-{ \
-  return BOOST_PP_CAT(in_place_factory, BOOST_PP_INC(n) ) < 
BOOST_PP_ENUM_PARAMS( BOOST_PP_INC(n), A ) > \
-           ( BOOST_PP_ENUM_PARAMS( BOOST_PP_INC(n), a ) ) ; \
-} ; \
-
-BOOST_PP_REPEAT( BOOST_MAX_INPLACE_FACTORY_ARITY, 
BOOST_DEFINE_INPLACE_FACTORY_CLASS, BOOST_PP_EMPTY() )
+#define  BOOST_PP_ITERATION_LIMITS (0, BOOST_MAX_INPLACE_FACTORY_ARITY)
+#define  BOOST_PP_FILENAME_1 <boost/utility/in_place_factory.hpp>
+#include BOOST_PP_ITERATE()
 
 } // namespace boost
 
 #include <boost/utility/detail/in_place_factory_suffix.hpp>
 
+#define BOOST_UTILITY_INPLACE_FACTORY_04APR2007_HPP
+#else
+#define N BOOST_PP_ITERATION()
+
+#if N
+template< BOOST_PP_ENUM_PARAMS(N, class A) >
+#endif
+class BOOST_PP_CAT(in_place_factory,N)
+  : 
+  public in_place_factory_base
+{
+public:
+
+  explicit BOOST_PP_CAT(in_place_factory,N)
+      ( BOOST_PP_ENUM_BINARY_PARAMS(N,A,const& a) )
+#if N > 0
+    : BOOST_PP_ENUM(N, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT, _)
+#endif
+  {}
+
+  template<class T>
+  void* apply(void* address
+      BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) const
+  {
+    return new(address) T( BOOST_PP_ENUM_PARAMS(N, m_a) );
+  }
+
+  template<class T>
+  void* apply(void* address, std::size_t n
+      BOOST_APPEND_EXPLICIT_TEMPLATE_TYPE(T)) const
+  {
+    for(char* next = address = this->BOOST_NESTED_TEMPLATE apply<T>(address);
+        !! --n;)
+      this->BOOST_NESTED_TEMPLATE apply<T>(next = next+sizeof(T));
+    return address; 
+  }
+
+  BOOST_PP_REPEAT(N, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL, _)
+};
+
+#if N > 0
+template< BOOST_PP_ENUM_PARAMS(N, class A) >
+inline BOOST_PP_CAT(in_place_factory,N)< BOOST_PP_ENUM_PARAMS(N, A) >
+in_place( BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& a) )
+{
+  return BOOST_PP_CAT(in_place_factory,N)< BOOST_PP_ENUM_PARAMS(N, A) >
+      ( BOOST_PP_ENUM_PARAMS(N, a) );
+}
+#else
+inline in_place_factory0 in_place()
+{
+  return in_place_factory0();
+}
+#endif
+
+#undef N
+#endif
 #endif
 

Index: typed_in_place_factory.hpp
===================================================================
RCS file: /cvsroot/boost/boost/boost/utility/typed_in_place_factory.hpp,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -d -r1.5 -r1.6
--- typed_in_place_factory.hpp  23 Sep 2004 17:03:54 -0000      1.5
+++ typed_in_place_factory.hpp  26 Jun 2007 23:07:25 -0000      1.6
@@ -1,4 +1,5 @@
 // Copyright (C) 2003, Fernando Luis Cacciola Carballal.
+// Copyright (C) 2007, Tobias Schwinger.
 //
 // Use, modification, and distribution is subject to the Boost Software
 // License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
@@ -9,8 +10,8 @@
 // You are welcome to contact the author at:
 //  [EMAIL PROTECTED]
 //
-#ifndef BOOST_UTILITY_TYPED_INPLACE_FACTORY_25AGO2003_HPP
-#define BOOST_UTILITY_TYPED_INPLACE_FACTORY_25AGO2003_HPP
+#ifndef BOOST_UTILITY_TYPED_INPLACE_FACTORY_04APR2007_HPP
+#ifndef BOOST_PP_IS_ITERATING
 
 #include <boost/utility/detail/in_place_factory_prefix.hpp>
 
@@ -18,40 +19,59 @@
 
 class typed_in_place_factory_base {} ;
 
-#define BOOST_DEFINE_TYPED_INPLACE_FACTORY_CLASS(z,n,_) \
-template< class T, BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n),class A) > \
-class BOOST_PP_CAT(typed_in_place_factory, BOOST_PP_INC(n) ) : public 
typed_in_place_factory_base \
-{ \
-public: \
-\
-  typedef T value_type ; \
-\
-  BOOST_PP_CAT(typed_in_place_factory, BOOST_PP_INC(n) ) ( 
BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_INC(n),A,const& a) ) \
-    : \
-    BOOST_PP_ENUM( BOOST_PP_INC(n), 
BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT, _ ) \
-  {} \
-\
-  void apply ( void* address ) const \
-  { \
-    new ( address ) T ( BOOST_PP_ENUM_PARAMS( BOOST_PP_INC(n), m_a ) ) ; \
-  } \
-\
-  BOOST_PP_REPEAT( BOOST_PP_INC(n), 
BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL, _) \
-} ; \
-\
-template< class T, BOOST_PP_ENUM_PARAMS(BOOST_PP_INC(n),class A) > \
-BOOST_PP_CAT(typed_in_place_factory, BOOST_PP_INC(n) ) < T , 
BOOST_PP_ENUM_PARAMS( BOOST_PP_INC(n), A ) > \
-in_place ( BOOST_PP_ENUM_BINARY_PARAMS(BOOST_PP_INC(n),A, const& a) ) \
-{ \
-  return BOOST_PP_CAT(typed_in_place_factory, BOOST_PP_INC(n) ) < T, 
BOOST_PP_ENUM_PARAMS( BOOST_PP_INC(n), A ) > \
-           ( BOOST_PP_ENUM_PARAMS( BOOST_PP_INC(n), a ) ) ; \
-} ; \
-
-BOOST_PP_REPEAT( BOOST_MAX_INPLACE_FACTORY_ARITY, 
BOOST_DEFINE_TYPED_INPLACE_FACTORY_CLASS, BOOST_PP_EMPTY() )
+#define  BOOST_PP_ITERATION_LIMITS (0, BOOST_MAX_INPLACE_FACTORY_ARITY)
+#define  BOOST_PP_FILENAME_1 <boost/utility/typed_in_place_factory.hpp>
+#include BOOST_PP_ITERATE()
 
 } // namespace boost
 
 #include <boost/utility/detail/in_place_factory_suffix.hpp>
 
+#define BOOST_UTILITY_TYPED_INPLACE_FACTORY_04APR2007_HPP
+#else 
+#define N BOOST_PP_ITERATION()
+
+template< class T BOOST_PP_ENUM_TRAILING_PARAMS(N,class A) >
+class BOOST_PP_CAT(typed_in_place_factory,N) 
+  : 
+  public typed_in_place_factory_base
+{
+public:
+
+  typedef T value_type;
+
+  explicit BOOST_PP_CAT(typed_in_place_factory,N) 
+      ( BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& a) )
+#if N > 0
+    : BOOST_PP_ENUM(N, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_INIT, _)
+#endif
+  {}
+
+  void* apply (void* address) const
+  {
+    return new(address) T( BOOST_PP_ENUM_PARAMS(N, m_a) );
+  }
+
+  void* apply (void* address, std::size_t n) const
+  {
+    for(char* next = address = this->apply(address); !! --n;)
+      this->apply(next = next+sizeof(T));
+    return address; 
+  }
+
+  BOOST_PP_REPEAT(N, BOOST_DEFINE_INPLACE_FACTORY_CLASS_MEMBER_DECL, _)
+};
+
+template< class T BOOST_PP_ENUM_TRAILING_PARAMS(N, class A) >
+inline BOOST_PP_CAT(typed_in_place_factory,N)<
+    T BOOST_PP_ENUM_TRAILING_PARAMS(N, A) >
+in_place( BOOST_PP_ENUM_BINARY_PARAMS(N, A, const& a) )
+{
+  return BOOST_PP_CAT(typed_in_place_factory,N)< 
+      T BOOST_PP_ENUM_TRAILING_PARAMS(N, A) >( BOOST_PP_ENUM_PARAMS(N, a) );
+}
+
+#undef N
+#endif
 #endif
 


-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Boost-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/boost-cvs

Reply via email to