]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/test/input_iterator.cpp
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>
12 using namespace boost::python
;
14 typedef std::list
<int> list_int
;
16 // Prove that we can handle InputIterators which return rvalues.
19 typedef int result_type
;
20 int operator()(int x
) const { return x
* 2; }
23 typedef boost::transform_iterator
<doubler
, list_int::iterator
> doubling_iterator
;
24 typedef std::pair
<doubling_iterator
,doubling_iterator
> list_range2
;
26 list_range2
range2(list_int
& x
)
29 boost::make_transform_iterator
<doubler
>(x
.begin(), doubler())
30 , boost::make_transform_iterator
<doubler
>(x
.end(), doubler()));
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.
37 BOOST_PYTHON_MODULE(input_iterator
)
39 def("range2", &::range2
);
41 class_
<list_range2
>("list_range2")
42 // We can wrap InputIterators which return by-value
44 , range(&list_range2::first
, &list_range2::second
))
48 #include "module_tail.cpp"