nullary_function_adaptor.hpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // Copyright David Abrahams 2003.
  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 NULLARY_FUNCTION_ADAPTOR_DWA2003824_HPP
  6. # define NULLARY_FUNCTION_ADAPTOR_DWA2003824_HPP
  7. # include <boost/python/detail/prefix.hpp>
  8. # include <boost/preprocessor/iteration/local.hpp>
  9. # include <boost/preprocessor/facilities/intercept.hpp>
  10. # include <boost/preprocessor/repetition/enum_params.hpp>
  11. # include <boost/preprocessor/repetition/enum_binary_params.hpp>
  12. namespace boost { namespace python { namespace detail {
  13. // nullary_function_adaptor -- a class template which ignores its
  14. // arguments and calls a nullary function instead. Used for building
  15. // error-reporting functions, c.f. pure_virtual
  16. template <class NullaryFunction>
  17. struct nullary_function_adaptor
  18. {
  19. nullary_function_adaptor(NullaryFunction fn)
  20. : m_fn(fn)
  21. {}
  22. void operator()() const { m_fn(); }
  23. # define BOOST_PP_LOCAL_MACRO(i) \
  24. template <BOOST_PP_ENUM_PARAMS_Z(1, i, class A)> \
  25. void operator()( \
  26. BOOST_PP_ENUM_BINARY_PARAMS_Z(1, i, A, const& BOOST_PP_INTERCEPT) \
  27. ) const \
  28. { \
  29. m_fn(); \
  30. }
  31. # define BOOST_PP_LOCAL_LIMITS (1, BOOST_PYTHON_MAX_ARITY)
  32. # include BOOST_PP_LOCAL_ITERATE()
  33. private:
  34. NullaryFunction m_fn;
  35. };
  36. }}} // namespace boost::python::detail
  37. #endif // NULLARY_FUNCTION_ADAPTOR_DWA2003824_HPP