result_type_wrapper.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // Boost.Signals2 library
  2. // Copyright Douglas Gregor 2001-2004.
  3. // Copyright Frank Mori Hess 2007. Use, modification and
  4. // distribution is subject to the Boost Software License, Version
  5. // 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  6. // http://www.boost.org/LICENSE_1_0.txt)
  7. // For more information, see http://www.boost.org
  8. #ifndef BOOST_SIGNALS2_RESULT_TYPE_WRAPPER_HPP
  9. #define BOOST_SIGNALS2_RESULT_TYPE_WRAPPER_HPP
  10. #include <boost/config.hpp>
  11. namespace boost {
  12. namespace signals2 {
  13. namespace detail {
  14. // A placeholder for void on compilers that don't support void returns
  15. struct void_type {};
  16. // Replaces void with void_type
  17. template<typename R>
  18. struct nonvoid {
  19. typedef R type;
  20. };
  21. template<>
  22. struct nonvoid<void> {
  23. typedef void_type type;
  24. };
  25. // Replaces void with void_type only if compiler doesn't support void returns
  26. template<typename R>
  27. struct result_type_wrapper {
  28. typedef R type;
  29. };
  30. #ifdef BOOST_NO_VOID_RETURNS
  31. template<>
  32. struct result_type_wrapper<void> {
  33. typedef void_type type;
  34. };
  35. #endif
  36. // specialization deals with possible void return from combiners
  37. template<typename R> class combiner_invoker
  38. {
  39. public:
  40. typedef R result_type;
  41. template<typename Combiner, typename InputIterator>
  42. result_type operator()(Combiner &combiner,
  43. InputIterator first, InputIterator last) const
  44. {
  45. return combiner(first, last);
  46. }
  47. };
  48. template<> class combiner_invoker<void>
  49. {
  50. public:
  51. typedef result_type_wrapper<void>::type result_type;
  52. template<typename Combiner, typename InputIterator>
  53. result_type operator()(Combiner &combiner,
  54. InputIterator first, InputIterator last) const
  55. {
  56. combiner(first, last);
  57. return result_type();
  58. }
  59. };
  60. } // end namespace detail
  61. } // end namespace signals2
  62. } // end namespace boost
  63. #endif // BOOST_SIGNALS2_RESULT_TYPE_WRAPPER_HPP