return_internal_reference.hpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. #ifndef RETURN_INTERNAL_REFERENCE_DWA2002131_HPP
  6. # define RETURN_INTERNAL_REFERENCE_DWA2002131_HPP
  7. # include <boost/python/detail/prefix.hpp>
  8. # include <boost/python/default_call_policies.hpp>
  9. # include <boost/python/reference_existing_object.hpp>
  10. # include <boost/python/with_custodian_and_ward.hpp>
  11. # include <boost/mpl/if.hpp>
  12. namespace boost { namespace python {
  13. namespace detail
  14. {
  15. template <std::size_t>
  16. struct return_internal_reference_owner_arg_must_be_greater_than_zero
  17. # if defined(__GNUC__) || defined(__EDG__)
  18. {}
  19. # endif
  20. ;
  21. }
  22. template <std::size_t owner_arg = 1, class BasePolicy_ = default_call_policies>
  23. struct return_internal_reference
  24. : with_custodian_and_ward_postcall<0, owner_arg, BasePolicy_>
  25. {
  26. private:
  27. BOOST_STATIC_CONSTANT(bool, legal = owner_arg > 0);
  28. public:
  29. typedef typename mpl::if_c<
  30. legal
  31. , reference_existing_object
  32. , detail::return_internal_reference_owner_arg_must_be_greater_than_zero<owner_arg>
  33. >::type result_converter;
  34. };
  35. }} // namespace boost::python
  36. #endif // RETURN_INTERNAL_REFERENCE_DWA2002131_HPP