1 2 // Copyright (C) 2009-2012 Lorenzo Caminiti 3 // Distributed under the Boost Software License, Version 1.0 4 // (see accompanying file LICENSE_1_0.txt or a copy at 5 // http://www.boost.org/LICENSE_1_0.txt) 6 // Home at http://www.boost.org/libs/local_function 7 8 #include "addable.hpp" 9 #include <boost/local_function.hpp> 10 #include <boost/type_traits/remove_reference.hpp> 11 #include <boost/concept_check.hpp> 12 #include <boost/detail/lightweight_test.hpp> 13 #include <algorithm> 14 15 template<typename T> calculate(const T & factor)16T calculate(const T& factor) { 17 T sum = 0; 18 19 void BOOST_LOCAL_FUNCTION_TPL( (const bind factor) (bind& sum) (T num) ) { 20 BOOST_CONCEPT_ASSERT((Addable<typename boost::remove_reference< 21 BOOST_LOCAL_FUNCTION_TYPEOF(sum)>::type>)); 22 sum += factor * num; 23 } BOOST_LOCAL_FUNCTION_NAME_TPL(add) 24 25 add(6); 26 return sum; 27 } 28 main(void)29int main(void) { 30 BOOST_TEST(calculate(10) == 60); 31 return boost::report_errors(); 32 } 33 34