diff --git a/doc/v2/containers.html b/doc/v2/containers.html index ee2b298c..b9c47c9d 100755 --- a/doc/v2/containers.html +++ b/doc/v2/containers.html @@ -72,14 +72,24 @@
- container_proxy + Container adapters +
+
+
+
+ container_proxy +
+
+ iterator_pair +
+
+
+
+ Compiler workarounds
Known limitations
-
- Compiler workarounds -
@@ -1001,6 +1011,97 @@ namespace our_namespace {

+

Simplistic ContainerTraits example

+ +

+ + The following block of code shows a simplistic implementation of + ContainerTraits for the container + std::set<std::string, int>. The actual + implementation used by the suite relies on template + metaprogramming techniques, whereas this example is designed to + show only the essential elements of a + ContainerTraits implementation. + +

+ +

+

+#include <map>
+#include <string>
+#include <boost/python/suite/indexing/iterator_traits.hpp>
+// Include iterator_traits to get IndexStyle
+
+struct simple_map_traits {
+  // Traits information for std::map<std::string, int>
+
+  typedef std::map<std::string, int> container;
+  typedef container::size_type       size_type;
+  typedef container::iterator        iterator;
+
+  typedef int                        value_type;
+  typedef int &                      reference;
+  typedef std::string                key_type;
+  typedef std::string                index_type;
+
+  typedef int                        value_param;
+  typedef std::string const &        key_param;
+  typedef std::string const &        index_param;
+
+  static bool const has_copyable_iter = true;
+  static bool const has_mutable_ref   = true;
+  static bool const has_find          = true;
+  static bool const has_insert        = true;
+  static bool const has_erase         = true;
+  static bool const has_pop_back      = false;
+  static bool const has_push_back     = false;
+  static bool const is_reorderable    = false;
+
+  static boost::python::indexing::IndexStyle const index_style
+    = boost::python::indexing::index_style_nonlinear;
+
+  struct value_traits_ {
+    // Traits information for our value_type
+    static bool const equality_comparable = true;
+    static bool const lessthan_comparable = true;
+  };
+
+  template<typename PythonClass, typename Policy>
+  static void visitor_helper (PythonClass &, Policy const &)
+  {
+    // Empty
+  }
+};
+
+

+ +

+ + Example usage of the simple_map_traits: + +

+ +

+

+#include "simple_map_traits.hpp"
+
+#include <boost/python/suite/indexing/container_suite.hpp>
+
+#include <boost/python/module.hpp>
+#include <boost/python/class.hpp>
+
+BOOST_PYTHON_MODULE(test_simple) {
+  using namespace boost::python;
+
+  typedef std::map<std::string, int> Container;
+  typedef indexing::map_algorithms<simple_map_traits> Algorithms;
+
+  class_<Container> ("map")
+    .def (indexing::container_suite<Container, Algorithms>());
+}
+
+

+

Algorithms

@@ -1463,6 +1564,67 @@ template<typename P> struct deref { +

iterator_pair

+ +

+ + The iterator_pair template provides a + container-like interface to a range defined by two iterators. + The interface is complete enough to allow the container suite to + expose an iterator-defined range as a Python sequence type, with + support for operations that do not require insertion or + deletion. This can be used to expose a C++ array to Python, or + with the result of an equal_range function, or any + other source of two iterators marking out a range of values. See + the getArray function in + libs/python/test/testarray.cpp for an example usage. + +

+

+ + iterator_pair should work with any + ForwardIterator type. + +

+ +

+

+namespace boost { namespace python { namespace indexing {
+  template<typename Iterator>
+  class iterator_pair
+  {
+  private:
+    typedef typename boost::call_traits<Iterator>::param_type iterator_param;
+    typedef std::iterator_traits<Iterator> std_traits;
+
+  public:
+    typedef typename std_traits::reference       reference;
+    typedef Iterator                             iterator;
+    typedef typename std_traits::difference_type size_type;
+    typedef typename std_traits::difference_type difference_type;
+    typedef typename std_traits::value_type      value_type;
+    typedef typename std_traits::pointer         pointer;
+
+    iterator_pair (iterator_param, iterator_param);
+    iterator_pair (std::pair<iterator, iterator> const &);
+
+    iterator begin() const;
+    iterator end() const;
+
+    size_type size () const;
+    reference operator[] (size_type) const;
+    reference at (size_type) const;
+
+  private:
+    // Member variables
+  };
+
+  template<typename T, std::size_t N> T *begin (T (&array)[N]);
+  template<typename T, std::size_t N> T *end   (T (&array)[N]);
+
+} } }
+
+

Compiler workarounds