make_tuple.hpp 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. # ifndef BOOST_PYTHON_SYNOPSIS
  2. # // Copyright David Abrahams 2002.
  3. # // Distributed under the Boost Software License, Version 1.0. (See
  4. # // accompanying file LICENSE_1_0.txt or copy at
  5. # // http://www.boost.org/LICENSE_1_0.txt)
  6. # if !defined(BOOST_PP_IS_ITERATING)
  7. # error Boost.Python - do not include this file!
  8. # endif
  9. # define N BOOST_PP_ITERATION()
  10. # define BOOST_PYTHON_MAKE_TUPLE_ARG(z, N, ignored) \
  11. PyTuple_SET_ITEM( \
  12. result.ptr() \
  13. , N \
  14. , python::incref(python::object(a##N).ptr()) \
  15. );
  16. template <BOOST_PP_ENUM_PARAMS_Z(1, N, class A)>
  17. tuple
  18. make_tuple(BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, const& a))
  19. {
  20. tuple result((detail::new_reference)::PyTuple_New(N));
  21. BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_MAKE_TUPLE_ARG, _)
  22. return result;
  23. }
  24. # undef BOOST_PYTHON_MAKE_TUPLE_ARG
  25. # undef N
  26. # endif // BOOST_PYTHON_SYNOPSIS