summaryrefslogtreecommitdiff
path: root/libs/python/doc/reference/list.qbk
blob: fd602c18521c81bdba7ca6651f2446edf3d73147 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
[section boost_python_list.hpp]
[section Introduction]
Exposes a [link concepts.objectwrapper.typewrapper_concept_requirements TypeWrapper] for the Python [@http://www.python.org/doc/current/lib/typesseq-mutable.html list] type.
[endsect]
[section Class `list`]
Exposes the [@http://www.python.org/doc/current/lib/typesseq-mutable.html mapping protocol] of Python's built-in `list` type. The semantics of the constructors and member functions defined below can be fully understood by reading the [link concepts.objectwrapper.typewrapper_concept_requirements TypeWrapper] concept definition. Since `list` is publicly derived from [link object_wrappers.boost_python_object_hpp.class_object `object`], the public `object` interface applies to `list` instances as well.``
namespace boost { namespace python
{
  class list : public object
  {
   public:
      list(); // new list

      template <class T>
      explicit list(T const& sequence);

      template <class T>
      void append(T const& x);

      template <class T>
      long count(T const& value) const;

      template <class T>
      void extend(T const& x);

      template <class T>
      long index(T const& x) const;

      template <class T>
      void insert(object const& index, T const& x); // insert object before index

      object pop(); // remove and return item at index (default last)
      object pop(long index);
      object pop(object const& index);

      template <class T>
      void remove(T const& value);

      void reverse(); // reverse *IN PLACE*

      void sort(); //  sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1

      template <class T>
      void sort(T const& value);
  };
}}
``
[endsect]
[section Example]
``
using namespace boost::python;

// Return the number of zeroes in the list
long zeroes(list l)
{
   return l.count(0);
}
``
[endsect]
[endsect]