Boost C++ Libraries

...one of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

Boost.Python - <boost/python/list.hpp>

Boost.Python

Header

Contents

Introduction
Classes
Class list
Class list synopsis
Example(s)

Introduction

Exposes a TypeWrapper for the Python list type.

Classes

Class list

Exposes the 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 TypeWrapper concept definition. Since list is publicly derived from object, the public object interface applies to list instances as well.

Class list synopsis

namespace boost { namespace python
{
  class list : public object
  {
   public:
      list(); // new list

      template 
      explicit list(T const& sequence);

      template 
      void append(T const& x);

      template 
      long count(T const& value) const;

      template 
      void extend(T const& x);

      template 
      long index(T const& x) const;

      template 
      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 
      void remove(T const& value);

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

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

      template 
      void sort(T const& value);
  };
}}

Example

using namespace boost::python;

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

Revised 1 October, 2002

© Copyright Dave Abrahams 2002.