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_CXX11_VARIADIC_MACROS
10 #   error "variadic macros required"
11 #else
12 
13 #include <boost/local_function.hpp>
14 #include <boost/functional/overloaded_function.hpp> // For overloading.
15 #include <boost/typeof/std/string.hpp>
16 #include <boost/detail/lightweight_test.hpp>
17 #include <string>
18 
19 //[overload_decl
add_i(int x,int y)20 int add_i(int x, int y) { return x + y; }
21 //]
22 
main(void)23 int main(void) {
24     //[overload
25     std::string s = "abc";
26     std::string BOOST_LOCAL_FUNCTION(
27             const bind& s, const std::string& x) {
28         return s + x;
29     } BOOST_LOCAL_FUNCTION_NAME(add_s)
30 
31     double d = 1.23;
32     double BOOST_LOCAL_FUNCTION(const bind d, double x, double y, default 0) {
33         return d + x + y;
34     } BOOST_LOCAL_FUNCTION_NAME(add_d)
35 
36     boost::overloaded_function<
37           std::string (const std::string&)
38         , double (double)
39         , double (double, double) // Overload giving default param.
40         , int (int, int)
41     > add(add_s, add_d, add_d, add_i); // Overloaded function object.
42 
43     BOOST_TEST(add("xyz") == "abcxyz"); // Call `add_s`.
44     BOOST_TEST((4.44 - add(3.21)) <= 0.001); // Call `add_d` (no default).
45     BOOST_TEST((44.44 - add(3.21, 40.0)) <= 0.001); // Call `add_d`.
46     BOOST_TEST(add(1, 2) == 3); // Call `add_i`.
47     //]
48     return boost::report_errors();
49 }
50 
51 #endif // VARIADIC_MACROS
52 
53