$include_dir="/home/hyper-archives/boost-commit/include"; include("$include_dir/msg-header.inc") ?>
Subject: [Boost-commit] svn:boost r54518 - in sandbox/monotonic: boost/heterogenous libs/monotonic/test/clones
From: christian.schladetsch_at_[hidden]
Date: 2009-06-30 01:01:46
Author: cschladetsch
Date: 2009-06-30 01:01:44 EDT (Tue, 30 Jun 2009)
New Revision: 54518
URL: http://svn.boost.org/trac/boost/changeset/54518
Log:
added heterogenous::adaptor
Added:
   sandbox/monotonic/boost/heterogenous/adaptor.hpp   (contents, props changed)
Text files modified: 
   sandbox/monotonic/boost/heterogenous/forward_declarations.hpp |    10 ++++++++++                              
   sandbox/monotonic/libs/monotonic/test/clones/clones.vcproj    |     4 ++++                                    
   sandbox/monotonic/libs/monotonic/test/clones/tests.cpp        |    26 ++++++++++++--------------              
   3 files changed, 26 insertions(+), 14 deletions(-)
Added: sandbox/monotonic/boost/heterogenous/adaptor.hpp
==============================================================================
--- (empty file)
+++ sandbox/monotonic/boost/heterogenous/adaptor.hpp	2009-06-30 01:01:44 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,46 @@
+// Copyright (C) 2009 Christian Schladetsch
+//
+//  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)
+
+#ifndef BOOST_HETEROGENOUS_ADAPTOR_HPP
+#define BOOST_HETEROGENOUS_ADAPTOR_HPP
+
+#include <boost/heterogenous/detail/prefix.hpp>
+#include <boost/heterogenous/base.hpp>
+
+namespace boost
+{
+	namespace heterogenous
+	{
+		/// an adaptor for an existing class
+		///
+		/// this is a type that can be used correctly in an homogenous container
+		template <class T, class Base, class AbstractBase>
+		struct adaptor : T, base<adaptor<T,Base,AbstractBase>, Base, AbstractBase>
+		{
+			adaptor() { }
+
+			template <class A0>
+			adaptor(A0 a0) : T(a0)
+			{
+			}
+			template <class A0, class A1>
+			adaptor(A0 a0, A1 a1) : T(a0, a1)
+			{
+			}
+			template <class A0, class A1, class A2>
+			adaptor(A0 a0, A1 a1, A2 a2) : T(a0, a1, a2)
+			{
+			}
+		};
+
+	} // namespace heterogenous
+
+} // namespace boost
+
+#include <boost/heterogenous/detail/suffix.hpp>
+
+#endif // BOOST_HETEROGENOUS_ADAPTOR_HPP
+
+//EOF
Modified: sandbox/monotonic/boost/heterogenous/forward_declarations.hpp
==============================================================================
--- sandbox/monotonic/boost/heterogenous/forward_declarations.hpp	(original)
+++ sandbox/monotonic/boost/heterogenous/forward_declarations.hpp	2009-06-30 01:01:44 EDT (Tue, 30 Jun 2009)
@@ -27,6 +27,16 @@
                         , class AbstractBase = abstract_base<Base> >
                 struct base;
 
+		/// an adaptor for an existing class.
+		///
+		/// this is a type that can be used correctly in an homogenous container,
+		/// of effective type T, where T does not inherit from heterogenous::base.
+		template <
+			class T
+			, class Base = default_base_type
+			, class AbstractBase = abstract_base<Base> >
+		struct adaptor;
+
                 template <
                         class Base = default_base_type
                         , class Alloc = monotonic::allocator<int>
Modified: sandbox/monotonic/libs/monotonic/test/clones/clones.vcproj
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/clones/clones.vcproj	(original)
+++ sandbox/monotonic/libs/monotonic/test/clones/clones.vcproj	2009-06-30 01:01:44 EDT (Tue, 30 Jun 2009)
@@ -365,6 +365,10 @@
 					>
                                 </File>
                                 <File
+					RelativePath="..\..\..\..\boost\heterogenous\adaptor.hpp"
+					>
+				</File>
+				<File
                                         RelativePath="..\..\..\..\boost\heterogenous\allocator.hpp"
 					>
                                 </File>
Modified: sandbox/monotonic/libs/monotonic/test/clones/tests.cpp
==============================================================================
--- sandbox/monotonic/libs/monotonic/test/clones/tests.cpp	(original)
+++ sandbox/monotonic/libs/monotonic/test/clones/tests.cpp	2009-06-30 01:01:44 EDT (Tue, 30 Jun 2009)
@@ -10,6 +10,7 @@
 #include <iostream>
 #include <boost/heterogenous/vector.hpp>
 #include <boost/heterogenous/map.hpp>
+#include <boost/heterogenous/adaptor.hpp>
 #include <boost/bind.hpp>
 #include <boost/any.hpp>
 #include <boost/variant.hpp>
@@ -95,14 +96,16 @@
         }
 }
 
-namespace boost
+/// some external type that we cannot change
+struct ExternalType
 {
-	namespace heterogenous
-	{
-		//template <class T, template <class> class Base = base, class AbstractBase = abstract_base>
-		//struct adaptor : 
-	}
-}
+	std::string text;
+	ExternalType() { }
+	ExternalType(const char *T) : text(T) { }
+};
+
+/// make an adaptor type, which makes `ExternalType` heterogenous
+typedef heterogenous::adaptor<ExternalType, my_base> T4;
 
 int main()
 {
@@ -112,9 +115,6 @@
         test_variant();
         test_map();
 
-
-
-
         // a 'heterogenous' container of objects of any type that derives from common_base
         typedef heterogenous::vector<my_base> vec;
 
@@ -126,17 +126,14 @@
                 bases.emplace_back<derived>(42);						
                 bases.emplace_back<derived2>("foo");
                 bases.emplace_back<derived3>(3.14f, -123, "spam");
+		bases.emplace_back<T4>("external");
 
                 // perform functor on each contained object of the given type
                 bases.for_each<derived3>(boost::bind(&derived3::print, _1));
 
-		BOOST_ASSERT(bases.size() == 3);
-
                 // does a deep copy, preserving concrete types
                 vec copy = bases;
 
-		BOOST_ASSERT(copy.size() == 3);
-
                 // each object in the container can be retrieved generically as a default_base_type
                 my_base &generic0 = copy[0];
                 my_base &generic1 = copy[1];
@@ -155,6 +152,7 @@
                 BOOST_ASSERT(p1.num == 42);
                 BOOST_ASSERT(p2->str == "foo");
                 BOOST_ASSERT(p3->real == 3.14f);BOOST_ASSERT(p3->num == -123);BOOST_ASSERT(p3->str == "spam");
+		BOOST_ASSERT(copy.ref_at<T4>(3).text == "external");
 
                 bool caught = false;
                 try