From 386bfcf20a5a764c61e01594f3c42ea1c772534f Mon Sep 17 00:00:00 2001
From: Raoul Gough
- The top-level interface to the container suite is via the
@@ -233,12 +236,20 @@ BOOST_PYTHON_MODULE(example) {
namespace boost { namespace python { namespace indexing {
typedef return_value_policy<return_by_value> default_container_policies;
- template<class Container, class Algorithms = algo_selector<Container> >
+ template<class Container,
+ int Flags = 0,
+ class Algorithms = algo_selector<Container> >
struct container_suite
- : public visitor<Algorithms, default_container_policies>
+ : public visitor<Algorithms, default_container_policies, Flags>
{
+ typedef Algorithms algorithms;
+
template<typename Policy>
- static visitor<Algorithms, Policy> with_policies (Policy const &policy);
+ static visitor<Algorithms, Policy, Flags>
+ with_policies (Policy const &policy)
+ {
+ return visitor <Algorithms, Policy> (policy);
+ }
};
} } }
@@ -274,6 +285,14 @@ namespace boost { namespace python { namespace indexing {
client-provided policies.
+ container_suite.hpp
- header which is summarized below:
+ header is summarized below:
Flags allows client code
+ to disable unneeded features in order to reduce code
+ size. Details are provided below.
+
+
list.hpp, set.hpp and
map.hpp. These correspond in the obvious way to the
standard headers vector, deque,
- etc. The header files for the container_proxy and
- iterator_range templates provide their own support
- implicitly.
+ etc. The header files for the container_proxy and iterator_range templates
+ provide their own support implicitly.
@@ -370,6 +390,89 @@ namespace boost { namespace python { namespace indexing {
+
+
+ The container_suite template has an optional
+ Flags parameter that allows client code to disable
+ various optional features of the suite. This can lead to
+ significant savings in the size of object files and executables
+ if features such as sorting or Python slice support are not
+ needed. The Flags parameter (an integer) can be any
+ bitwise combination of the following values (defined in the
+ boost::python::indexing namespace by visitor.hpp):
+
+
+ +
| Flag | +Effect | +
|---|---|
disable_len |
+
+ omits the Python __len__ method |
+
+
disable_slices |
+
+ omits slice support code from __getitem__,
+ __setitem__ and __delitem__. |
+
+
disable_search |
+
+ omits the container search methods count and __contains__ |
+
+
disable_reorder |
+
+ omits the container reordering operations
+ sort and reverse |
+
+
disable_extend |
+
+ omits the extend method |
+
+
disable_insert |
+
+ omits the insert method |
+
+
+
+ Note that some containers don't support some of the optional
+ features at all, in which case the relevant flags are
+ ignored. The value minimum_support may be passed as
+ a flag value to disable all optional features. A simple example
+ is provided in test_vector_disable.cpp
+
+
@@ -2031,38 +2134,39 @@ namespace boost { namespace python { namespace indexing {
- Note: the suite hasn't yet been tested on a compiler
- without partial template specialization support. If you have any
- results with such a compiler (good or bad) please report them on
- the mailing list for the Python C++-SIG.
+ It is possible to use the suite without partial template
+ specialization support, but the algo_selector
+ specializations for the standard containers does not work. To
+ avoid this problem, the client code must explicitly select the
+ Algorithms and ContainerTraits
+ instances to be used, and there are some additional support
+ templates in the container-specific header files for this
+ purpose.
+
+
+#include <boost/python/suite/indexing/vector.hpp>
+
+...
+
+ using namespace boost::python;
+ using namespace boost::python::indexing;
+
+ class_<std::vector<int> > ("vector_int")
+ .def (indexing::vector_suite <vector <int> >());
+
- It should be possible to use the suite without partial template
- specialization support. However, the algo_selector
- template will not work, which also means that the default
- template parameter for container_suite won't
- work. To avoid this problem, the client code must explicitly
- select the Algorithms and
- ContainerTraits instances to be used. It is
- probably easiest to use the visitor template
- directly, as in the following example:
-
-
- using namespace boost::python;
- using namespace boost::python::indexing;
-
- class_<std::vector<int> > ("vector_int")
- .def (visitor <
- default_algorithms <
- default_sequence_traits <
- std::vector <int> > >,
- return_value_policy <return_by_value>
- >());
-
+ Microsoft Visual C++ 6.0 has a version of the standard
+ deque header that is incompatible with the
+ container_proxy template, since it lacks a correct
+ template version of the insert member function. An
+ updated copy of the deque header that fixes this
+ problem (among others) is available directly from Dinkumware
+ (at time of writing, 2003/11/04).