fix doc example typo
[boost.git] / boost / python / list.hpp
blob0f6d1e8e9ca42d5be52aaebd119fca85b187004c
1 // Copyright David Abrahams 2002.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef LIST_DWA2002627_HPP
6 # define LIST_DWA2002627_HPP
8 # include <boost/python/detail/prefix.hpp>
10 # include <boost/python/object.hpp>
11 # include <boost/python/converter/pytype_object_mgr_traits.hpp>
12 # include <boost/python/ssize_t.hpp>
14 namespace boost { namespace python {
16 namespace detail
18 struct BOOST_PYTHON_DECL list_base : object
20 void append(object_cref); // append object to end
22 long count(object_cref value) const; // return number of occurrences of value
24 void extend(object_cref sequence); // extend list by appending sequence elements
26 long index(object_cref value) const; // return index of first occurrence of value
28 void insert(ssize_t index, object_cref); // insert object before index
29 void insert(object const& index, object_cref);
31 object pop(); // remove and return item at index (default last)
32 object pop(ssize_t index);
33 object pop(object const& index);
35 void remove(object_cref value); // remove first occurrence of value
37 void reverse(); // reverse *IN PLACE*
39 void sort(); // sort *IN PLACE*; if given, cmpfunc(x, y) -> -1, 0, 1
40 void sort(object_cref cmpfunc);
43 protected:
44 list_base(); // new list
45 explicit list_base(object_cref sequence); // new list initialized from sequence's items
47 BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list_base, object)
48 private:
49 static detail::new_non_null_reference call(object const&);
53 class list : public detail::list_base
55 typedef detail::list_base base;
56 public:
57 list() {} // new list
59 template <class T>
60 explicit list(T const& sequence)
61 : base(object(sequence))
65 template <class T>
66 void append(T const& x)
68 base::append(object(x));
71 template <class T>
72 long count(T const& value) const
74 return base::count(object(value));
77 template <class T>
78 void extend(T const& x)
80 base::extend(object(x));
83 template <class T>
84 long index(T const& x) const
86 return base::index(object(x));
89 template <class T>
90 void insert(ssize_t index, T const& x) // insert object before index
92 base::insert(index, object(x));
95 template <class T>
96 void insert(object const& index, T const& x) // insert object before index
98 base::insert(index, object(x));
101 object pop() { return base::pop(); }
102 object pop(ssize_t index) { return base::pop(index); }
104 template <class T>
105 object pop(T const& index)
107 return base::pop(object(index));
110 template <class T>
111 void remove(T const& value)
113 base::remove(object(value));
116 void sort() { base::sort(); }
118 template <class T>
119 void sort(T const& value)
121 base::sort(object(value));
124 public: // implementation detail -- for internal use only
125 BOOST_PYTHON_FORWARD_OBJECT_CONSTRUCTORS(list, base)
129 // Converter Specializations
131 namespace converter
133 template <>
134 struct object_manager_traits<list>
135 : pytype_object_manager_traits<&PyList_Type,list>
140 }} // namespace boost::python
142 #endif // LIST_DWA2002627_HPP