|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r54604 - in sandbox/cloneable: boost/cloneable boost/cloneable/detail libs/cloneable/test
From: christian.schladetsch_at_[hidden]
Date: 2009-07-02 23:17:20
Author: cschladetsch
Date: 2009-07-02 23:17:18 EDT (Thu, 02 Jul 2009)
New Revision: 54604
URL: http://svn.boost.org/trac/boost/changeset/54604
Log:
added container_base
next is sequence_base, associative_base etc...
Added:
sandbox/cloneable/boost/cloneable/detail/container_base.hpp (contents, props changed)
Text files modified:
sandbox/cloneable/boost/cloneable/base.hpp | 2
sandbox/cloneable/boost/cloneable/instance.hpp | 1
sandbox/cloneable/boost/cloneable/list.hpp | 82 ++++++++++----------------
sandbox/cloneable/boost/cloneable/map.hpp | 121 +++++++++++++++++++--------------------
sandbox/cloneable/boost/cloneable/set.hpp | 62 +++++++++++---------
sandbox/cloneable/boost/cloneable/traits.hpp | 8 +
sandbox/cloneable/boost/cloneable/vector.hpp | 46 ++++++++------
sandbox/cloneable/libs/cloneable/test/cloneable.vcproj | 8 ++
sandbox/cloneable/libs/cloneable/test/tests.cpp | 11 ++-
9 files changed, 171 insertions(+), 170 deletions(-)
Modified: sandbox/cloneable/boost/cloneable/base.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/base.hpp (original)
+++ sandbox/cloneable/boost/cloneable/base.hpp 2009-07-02 23:17:18 EDT (Thu, 02 Jul 2009)
@@ -43,7 +43,7 @@
/// base for the given derived type, using the given base class
template <class Derived, class Base, class DefaultCtor>
- struct base : abstract_base<Base, DefaultCtor>, is_cloneable_tag
+ struct base : abstract_base<Base, DefaultCtor>, virtual is_cloneable_tag, virtual DefaultCtor
{
typedef Derived derived_type;
typedef Base base_type;
Added: sandbox/cloneable/boost/cloneable/detail/container_base.hpp
==============================================================================
--- (empty file)
+++ sandbox/cloneable/boost/cloneable/detail/container_base.hpp 2009-07-02 23:17:18 EDT (Thu, 02 Jul 2009)
@@ -0,0 +1,110 @@
+// 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_DETAIL_CONTAINER_BASE_HPP
+#define BOOST_CLONEABLE_DETAIL_CONTAINER_BASE_HPP
+
+#include <boost/cloneable/detail/prefix.hpp>
+#include <boost/cloneable/detail/make_clone_allocator.hpp>
+#include <boost/cloneable/instance.hpp>
+#include <boost/cloneable/traits.hpp>
+
+namespace boost
+{
+ namespace cloneable
+ {
+ namespace detail
+ {
+ /// common functionality for all containers using the given base and allocator types
+ template <class Base, class Alloc>
+ struct container_base
+ {
+ typedef Base base_type;
+ typedef abstract_base<base_type> abstract_base_type;
+ typedef typename detail::make_clone_allocator<Alloc>::type allocator_type;
+ typedef instance_base<Base, allocator_type> instance_base_type;
+
+ /// ensures that the given type T is a valid type for this container.
+ /// this provides better information from errors than otherwise.
+ template <class T>
+ struct validate
+ {
+ // can only add cloneable things to a heterogenous container
+ BOOST_STATIC_ASSERT(is_cloneable<T>::value);
+
+ // you must ensure that base-types for objects that you add to a container
+ // is the same base used by the container
+ typedef is_convertible<T *, base_type *> has_base_type;
+ BOOST_STATIC_ASSERT(has_base_type::value);
+
+ typedef T type;
+ };
+
+ /// an instance of the given derived type U suitable for this container
+ template <class U>
+ struct instance
+ : cloneable::instance<U, Base, Alloc>
+ {
+ typedef cloneable::instance<U, Base, Alloc> parent_type;
+ instance(allocator_type &a) : parent_type(a) { }
+ template <class A0>
+ instance(allocator_type &a, A0 a0) : parent_type(a, a0) { }
+ template <class A0, class A1>
+ instance(allocator_type &a, A0 a0, A1 a1) : parent_type(a, a0, a1) { }
+ template <class A0, class A1, class A2>
+ instance(allocator_type &a, A0 a0, A1 a1, A2 a2) : parent_type(a, a0, a1, a2) { }
+ };
+
+ private:
+ allocator_type alloc;
+
+ protected:
+ template <class U>
+ instance<U> new_instance()
+ {
+ return instance<U>(get_allocator());
+ }
+ template <class U, class A0>
+ instance<U> new_instance(A0 a0)
+ {
+ return instance<U>(get_allocator(), a0);
+ }
+ template <class U, class A0, class A1>
+ instance<U> new_instance(A0 a0, A1 a1)
+ {
+ return instance<U>(get_allocator(), a0, a1);
+ }
+ template <class U, class A0, class A1, class A2>
+ instance<U> new_instance(A0 a0, A1 a1, A2 a2)
+ {
+ return instance<U>(get_allocator(), a0, a1, a2);
+ }
+
+ public:
+ container_base() { }
+ container_base(allocator_type &a)
+ : alloc(a) { }
+
+ const allocator_type &get_allocator() const
+ {
+ return alloc;
+ }
+ allocator_type &get_allocator()
+ {
+ return alloc;
+ }
+ };
+
+ } // namespace detail
+
+ } // namespace cloneable
+
+} // namespace boost
+
+#include <boost/cloneable/detail/suffix.hpp>
+
+#endif // BOOST_CLONEABLE_DETAIL_CONTAINER_BASE_HPP
+
+//EOF
Modified: sandbox/cloneable/boost/cloneable/instance.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/instance.hpp (original)
+++ sandbox/cloneable/boost/cloneable/instance.hpp 2009-07-02 23:17:18 EDT (Thu, 02 Jul 2009)
@@ -77,6 +77,7 @@
instance(allocator_type &al) : parent_type(&al), ptr(0)
{
allocate();
+ new (to_derived()) derived_type();
}
template <class A0>
instance(allocator_type &al, A0 a0) : parent_type(&al), ptr(0)
Modified: sandbox/cloneable/boost/cloneable/list.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/list.hpp (original)
+++ sandbox/cloneable/boost/cloneable/list.hpp 2009-07-02 23:17:18 EDT (Thu, 02 Jul 2009)
@@ -10,9 +10,8 @@
#include <boost/foreach.hpp>
#include <boost/cloneable/detail/prefix.hpp>
-#include <boost/cloneable/detail/make_clone_allocator.hpp>
+#include <boost/cloneable/detail/container_base.hpp>
#include <boost/cloneable/base.hpp>
-#include <boost/cloneable/traits.hpp>
#include <boost/cloneable/instance.hpp>
namespace boost
@@ -20,46 +19,38 @@
namespace cloneable
{
/// a list of heterogenous objects
+ // TODO: derive from sequence<ptr_list>
// TODO: move to boost/heterogenous/list
template <class Base, class Alloc>
struct list
+ : detail::container_base<Base, Alloc>
{
- typedef Base base_type;
- typedef abstract_base<Base> abstract_base_type;
- typedef typename detail::make_clone_allocator<Alloc>::type allocator_type;
+ typedef detail::container_base<Base,Alloc> parent_type;
+ typedef typename parent_type::base_type base_type;
+ typedef typename parent_type::abstract_base_type abstract_base_type;
+ typedef typename parent_type::allocator_type allocator_type;
+ using parent_type::validate;
+ using parent_type::new_instance;
+
typedef ptr_list<abstract_base_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;
- // this provides better information from errors than otherwise
- template <class T>
- struct validate
- {
- // can only add cloneable things to a heterogenous container
- BOOST_STATIC_ASSERT(is_cloneable<T>::value);
-
- typedef is_same<typename traits<T>::abstract_base_type, abstract_base_type> same_type;
-
- // you must ensure that base-types for objects that you add to a container
- // is the same base used by the container
- BOOST_STATIC_ASSERT(same_type::value);
-
- typedef typename traits<T>::derived_type type;
- };
-
private:
implementation impl;
public:
list()
+ : impl(get_allocator())
{
}
list(allocator_type &a)
- : impl(a)
+ : parent_type(a), impl(get_allocator())
{
}
@@ -149,6 +140,7 @@
template <class Other>
Other &front_as()
{
+ BOOST_STATIC_ASSERT(is_cloneable<Other>::value);
Other *ptr = dynamic_cast<Other *>(front());
if (ptr == 0)
throw std::bad_cast();
@@ -157,58 +149,46 @@
// TODO: use variadic arguments or BOOST_PP to pass ctor args
template <class U>
- void emplace_back()
+ void push_back()
{
- typedef typename validate<U>::type value;
- impl.push_back(instance<value,base_type,allocator_type>(get_allocator()).to_abstract());
+ impl.push_back(new_instance<typename validate<U>::type>().to_abstract());
}
template <class U, class A0>
- void emplace_back(A0 a0)
+ void push_back(A0 a0)
{
- typedef typename validate<U>::type value;
- impl.push_back(instance<value,base_type,allocator_type>(get_allocator(), a0).to_abstract());
+ impl.push_back(new_instance<typename validate<U>::type>(a0).to_abstract());
}
template <class U, class A0, class A1>
- void emplace_back(A0 a0, A1 a1)
+ void push_back(A0 a0, A1 a1)
{
- typedef validate<U>::type value;
- impl.push_back(instance<value,base_type,allocator_type>(get_allocator(), a0,a1).to_abstract());
+ impl.push_back(new_instance<typename validate<U>::type>(a0,a1).to_abstract());
}
template <class U, class A0, class A1, class A2>
- void emplace_back(A0 a0, A1 a1, A2 a2)
+ void push_back(A0 a0, A1 a1, A2 a2)
{
- typedef typename validate<U>::type value;
- impl.push_back(instance<value,base_type,allocator_type>(get_allocator(), a0,a1,a2).to_abstract());
+ impl.push_back(new_instance<typename validate<U>::type>(a0,a1,a2).to_abstract());
}
+
template <class U>
- void emplace_front()
+ void push_front()
{
- typedef typename validate<U>::type value;
- impl.push_front(instance<value,base_type,allocator_type>(get_allocator()).to_abstract());
+ impl.push_front(new_instance<typename validate<U>::type>().to_abstract());
}
template <class U, class A0>
- void emplace_front(A0 a0)
+ void push_front(A0 a0)
{
- typedef typename validate<U>::type value;
- impl.push_front(instance<value,base_type,allocator_type>(get_allocator(), a0).to_abstract());
+ impl.push_front(new_instance<typename validate<U>::type>(a0).to_abstract());
}
template <class U, class A0, class A1>
- void emplace_front(A0 a0, A1 a1)
+ void push_front(A0 a0, A1 a1)
{
- typedef typename validate<U>::type value;
- impl.push_front(instance<value,base_type,allocator_type>(get_allocator(), a0,a1).to_abstract());
+ impl.push_front(new_instance<typename validate<U>::type>(a0,a1).to_abstract());
}
template <class U, class A0, class A1, class A2>
- void emplace_front(A0 a0, A1 a1, A2 a2)
- {
- typedef typename validate<U>::type value;
- impl.push_front(instance<value,base_type,allocator_type>(get_allocator(), a0,a1,a2).to_abstract());
- }
-
- typename allocator_type get_allocator()
+ void push_front(A0 a0, A1 a1, A2 a2)
{
- return impl.get_allocator();
+ impl.push_front(new_instance<typename validate<U>::type>(a0,a1,a2).to_abstract());
}
};
Modified: sandbox/cloneable/boost/cloneable/map.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/map.hpp (original)
+++ sandbox/cloneable/boost/cloneable/map.hpp 2009-07-02 23:17:18 EDT (Thu, 02 Jul 2009)
@@ -10,7 +10,7 @@
#include <boost/foreach.hpp>
#include <boost/cloneable/detail/make_clone_allocator.hpp>
-#include <boost/cloneable/instance.hpp>
+#include <boost/cloneable/detail/container_base.hpp>
namespace boost
{
@@ -20,16 +20,18 @@
// TODO: move to boost/heterogenous/map
template <class Base, class Pred, class Alloc>
struct map
+ : detail::container_base<Base, Alloc>
{
- typedef Base base_type;
+ typedef detail::container_base<Base,Alloc> parent_type;
+ typedef typename parent_type::base_type base_type;
+ typedef typename parent_type::abstract_base_type abstract_base_type;
+ typedef typename parent_type::allocator_type allocator_type;
+ using parent_type::validate;
+ using parent_type::new_instance;
+
typedef Pred predicate_type;
- typedef abstract_base<base_type> abstract_base_type;
- typedef typename detail::make_clone_allocator<Alloc>::type allocator_type;
- typedef instance_base<base_type, allocator_type> instance_base_type;
typedef ptr_map<abstract_base_type, abstract_base_type, Pred, allocator, allocator_type> implementation;
- //typedef std::map<abstract_base_type *, abstract_base_type *, Pred, allocator_type> implementation;
-
typedef typename implementation::value_type value_type;
typedef typename implementation::reference reference;
typedef typename implementation::const_reference const_reference;
@@ -37,24 +39,32 @@
typedef typename implementation::const_iterator const_iterator;
typedef typename implementation::key_type key_type;
typedef typename implementation::mapped_type mapped_type;
+
typedef map<Base, Pred, Alloc> this_type;
private:
implementation impl;
public:
- map()
+ map()
+ : impl(predicate_type(), get_allocator())
{
}
- map(allocator_type a)
- : impl(a)
+ map(allocator_type &a)
+ : parent_type(a), impl(predicate_type(), get_allocator())
{
}
- /* purposefully elided
template <class II>
- map(II F, II L, allocator_type a = allocator_type());
- */
+ map(II F, II L)
+ : impl(F,L, get_allocator())
+ {
+ }
+ template <class II>
+ map(II F, II L, allocator_type &a)
+ : parent_type(a), impl(F,L, get_allocator())
+ {
+ }
private:
typedef std::pair<iterator, bool> map_insert_result;
@@ -62,9 +72,9 @@
template <class K, class V>
struct insert_result
{
- //TODO: typedef const_instance<K,base_type,allocator_type> key_type;
- typedef instance<K,base_type,allocator_type> key_type;
- typedef instance<V,base_type,allocator_type> value_type;
+ //TODO: typedef const_instance<K> key_type;
+ typedef instance<K> key_type;
+ typedef instance<V> value_type;
key_type key;
value_type value;
@@ -79,90 +89,79 @@
template <class K>
struct value_adder
{
- typedef instance<K,base_type,allocator_type> key_type;
+ private:
+ typedef instance<K> key_type;
this_type *parent;
key_type key;
+ public:
value_adder(this_type &P, const key_type &K)
: parent(&P), key(K) { }
template <class V>
insert_result<K,V> value()
{
- instance<V,base_type,allocator_type> val(parent->get_allocator());
- map_insert_result result = parent->insert(key.to_abstract(), val.to_abstract());
- if (!result.second)
- {
- key.release();
- val.release();
- }
- return insert_result<K,V>(key, val, result);
+ return insert(parent->new_instance<V>());
}
template <class V, class A0>
insert_result<K,V> value(A0 a0)
{
- instance<V,base_type,allocator_type> val(parent->get_allocator(), a0);
- map_insert_result result = parent->insert(key.to_abstract(), val.to_abstract());
- if (!result.second)
- {
- key.release();
- val.release();
- }
- return insert_result<K,V>(key, val, result);
+ return insert(parent->new_instance<V>(a0));
}
template <class V, class A0, class A1>
insert_result<K,V> value(A0 a0, A1 a1)
{
- instance<V,base_type,allocator_type> val(parent->get_allocator(), a0, a1);
- map_insert_result result = parent->insert(key.to_abstract(), val.to_abstract());
+ return insert(parent->new_instance<V>(a0,a1));
+ }
+
+ private:
+ template <class V>
+ insert_result<K,V> insert(instance<V> &value)
+ {
+ map_insert_result result = parent->insert(key.to_abstract(), value.to_abstract());
if (!result.second)
{
key.release();
- val.release();
+ value.release();
}
- return insert_result<K,V>(key, val, result);
+ return insert_result<K,V>(key, value, result);
}
};
+ // TODO: make this private
+ template <class A, class B>
+ map_insert_result insert(A a, B b)
+ {
+ return impl.insert(a, b);
+ }
+ void insert(value_type x)
+ {
+ impl.insert(x);
+ }
+
public:
template <class K>
value_adder<K> key()
{
- instance<K,base_type,allocator_type> key_instance(get_allocator());
- return value_adder<K>(*this, key_instance);
+ return value_adder<K>(*this, new_instance<K>());
}
// TODO: use variadic arguments or BOOST_PP to pass ctor args
template <class K, class A0>
value_adder<K> key(A0 a0)
{
- instance<K,base_type,allocator_type> key_instance(get_allocator(), a0);
- return value_adder<K>(*this, key_instance);
+ return value_adder<K>(*this, new_instance<K>(a0));
}
template <class K, class A0, class A1>
value_adder<K> key(A0 a0, A1 a1)
{
- instance<K,base_type,allocator_type> key_instance(get_allocator(), a0, a1);
- return value_adder<K>(*this, key_instance);
+ return value_adder<K>(*this, new_instance<K>(a0,a1));
}
template <class K, class A0, class A1, class A2>
value_adder<K> key(A0 a0, A1 a1, A2 a2)
{
- throw;
- //base_type *key_instance = detail::construct<U,base_type>(get_allocator(), a0, a1, a2).to_base();
- //return value_adder(*this, *key_instance);
- }
-
- // TODO: make this private
- template <class A, class B>
- map_insert_result insert(A a, B b)
- {
- return impl.insert(a, b);
- }
- void insert(value_type x)
- {
- impl.insert(x);
+ return value_adder<K>(*this, new_instance<K>(a0,a1,a2));
}
template <class Fun>
@@ -229,7 +228,7 @@
template <class K>
iterator find()
{
- instance<K,base_type,allocator_type> k(get_allocator());
+ instance<K> k(get_allocator());
BOOST_SCOPE_EXIT((k))
{
k.release();
@@ -241,7 +240,7 @@
template <class K, class A0>
iterator find(A0 a0)
{
- instance<K,base_type,allocator_type> k(get_allocator(), a0);
+ instance<K> k(get_allocator(), a0);
BOOST_SCOPE_EXIT((k))
{
k.release();
@@ -259,10 +258,6 @@
// return impl[n];
//}
- typename allocator_type get_allocator()
- {
- return impl.get_allocator();
- }
};
} // namespace heterogenous
Modified: sandbox/cloneable/boost/cloneable/set.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/set.hpp (original)
+++ sandbox/cloneable/boost/cloneable/set.hpp 2009-07-02 23:17:18 EDT (Thu, 02 Jul 2009)
@@ -9,10 +9,9 @@
#include <boost/ptr_container/ptr_set.hpp>
#include <boost/foreach.hpp>
-#include <boost/cloneable/detail/make_clone_allocator.hpp>
-#include <boost/cloneable/allocator.hpp>
+#include <boost/cloneable/detail/prefix.hpp>
+#include <boost/cloneable/detail/container_base.hpp>
#include <boost/cloneable/adaptor.hpp>
-#include <boost/cloneable/instance.hpp>
namespace boost
{
@@ -22,12 +21,16 @@
// TODO: move to boost/heterogenous/set.hpp, or boost/cloneable/containers/set.hpp
template <class Base, class Pred, class Alloc>
struct set
+ : detail::container_base<Base, Alloc>
{
- typedef Base base_type;
- typedef Pred predicate_type;
- typedef abstract_base<Base> abstract_base_type;
- typedef typename detail::make_clone_allocator<Alloc>::type allocator_type;
+ typedef detail::container_base<Base,Alloc> parent_type;
+ typedef typename parent_type::base_type base_type;
+ typedef typename parent_type::abstract_base_type abstract_base_type;
+ typedef typename parent_type::allocator_type allocator_type;
+ using parent_type::validate;
+ using parent_type::new_instance;
+ typedef Pred predicate_type;
typedef ptr_set<abstract_base_type, predicate_type, allocator, allocator_type> implementation;
typedef typename implementation::value_type value_type;
@@ -37,23 +40,30 @@
typedef typename implementation::const_iterator const_iterator;
typedef set<Base, Pred, Alloc> this_type;
- //private:
+ private:
implementation impl;
public:
- set()
+ set()
+ : impl(predicate_type(), get_allocator())
{
}
- set(allocator_type a)
- : impl(a)
+ set(allocator_type &a)
+ : parent_type(a), impl(predicate_type(), get_allocator())
{
}
- /* purposefully elided
template <class II>
- set(II F, II L, allocator_type a = allocator_type());
- */
+ set(II F, II L)
+ : impl(F, L, get_allocator())
+ {
+ }
+ template <class II>
+ set(II F, II L, allocator_type &a)
+ : parent_type(a), impl(F, L, get_allocator())
+ {
+ }
public:
typedef std::pair<iterator, bool> insert_result;
@@ -61,7 +71,7 @@
template <class U>
struct emplace_result
{
- typedef instance<U, base_type,allocator_type> instance_type;
+ typedef instance<U> instance_type;
instance_type value;
bool inserted;
iterator where;
@@ -71,7 +81,7 @@
};
template <class U>
- emplace_result<U> emplace(instance<U,base_type,allocator_type> value)
+ emplace_result<U> emplace(instance<U> value)
{
insert_result result = impl.insert(value.to_abstract());
if (!result.second)
@@ -82,23 +92,23 @@
template <class U>
emplace_result<U> emplace()
{
- return emplace(instance<U, base_type,allocator_type>(get_allocator()));
+ return emplace(new_instance<U>());
}
template <class U, class A0>
emplace_result<U> emplace(A0 a0)
{
- return emplace(instance<U, base_type,allocator_type>(get_allocator(), a0));
+ return emplace(new_instance<U>(a0));
}
template <class U, class A0, class A1>
emplace_result<U> emplace(A0 a0, A1 a1)
{
- return emplace(instance<U, base_type,allocator_type>(get_allocator(), a0, a1));
+ return emplace(new_instance<U>(a0, a1));
}
template <class U, class A0, class A1, class A2>
emplace_result<U> emplace(A0 a0, A1 a1, A2 a2)
{
- return emplace(instance<U, base_type,allocator_type>(get_allocator(), a0, a1, a2));
+ return emplace(new_instance<U>(a0, a1, a2));
}
template <class Fun>
@@ -154,18 +164,18 @@
static iterator given(this_type *cont)
{
- return search(cont, instance<U,base_type,allocator_type>(cont->get_allocator()));
+ return search(cont, cont->new_instance<U>());
}
template <class A0>
static iterator given(this_type *cont, A0 a0)
{
- return search(cont, instance<U,base_type,allocator_type>(cont->get_allocator(), a0));
+ return search(cont, cont->new_instance<U>(a0));
}
template <class A0, class A1>
static iterator given(this_type *cont, A0 a0, A1 a1)
{
- return search(cont, instance<U,base_type,allocator_type>(cont->get_allocator(), a0, a1));
+ return search(cont, cont->new_instance<U>(a0, a1));
}
};
struct default_key : base<default_key, base_type>
@@ -190,7 +200,7 @@
};
};
template <class U>
- iterator find_instance(instance<U,base_type,allocator_type> value)
+ iterator find_instance(instance<U> value)
{
if (!value.exists())
return end();
@@ -209,10 +219,6 @@
return impl::find<U>::given(this, a0);
}
- allocator_type get_allocator()
- {
- return impl.get_allocator();
- }
};
} // namespace heterogenous
Modified: sandbox/cloneable/boost/cloneable/traits.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/traits.hpp (original)
+++ sandbox/cloneable/boost/cloneable/traits.hpp 2009-07-02 23:17:18 EDT (Thu, 02 Jul 2009)
@@ -19,10 +19,12 @@
template <class T, bool>
struct traits
{
+ /*
typedef T derived_type;
typedef T base_type;
typedef unknown_construction default_constructable_type;
typedef T abstract_base_type;
+ */
BOOST_STATIC_CONSTANT(bool, is_cloneable = false);
BOOST_STATIC_CONSTANT(bool, has_default_ctor = false); // this really should be ternary: yes, no or unknown
@@ -31,14 +33,16 @@
template <class T>
struct traits<T, true>
{
+ /*
typedef typename T::derived_type derived_type;
typedef typename T::base_type base_type;
typedef typename T::default_constructable_type default_constructable_type;
typedef typename T::abstract_base_type abstract_base_type;
+ */
BOOST_STATIC_CONSTANT(bool, is_cloneable = true);
- typedef is_same<default_constructable_type, default_construction> same_type;
- BOOST_STATIC_CONSTANT(bool, has_default_ctor = same_type::value);
+ typedef is_convertible<T *, default_construction *> has_default_ctor_type;
+ BOOST_STATIC_CONSTANT(bool, has_default_ctor = has_default_ctor_type::value);
};
template <class T>
Modified: sandbox/cloneable/boost/cloneable/vector.hpp
==============================================================================
--- sandbox/cloneable/boost/cloneable/vector.hpp (original)
+++ sandbox/cloneable/boost/cloneable/vector.hpp 2009-07-02 23:17:18 EDT (Thu, 02 Jul 2009)
@@ -10,9 +10,8 @@
#include <boost/foreach.hpp>
#include <boost/cloneable/detail/prefix.hpp>
-#include <boost/cloneable/detail/make_clone_allocator.hpp>
+#include <boost/cloneable/detail/container_base.hpp>
#include <boost/cloneable/base.hpp>
-#include <boost/cloneable/instance.hpp>
namespace boost
{
@@ -22,11 +21,17 @@
// TODO: move to boost/heterogenous/vector
template <class Base, class Alloc>
struct vector
+ : detail::container_base<Base, Alloc>
{
- typedef Base base_type;
- typedef abstract_base<Base> abstract_base_type;
- typedef typename detail::make_clone_allocator<Alloc>::type allocator_type;
+ typedef detail::container_base<Base,Alloc> parent_type;
+ typedef typename parent_type::base_type base_type;
+ typedef typename parent_type::abstract_base_type abstract_base_type;
+ typedef typename parent_type::allocator_type allocator_type;
+ using parent_type::validate;
+ using parent_type::new_instance;
+
typedef ptr_vector<abstract_base_type, allocator, allocator_type> implementation;
+
typedef typename implementation::value_type value_type;
typedef typename implementation::reference reference;
typedef typename implementation::const_reference const_reference;
@@ -37,19 +42,23 @@
implementation impl;
public:
- vector()
+ vector() : impl(get_allocator())
{
}
vector(allocator_type &a)
- : impl(a)
+ : parent_type(a), impl(a)
{
}
- //purposefully elided
- //template <class II>
- //vector(II F, II L, allocator_type a = allocator_type());
- //vector(size_t reserved);
+ /*
+ template <class II>
+ vector(II F, II L, allocator_type a = allocator_type());
+ vector(size_t reserved)
+ : impl(alloc)
+ {
+ }
+ */
template <class Ty, class Fun>
Fun for_each(Fun fun)
@@ -166,7 +175,7 @@
return dynamic_cast<Other *>(&at(n));
}
template <class Other>
- const Other *ptr(size_t n) const
+ const Other *pointer(size_t n) const
{
return dynamic_cast<const Other *>(&at(n));
}
@@ -175,29 +184,24 @@
template <class U>
void emplace_back()
{
- impl.push_back(instance<U,base_type,allocator_type>(get_allocator()).to_abstract());
+ impl.push_back(new_instance<typename validate<U>::type>().to_abstract());
}
template <class U, class A0>
void emplace_back(A0 a0)
{
- impl.push_back(instance<U,base_type,allocator_type>(get_allocator(), a0).to_abstract());
+ impl.push_back(new_instance<typename validate<U>::type>(a0).to_abstract());
}
template <class U, class A0, class A1>
void emplace_back(A0 a0, A1 a1)
{
- impl.push_back(instance<U,base_type,allocator_type>(get_allocator(), a0,a1).to_abstract());
+ impl.push_back(new_instance<typename validate<U>::type>(a0,a1).to_abstract());
}
template <class U, class A0, class A1, class A2>
void emplace_back(A0 a0, A1 a1, A2 a2)
{
- impl.push_back(instance<U,base_type,allocator_type>(get_allocator(), a0,a1,a2).to_abstract());
+ impl.push_back(new_instance<typename validate<U>::type>(a0,a1,a2).to_abstract());
}
- // TODO: this should return a reference
- typename allocator_type get_allocator()
- {
- return impl.get_allocator();
- }
};
} // namespace cloneable
Modified: sandbox/cloneable/libs/cloneable/test/cloneable.vcproj
==============================================================================
--- sandbox/cloneable/libs/cloneable/test/cloneable.vcproj (original)
+++ sandbox/cloneable/libs/cloneable/test/cloneable.vcproj 2009-07-02 23:17:18 EDT (Thu, 02 Jul 2009)
@@ -257,6 +257,14 @@
RelativePath="..\..\..\boost\cloneable\vector.hpp"
>
</File>
+ <Filter
+ Name="detail"
+ >
+ <File
+ RelativePath="..\..\..\boost\cloneable\detail\container_base.hpp"
+ >
+ </File>
+ </Filter>
</Filter>
</Filter>
<Filter
Modified: sandbox/cloneable/libs/cloneable/test/tests.cpp
==============================================================================
--- sandbox/cloneable/libs/cloneable/test/tests.cpp (original)
+++ sandbox/cloneable/libs/cloneable/test/tests.cpp 2009-07-02 23:17:18 EDT (Thu, 02 Jul 2009)
@@ -412,10 +412,10 @@
{
typedef cloneable::list<my_base> list;
list l0;
- l0.emplace_back<T0>(42);
- l0.emplace_back<T1>("foo");
- l0.emplace_back<T2>(3.14f, -123, "spam");
- l0.emplace_back<cloneable_external_type>("external");
+ l0.push_back<T0>(42);
+ l0.push_back<T1>("foo");
+ l0.push_back<T2>(3.14f, -123, "spam");
+ l0.push_back<cloneable_external_type>("external");
list l1 = l0;
list::iterator iter = l1.begin();
BOOST_ASSERT(typeid(*iter++) == typeid(T0));
@@ -473,6 +473,9 @@
using namespace map_test;
typedef cloneable::map<map_test::my_base, wtf_less> map_type;
map_type map;
+ map.key<M2>().value<M3>();
+ map_type::iterator a = map.find<M2>();
+
map.key<M0>(42).value<M1>("foo");
map.key<M2>().value<M3>();
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