Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54555 - in sandbox: cloneable/boost/cloneable cloneable/libs/cloneable/test monotonic/boost/ptr_container
From: christian.schladetsch_at_[hidden]
Date: 2009-06-30 20:55:42


Author: cschladetsch
Date: 2009-06-30 20:55:41 EDT (Tue, 30 Jun 2009)
New Revision: 54555
URL: http://svn.boost.org/trac/boost/changeset/54555

Log:
added cloneable/set.hpp

Added:
   sandbox/cloneable/boost/cloneable/set.hpp (contents, props changed)
Text files modified:
   sandbox/cloneable/boost/cloneable/forward_declarations.hpp | 19 ++++++++++++---
   sandbox/cloneable/libs/cloneable/test/cloneable.vcproj | 4 +++
   sandbox/cloneable/libs/cloneable/test/tests.cpp | 50 ++++++++++++++++++++++++++++++++++++---
   sandbox/monotonic/boost/ptr_container/indirect_fun.hpp | 7 +++--
   sandbox/monotonic/boost/ptr_container/ptr_set_adapter.hpp | 2
   5 files changed, 70 insertions(+), 12 deletions(-)

Modified: sandbox/cloneable/boost/cloneable/forward_declarations.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/forward_declarations.hpp (original)
+++ sandbox/cloneable/boost/cloneable/forward_declarations.hpp 2009-06-30 20:55:41 EDT (Tue, 30 Jun 2009)
@@ -54,20 +54,31 @@
 
                 // TODO: move to boost/heterogenous/foward
                 /// a heterogenous vector of objects
- template <
+ template
+ <
                         class Base = default_base_type
                         , class Alloc = monotonic::allocator<int>
- >//, class AbstractBase = abstract_cloneable<Base> >
+ >
                 struct vector;
 
                 /// a mapping of heterogenous objects to heterogenous objects
- template <
+ template
+ <
                         class Base = default_base_type
                         , class Pred = std::less<Base>
                         , class Alloc = monotonic::allocator<int>
- >//, class AbstractBase = abstract_cloneable<Base> >
+ >
                 struct map;
 
+ /// a set of heterogenous objects
+ template
+ <
+ class Base = default_base_type
+ , class Pred = std::less<Base>
+ , class Alloc = monotonic::allocator<int>
+ >
+ struct set;
+
         } // namespace cloneable
 
 } // namespace boost

