typeof.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (C) 2009-2012 Lorenzo Caminiti
  2. // Distributed under the Boost Software License, Version 1.0
  3. // (see accompanying file LICENSE_1_0.txt or a copy at
  4. // http://www.boost.org/LICENSE_1_0.txt)
  5. // Home at http://www.boost.org/libs/local_function
  6. #include <boost/config.hpp>
  7. #ifdef BOOST_NO_CXX11_VARIADIC_MACROS
  8. # error "variadic macros required"
  9. #else
  10. #include "addable.hpp"
  11. #include <boost/local_function.hpp>
  12. #include <boost/type_traits/remove_reference.hpp>
  13. #include <boost/concept_check.hpp>
  14. #include <boost/detail/lightweight_test.hpp>
  15. #include <algorithm>
  16. int main(void) {
  17. //[typeof
  18. int sum = 0, factor = 10;
  19. void BOOST_LOCAL_FUNCTION(const bind factor, bind& sum, int num) {
  20. // Type-of for concept checking.
  21. BOOST_CONCEPT_ASSERT((Addable<boost::remove_reference<
  22. BOOST_LOCAL_FUNCTION_TYPEOF(sum)>::type>));
  23. // Type-of for declarations.
  24. boost::remove_reference<BOOST_LOCAL_FUNCTION_TYPEOF(
  25. factor)>::type mult = factor * num;
  26. sum += mult;
  27. } BOOST_LOCAL_FUNCTION_NAME(add)
  28. add(6);
  29. //]
  30. BOOST_TEST(sum == 60);
  31. return boost::report_errors();
  32. }
  33. #endif // VARIADIC_MACROS