typeof_template_seq.cpp 939 B

123456789101112131415161718192021222324252627282930313233
  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. template<typename T>
  13. T calculate(const T& factor) {
  14. T sum = 0;
  15. void BOOST_LOCAL_FUNCTION_TPL( (const bind factor) (bind& sum) (T num) ) {
  16. BOOST_CONCEPT_ASSERT((Addable<typename boost::remove_reference<
  17. BOOST_LOCAL_FUNCTION_TYPEOF(sum)>::type>));
  18. sum += factor * num;
  19. } BOOST_LOCAL_FUNCTION_NAME_TPL(add)
  20. add(6);
  21. return sum;
  22. }
  23. int main(void) {
  24. BOOST_TEST(calculate(10) == 60);
  25. return boost::report_errors();
  26. }