]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/python/test/input_iterator.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / boost / libs / python / test / input_iterator.cpp
CommitLineData
7c673cae
FG
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#include <boost/python/module.hpp>
6#include <boost/python/def.hpp>
7#include <boost/python/class.hpp>
8#include <boost/python/iterator.hpp>
9#include <boost/iterator/transform_iterator.hpp>
10#include <list>
11
12using namespace boost::python;
13
14typedef std::list<int> list_int;
15
16// Prove that we can handle InputIterators which return rvalues.
17struct doubler
18{
19 typedef int result_type;
20 int operator()(int x) const { return x * 2; }
21};
22
23typedef boost::transform_iterator<doubler, list_int::iterator> doubling_iterator;
24typedef std::pair<doubling_iterator,doubling_iterator> list_range2;
25
26list_range2 range2(list_int& x)
27{
28 return list_range2(
29 boost::make_transform_iterator<doubler>(x.begin(), doubler())
30 , boost::make_transform_iterator<doubler>(x.end(), doubler()));
31}
32
33// We do this in a separate module from iterators_ext (iterators.cpp)
34// to work around an MSVC6 linker bug, which causes it to complain
35// about a "duplicate comdat" if the input iterator is instantiated in
36// the same module with the others.
37BOOST_PYTHON_MODULE(input_iterator)
38{
39 def("range2", &::range2);
40
41 class_<list_range2>("list_range2")
42 // We can wrap InputIterators which return by-value
43 .def("__iter__"
44 , range(&list_range2::first, &list_range2::second))
45 ;
46}
47
48#include "module_tail.cpp"