Added: sandbox/cloneable/boost/cloneable/set.hpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/boost/cloneable/set.hpp 2009-06-30 20:55:41 EDT (Tue, 30 Jun 2009)
@@ -0,0 +1,138 @@
+// 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_CLONEABLE_SET_HPP
+#define BOOST_CLONEABLE_SET_HPP
+
+#include <boost/ptr_container/ptr_set.hpp>
+#include <boost/foreach.hpp>
+
+#include <boost/cloneable/detail/make_clone_allocator.hpp>
+
+namespace boost
+{
+ namespace cloneable
+ {
+ /// a vector of heterogenous objects
+ // TODO: move to boost/heterogenous/map
+ template <class Base, class Pred, class Alloc>
+ struct set
+ {
+ typedef typename detail::make_clone_allocator<Alloc>::type allocator_type;
+ typedef Base base_type;
+ typedef Pred predicate_type;
+ typedef abstract_base<Base> abstract_base_type;
+
+ typedef ptr_set<abstract_base_type, predicate_type, allocator, allocator_type> implementation;
+
+ typedef typename implementation::value_type value_type;
+ typedef typename implementation::reference reference;
+ typedef typename implementation::const_reference const_reference;
+ typedef typename implementation::iterator iterator;
+ typedef typename implementation::const_iterator const_iterator;
+ typedef map<Base, Pred, Alloc/*, AbstractBase*/> this_type;
+
+ private:
+ implementation impl;
+
+ public:
+ set()
+ {
+ }
+ set(allocator_type a)
+ : impl(a)
+ {
+ }
+
+ /* purposefully elided
+ template <class II>
+ set(II F, II L, allocator_type a = allocator_type());
+ */
+
+
+ public:
+ typedef std::pair<iterator, bool> emplace_result;
+ template <class U>
+ emplace_result emplace()
+ {
+ abstract_base_type *instance = detail::construct<U,base_type>(get_allocator()).to_abstract();
+ return impl.insert(instance);
+ }
+
+ // TODO: use variadic arguments or BOOST_PP to pass ctor args
+ template <class U, class A0>
+ emplace_result emplace(A0 a0)
+ {
+ abstract_base_type *instance = detail::construct<U,base_type>(get_allocator(), a0).to_abstract();
+ return impl.insert(instance);
+ }
+ template <class U, class A0, class A1>
+ emplace_result emplace(A0 a0, A1 a1)
+ {
+ abstract_base_type *instance = detail::construct<U,base_type>(get_allocator(), a0, a1).to_abstract();
+ return impl.insert(instance);
+ }
+ template <class U, class A0, class A1, class A2>
+ emplace_result emplace(A0 a0, A1 a1, A2 a2)
+ {
+ abstract_base_type *instance = detail::construct<U,base_type>(get_allocator(), a0, a1, a2).to_abstract();
+ return impl.insert(instance);
+ }
+
+ template <class Fun>
+ Fun for_each(Fun fun)
+ {
+ BOOST_FOREACH(value_type &value, *this)
+ {
+ fun(value);
+ }
+ }
+
+ size_t size() const
+ {
+ return impl.size();
+ }
+ bool empty() const
+ {
+ return impl.empty();
+ }
+
+ iterator begin()
+ {
+ return impl.begin();
+ }
+ iterator end()
+ {
+ return impl.end();
+ }
+ const_iterator begin() const
+ {
+ return impl.begin();
+ }
+ const_iterator end() const
+ {
+ return impl.end();
+ }
+
+ iterator find(value_type const &key)
+ {
+ return impl.find(key);
+ }
+
+ typename implementation::allocator_type get_allocator()
+ {
+ return impl.get_allocator();
+ }
+ };
+
+ } // namespace heterogenous
+
+} // namespace boost
+
+#include <boost/cloneable/detail/suffix.hpp>
+
+#endif // BOOST_CLONEABLE_SET_HPP
+
+//EOF

Modified: sandbox/cloneable/libs/cloneable/test/cloneable.vcproj
==============================================================================
--- sandbox/cloneable/libs/cloneable/test/cloneable.vcproj (original)
+++ sandbox/cloneable/libs/cloneable/test/cloneable.vcproj 2009-06-30 20:55:41 EDT (Tue, 30 Jun 2009)
@@ -238,6 +238,10 @@
>
                                         </File>
                                         <File
+ RelativePath="..\..\..\boost\cloneable\set.hpp"
+ >
+ </File>
+ <File
                                                 RelativePath="..\..\..\boost\cloneable\vector.hpp"
>
                                         </File>

Modified: sandbox/cloneable/libs/cloneable/test/tests.cpp
==============================================================================
--- sandbox/cloneable/libs/cloneable/test/tests.cpp (original)
+++ sandbox/cloneable/libs/cloneable/test/tests.cpp 2009-06-30 20:55:41 EDT (Tue, 30 Jun 2009)
@@ -12,6 +12,11 @@
 #include <string>
 #include <iostream>
 
+#include <boost/bind.hpp>
+#include <boost/any.hpp>
+#include <boost/variant.hpp>
+#include <boost/function.hpp>
+
 #define BOOST_HETEROGENOUS
 #include <boost/monotonic/allocator.hpp>
 #include <boost/monotonic/local.hpp>
@@ -19,11 +24,9 @@
 #include <boost/cloneable/clone.hpp>
 #include <boost/cloneable/vector.hpp>
 #include <boost/cloneable/map.hpp>
