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/utility/identity_type.hpp> |
15 | #include <boost/typeof/std/string.hpp> // Type-of registrations |
16 | #include <boost/typeof/std/map.hpp> // needed for `NAME` macro. |
17 | #include <map> |
18 | #include <string> |
19 | |
20 | std::string cat(const std::string& x, const std::string& y) { return x + y; } |
21 | |
22 | template<typename V, typename K> |
23 | struct key_sizeof { |
24 | static int const value; |
25 | }; |
26 | |
27 | template<typename V, typename K> |
28 | int const key_sizeof<V, K>::value = sizeof(K); |
29 | |
30 | typedef int sign_t; |
31 | |
32 | int main(void) { |
33 | //[macro_commas |
34 | void BOOST_LOCAL_FUNCTION( |
35 | BOOST_IDENTITY_TYPE((const std::map<std::string, size_t>&)) m, |
36 | BOOST_IDENTITY_TYPE((::sign_t)) sign, |
37 | const size_t& factor, |
38 | default (key_sizeof<std::string, size_t>::value), |
39 | const std::string& separator, default cat(":" , " " ) |
40 | ) { |
41 | // Do something... |
42 | } BOOST_LOCAL_FUNCTION_NAME(f) |
43 | //] |
44 | |
45 | std::map<std::string, size_t> m; |
46 | ::sign_t sign = -1; |
47 | f(m, sign); |
48 | return 0; |
49 | } |
50 | |
51 | #endif // VARIADIC_MACROS |
52 | |
53 | |