Imported Upstream version 1.51.0
[platform/upstream/boost.git] / libs / local_function / test / typeof_template.cpp
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 <boost/config.hpp>
9 #ifdef BOOST_NO_VARIADIC_MACROS
10 #   error "variadic macros required"
11 #else
12
13 #include "addable.hpp"
14 #include <boost/local_function.hpp>
15 #include <boost/type_traits/remove_reference.hpp>
16 #include <boost/concept_check.hpp>
17 #include <boost/detail/lightweight_test.hpp>
18 #include <algorithm>
19
20 //[typeof_template
21 template<typename T>
22 T calculate(const T& factor) {
23     T sum = 0;
24
25     void BOOST_LOCAL_FUNCTION_TPL(const bind factor, bind& sum, T num) {
26         // Local function `TYPEOF` does not need `typename`.
27         BOOST_CONCEPT_ASSERT((Addable<typename boost::remove_reference<
28                 BOOST_LOCAL_FUNCTION_TYPEOF(sum)>::type>));
29         sum += factor * num;
30     } BOOST_LOCAL_FUNCTION_NAME_TPL(add)
31
32     add(6);
33     return sum;
34 }
35 //]
36
37 int main(void) {
38     BOOST_TEST(calculate(10) == 60);
39     return boost::report_errors();
40 }
41
42 #endif // VARIADIC_MACROS
43