typeof_seq.cpp 963 B

123456789101112131415161718192021222324252627282930
  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 "addable.hpp"
  7. #include <boost/local_function.hpp>
  8. #include <boost/type_traits/remove_reference.hpp>
  9. #include <boost/concept_check.hpp>
  10. #include <boost/detail/lightweight_test.hpp>
  11. #include <algorithm>
  12. int main(void) {
  13. int sum = 0, factor = 10;
  14. void BOOST_LOCAL_FUNCTION( (const bind factor) (bind& sum) (int num) ) {
  15. BOOST_CONCEPT_ASSERT((Addable<boost::remove_reference<
  16. BOOST_LOCAL_FUNCTION_TYPEOF(sum)>::type>));
  17. boost::remove_reference<BOOST_LOCAL_FUNCTION_TYPEOF(
  18. factor)>::type mult = factor * num;
  19. sum += mult;
  20. } BOOST_LOCAL_FUNCTION_NAME(add)
  21. add(6);
  22. BOOST_TEST(sum == 60);
  23. return boost::report_errors();
  24. }