select_functions.hpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // -- select_functions.hpp -- Boost Lambda Library --------------------------
  2. // Copyright (C) 1999, 2000 Jaakko Jarvi (jaakko.jarvi@cs.utu.fi)
  3. //
  4. // Distributed under the Boost Software License, Version 1.0. (See
  5. // accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. //
  8. // For more information, see http://www.boost.org
  9. #ifndef BOOST_LAMBDA_SELECT_FUNCTIONS_HPP
  10. #define BOOST_LAMBDA_SELECT_FUNCTIONS_HPP
  11. namespace boost {
  12. namespace lambda {
  13. namespace detail {
  14. // select functions -------------------------------
  15. template<class Any, CALL_TEMPLATE_ARGS>
  16. inline Any& select(Any& any, CALL_FORMAL_ARGS) { CALL_USE_ARGS; return any; }
  17. template<class Arg, CALL_TEMPLATE_ARGS>
  18. inline typename Arg::template sig<tuple<CALL_REFERENCE_TYPES> >::type
  19. select ( const lambda_functor<Arg>& op, CALL_FORMAL_ARGS ) {
  20. return op.template call<
  21. typename Arg::template sig<tuple<CALL_REFERENCE_TYPES> >::type
  22. >(CALL_ACTUAL_ARGS);
  23. }
  24. template<class Arg, CALL_TEMPLATE_ARGS>
  25. inline typename Arg::template sig<tuple<CALL_REFERENCE_TYPES> >::type
  26. select ( lambda_functor<Arg>& op, CALL_FORMAL_ARGS) {
  27. return op.template call<
  28. typename Arg::template sig<tuple<CALL_REFERENCE_TYPES> >::type
  29. >(CALL_ACTUAL_ARGS);
  30. }
  31. // ------------------------------------------------------------------------
  32. // select functions where the return type is explicitly given
  33. // Note: on many functions, this return type is just discarded.
  34. // The select functions are inside a class template, and the return type
  35. // is a class template argument.
  36. // The first implementation used function templates with an explicitly
  37. // specified template parameter.
  38. // However, this resulted in ambiguous calls (at least with gcc 2.95.2
  39. // and edg 2.44). Not sure whether the compilers were right or wrong.
  40. template<class RET> struct r_select {
  41. // Any == RET
  42. template<class Any, CALL_TEMPLATE_ARGS>
  43. static
  44. inline RET go (Any& any, CALL_FORMAL_ARGS) { CALL_USE_ARGS; return any; }
  45. template<class Arg, CALL_TEMPLATE_ARGS>
  46. static
  47. inline RET go (const lambda_functor<Arg>& op, CALL_FORMAL_ARGS ) {
  48. return op.template call<RET>(CALL_ACTUAL_ARGS);
  49. }
  50. template<class Arg, CALL_TEMPLATE_ARGS>
  51. static
  52. inline RET go (lambda_functor<Arg>& op, CALL_FORMAL_ARGS ) {
  53. return op.template call<RET>(CALL_ACTUAL_ARGS);
  54. }
  55. };
  56. } // namespace detail
  57. } // namespace lambda
  58. } // namespace boost
  59. #endif