invoke_int_0_pass.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //===----------------------------------------------------------------------===//
  2. //
  3. // The LLVM Compiler Infrastructure
  4. //
  5. // This file is dual licensed under the MIT and the University of Illinois Open
  6. // Source Licenses. See LICENSE.TXT for details.
  7. //
  8. //===----------------------------------------------------------------------===//
  9. // Copyright (C) 2014 Vicente J. Botet Escriba
  10. //
  11. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  12. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  13. // <boost/thread/detail/invoke.hpp>
  14. #include <boost/thread/detail/invoke.hpp>
  15. #include <boost/detail/lightweight_test.hpp>
  16. int f()
  17. {
  18. return 1;
  19. }
  20. struct A_int_0
  21. {
  22. A_int_0()
  23. {
  24. }
  25. int operator()()
  26. {
  27. return 4;
  28. }
  29. int operator()() const
  30. {
  31. return 5;
  32. }
  33. };
  34. int main()
  35. {
  36. const A_int_0 ca;
  37. A_int_0 a;
  38. #if defined BOOST_THREAD_PROVIDES_INVOKE
  39. BOOST_TEST_EQ(boost::detail::invoke(f), 1);
  40. BOOST_TEST_EQ(boost::detail::invoke(&f), 1);
  41. BOOST_TEST_EQ(boost::detail::invoke(A_int_0()), 4);
  42. BOOST_TEST_EQ(boost::detail::invoke(a), 4);
  43. BOOST_TEST_EQ(boost::detail::invoke(ca), 5);
  44. #endif
  45. BOOST_TEST_EQ(boost::detail::invoke<int>(f), 1);
  46. BOOST_TEST_EQ(boost::detail::invoke<int>(&f), 1);
  47. BOOST_TEST_EQ(A_int_0()(), 4);
  48. #if defined BOOST_THREAD_PROVIDES_INVOKE || ! defined(BOOST_NO_CXX11_VARIADIC_TEMPLATES)
  49. BOOST_TEST_EQ(boost::detail::invoke<int>(A_int_0()), 4);
  50. #else
  51. //BOOST_TEST_EQ(boost::detail::invoke<int>(A_int_0()), 5);
  52. #endif
  53. BOOST_TEST_EQ(a(), 4);
  54. BOOST_TEST_EQ(boost::detail::invoke<int>(a), 4);
  55. BOOST_TEST_EQ(ca(), 5);
  56. BOOST_TEST_EQ(boost::detail::invoke<int>(ca), 5);
  57. return boost::report_errors();
  58. }