2001-02-12 21:35:20 +00:00
|
|
|
// (C) Copyright Jeremy Siek 2000. Permission to copy, use, modify, sell and
|
|
|
|
// distribute this software is granted provided this copyright notice appears
|
|
|
|
// in all copies. This software is provided "as is" without express or implied
|
|
|
|
// warranty, and with no claim as to its suitability for any purpose.
|
|
|
|
|
|
|
|
|
|
|
|
#include <boost/config.hpp>
|
2003-07-20 19:17:18 +00:00
|
|
|
#include <algorithm>
|
2001-02-12 21:35:20 +00:00
|
|
|
#include <iostream>
|
2001-02-12 21:57:19 +00:00
|
|
|
#include <iterator>
|
|
|
|
#include <vector>
|
2003-07-12 04:15:13 +00:00
|
|
|
#include <boost/iterator/counting_iterator.hpp>
|
|
|
|
#include <boost/iterator/indirect_iterator.hpp>
|
2001-02-12 21:35:20 +00:00
|
|
|
|
|
|
|
int main(int, char*[])
|
|
|
|
{
|
|
|
|
// Example of using counting_iterator_generator
|
|
|
|
std::cout << "counting from 0 to 4:" << std::endl;
|
2003-07-12 04:15:13 +00:00
|
|
|
boost::counting_iterator<int> first(0), last(4);
|
2001-02-12 21:35:20 +00:00
|
|
|
std::copy(first, last, std::ostream_iterator<int>(std::cout, " "));
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
|
|
|
// Example of using make_counting_iterator()
|
2001-02-12 21:57:19 +00:00
|
|
|
std::cout << "counting from -5 to 4:" << std::endl;
|
2001-02-12 21:35:20 +00:00
|
|
|
std::copy(boost::make_counting_iterator(-5),
|
2002-02-04 20:29:35 +00:00
|
|
|
boost::make_counting_iterator(5),
|
|
|
|
std::ostream_iterator<int>(std::cout, " "));
|
2001-02-12 21:35:20 +00:00
|
|
|
std::cout << std::endl;
|
|
|
|
|
2001-02-12 21:57:19 +00:00
|
|
|
// Example of using counting iterator to create an array of pointers.
|
Preparation for delivering nicely-formatted error messages in
Boost.Python. The major change is that, instead of being
boost::function2<PyObject*,PyObject*,PyObject*>, py_function is now a
runtime-polymorphic wrapper for compile-time polymorphic
behavior (just like function) of our own which carries more
information/behaviors. In particular, you can retrieve an array of
c-strings describing the types in the function signature.
Additionally, the minimum and maximum arity are stored in the
py_function object instead of in the 'function' object which wraps it.
* data_members.hpp -
Adjustments for the new py_function. Workarounds for CodeWarrior
Pro 8.3 bugs in function template argument deduction with
pointers-to-members.
* has_back_reference.hpp, test/back_reference.cpp,
test/select_holder.cpp -
Updated to follow the metafunction protocol
* init.hpp, detail/defaults_gen.hpp -
Make Keywords a more-specific type in function signatures to
prevent string literals that show up as char[N] from binding to
the wrong argument (at least Intel 7.1 for Windows does this).
* make_function.hpp -
Adjustments for the new py_function. Arities are now computed
by caller<>.
* opaque_pointer_converter.hpp, type_id.hpp -
Use BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS facilities;
generate specializations that all compilers can handle.
* raw_function.hpp -
Adjustments for the new py_function.
* caller.hpp -
Added arity and signature type name reporting.
* detail/config.hpp
Enable __declspec(dllexport) for Cygwin, thereby fixing the
recent horrible Cygwin linking problems.
* detail/msvc_typeinfo.hpp -
Always pass boost::type<T>* explicitly, thereby working around
incompatible notions of how to specialize function templates with
default arguments on various compilers.
* object/function.hpp
, object/function_handle.hpp
, object/function_object.hpp
, object/function_object.cpp
Adjustments for the new py_function. Arities are carried by
py_function.
* object/iterator.hpp, object/iterator.cpp
Adjustments for the new py_function; we have to compute a
signature of types to construct it with.
* object/py_function.hpp
Removed dependency on boost::function; see the comment at the
top of this entry for more details.
* object/select_holder.hpp
Clean up to more closely follow MPL idioms.
* test/Jamfile -
Adjust the embedding test for the new Cygwin use of declspec.
Update bases and pointee tests with missing properties.
* test/input_iterator.cpp -
Updates for the new iterator adaptors.
* test/opaque.py -
Add Python encoding comment to suppress PendinDeprecationWarning
with recent Python builds.
* test/str.cpp
Pass a Python long instead of a float to string.expandtabs,
suppressing a PendinDeprecationWarning with recent Python builds.
* libs/utility/counting_iterator_example.cpp
Borland workaround
* libs/utility/indirect_iterator_example.cpp
const-correctness fix.
*
[SVN r19247]
2003-07-22 00:06:41 +00:00
|
|
|
#if !BOOST_WORKAROUND(__BORLANDC__, BOOST_TESTED_AT(0x551))
|
|
|
|
const
|
|
|
|
#endif
|
|
|
|
int N = 7;
|
2001-02-12 21:57:19 +00:00
|
|
|
std::vector<int> numbers;
|
|
|
|
// Fill "numbers" array with [0,N)
|
Preparation for delivering nicely-formatted error messages in
Boost.Python. The major change is that, instead of being
boost::function2<PyObject*,PyObject*,PyObject*>, py_function is now a
runtime-polymorphic wrapper for compile-time polymorphic
behavior (just like function) of our own which carries more
information/behaviors. In particular, you can retrieve an array of
c-strings describing the types in the function signature.
Additionally, the minimum and maximum arity are stored in the
py_function object instead of in the 'function' object which wraps it.
* data_members.hpp -
Adjustments for the new py_function. Workarounds for CodeWarrior
Pro 8.3 bugs in function template argument deduction with
pointers-to-members.
* has_back_reference.hpp, test/back_reference.cpp,
test/select_holder.cpp -
Updated to follow the metafunction protocol
* init.hpp, detail/defaults_gen.hpp -
Make Keywords a more-specific type in function signatures to
prevent string literals that show up as char[N] from binding to
the wrong argument (at least Intel 7.1 for Windows does this).
* make_function.hpp -
Adjustments for the new py_function. Arities are now computed
by caller<>.
* opaque_pointer_converter.hpp, type_id.hpp -
Use BOOST_NO_EXPLICIT_FUNCTION_TEMPLATE_ARGUMENTS facilities;
generate specializations that all compilers can handle.
* raw_function.hpp -
Adjustments for the new py_function.
* caller.hpp -
Added arity and signature type name reporting.
* detail/config.hpp
Enable __declspec(dllexport) for Cygwin, thereby fixing the
recent horrible Cygwin linking problems.
* detail/msvc_typeinfo.hpp -
Always pass boost::type<T>* explicitly, thereby working around
incompatible notions of how to specialize function templates with
default arguments on various compilers.
* object/function.hpp
, object/function_handle.hpp
, object/function_object.hpp
, object/function_object.cpp
Adjustments for the new py_function. Arities are carried by
py_function.
* object/iterator.hpp, object/iterator.cpp
Adjustments for the new py_function; we have to compute a
signature of types to construct it with.
* object/py_function.hpp
Removed dependency on boost::function; see the comment at the
top of this entry for more details.
* object/select_holder.hpp
Clean up to more closely follow MPL idioms.
* test/Jamfile -
Adjust the embedding test for the new Cygwin use of declspec.
Update bases and pointee tests with missing properties.
* test/input_iterator.cpp -
Updates for the new iterator adaptors.
* test/opaque.py -
Add Python encoding comment to suppress PendinDeprecationWarning
with recent Python builds.
* test/str.cpp
Pass a Python long instead of a float to string.expandtabs,
suppressing a PendinDeprecationWarning with recent Python builds.
* libs/utility/counting_iterator_example.cpp
Borland workaround
* libs/utility/indirect_iterator_example.cpp
const-correctness fix.
*
[SVN r19247]
2003-07-22 00:06:41 +00:00
|
|
|
std::copy(
|
|
|
|
boost::make_counting_iterator(0)
|
|
|
|
, boost::make_counting_iterator(N)
|
|
|
|
, std::back_inserter(numbers));
|
2001-02-12 21:59:25 +00:00
|
|
|
|
|
|
|
std::vector<std::vector<int>::iterator> pointers;
|
2001-02-12 21:35:20 +00:00
|
|
|
|
2001-02-12 21:57:19 +00:00
|
|
|
// Use counting iterator to fill in the array of pointers.
|
2002-07-13 12:22:51 +00:00
|
|
|
// causes an ICE with MSVC6
|
2001-02-12 21:57:19 +00:00
|
|
|
std::copy(boost::make_counting_iterator(numbers.begin()),
|
2002-02-04 20:29:35 +00:00
|
|
|
boost::make_counting_iterator(numbers.end()),
|
|
|
|
std::back_inserter(pointers));
|
2001-02-12 21:57:19 +00:00
|
|
|
|
|
|
|
// Use indirect iterator to print out numbers by accessing
|
|
|
|
// them through the array of pointers.
|
|
|
|
std::cout << "indirectly printing out the numbers from 0 to "
|
2002-02-04 20:29:35 +00:00
|
|
|
<< N << std::endl;
|
2001-02-12 21:57:19 +00:00
|
|
|
std::copy(boost::make_indirect_iterator(pointers.begin()),
|
2002-02-04 20:29:35 +00:00
|
|
|
boost::make_indirect_iterator(pointers.end()),
|
|
|
|
std::ostream_iterator<int>(std::cout, " "));
|
2001-02-12 21:57:19 +00:00
|
|
|
std::cout << std::endl;
|
2003-07-12 04:15:13 +00:00
|
|
|
|
2001-02-12 21:35:20 +00:00
|
|
|
return 0;
|
|
|
|
}
|