+#include <boost/cloneable/set.hpp>
+
 #include <boost/cloneable/adaptor.hpp>
-#include <boost/cloneable/allocator.hpp>
-#include <boost/bind.hpp>
-#include <boost/any.hpp>
-#include <boost/variant.hpp>
 
 #define BOOST_TEST_MODULE basic_test test
 #include <boost/test/unit_test.hpp>
@@ -493,4 +496,43 @@
         BOOST_ASSERT(boost::get<T1>(v1[1]).str == "foo");
 }
 
+namespace set_test
+{
+ struct S0 : base<S0> { };
+ struct S1 : base<S1> { };
+ struct S2 : base<S2> { };
+
+ struct set_less
+ //: std::binary_function<default_base_type const &,default_base_type const &,bool>
+ : boost::function<bool (default_base_type const &,default_base_type const &)>
+ {
+ bool operator()(default_base_type const &a, default_base_type const &b) const
+ {
+ return &a < &b;
+ }
+ };
+}
+
+namespace boost
+{
+ namespace cloneable
+ {
+ // hax due to result_of<> issue with ptr_set and predicates
+ bool operator<(default_base_type const &a, default_base_type const &b)
+ {
+ return &a < &b;
+ }
+ }
+}
+
+BOOST_AUTO_TEST_CASE(test_set)
+{
+ using namespace set_test;
+ cloneable::set<> set;
+ set.emplace<S0>();
+ set.emplace<S1>();
+ set.emplace<S2>();
+}
+
 //EOF
+
\ No newline at end of file

Modified: sandbox/monotonic/boost/ptr_container/indirect_fun.hpp
==============================================================================
--- sandbox/monotonic/boost/ptr_container/indirect_fun.hpp (original)
+++ sandbox/monotonic/boost/ptr_container/indirect_fun.hpp 2009-06-30 20:55:41 EDT (Tue, 30 Jun 2009)
@@ -17,6 +17,7 @@
 #endif
 
 #include <boost/config.hpp>
+#include <boost/utility/result_of.hpp>
 
 #ifdef BOOST_NO_SFINAE
 #else
@@ -85,7 +86,7 @@
         class Fun,
         class Arg1,
         class Arg2 = Arg1
-#ifdef BOOST_NO_SFINAE
+#if 1//def BOOST_NO_SFINAE
       , class Result = bool
 #endif
>
@@ -99,7 +100,7 @@
 
         void_ptr_indirect_fun( Fun f ) : fun(f)
         { }
-#ifdef BOOST_NO_SFINAE
+#if 1//def BOOST_NO_SFINAE
         Result
 #else
         BOOST_DEDUCED_TYPENAME result_of< Fun( Arg1 ) >::type
@@ -110,7 +111,7 @@
             return fun( * static_cast<const Arg1*>( r ) );
         }
 
-#ifdef BOOST_NO_SFINAE
+#if 1//def BOOST_NO_SFINAE
         Result
 #else
         BOOST_DEDUCED_TYPENAME result_of< Fun( Arg1, Arg2 ) >::type

Modified: sandbox/monotonic/boost/ptr_container/ptr_set_adapter.hpp
==============================================================================
--- sandbox/monotonic/boost/ptr_container/ptr_set_adapter.hpp (original)
+++ sandbox/monotonic/boost/ptr_container/ptr_set_adapter.hpp 2009-06-30 20:55:41 EDT (Tue, 30 Jun 2009)
@@ -405,7 +405,7 @@
         {
             this->enforce_null_policy( x, "Null pointer in 'ptr_set::insert()'" );
             
- auto_type ptr( x );
+ auto_type ptr( x, get_allocator() );
             std::pair<BOOST_DEDUCED_TYPENAME base_type::ptr_iterator,bool>
                  res = this->base().insert( x );
             if( res.second )


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk