macro_commas.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 <boost/config.hpp>
  7. #ifdef BOOST_NO_CXX11_VARIADIC_MACROS
  8. # error "variadic macros required"
  9. #else
  10. #include <boost/local_function.hpp>
  11. #include <boost/utility/identity_type.hpp>
  12. #include <boost/typeof/std/string.hpp> // Type-of registrations
  13. #include <boost/typeof/std/map.hpp> // needed for `NAME` macro.
  14. #include <map>
  15. #include <string>
  16. std::string cat(const std::string& x, const std::string& y) { return x + y; }
  17. template<typename V, typename K>
  18. struct key_sizeof {
  19. static int const value;
  20. };
  21. template<typename V, typename K>
  22. int const key_sizeof<V, K>::value = sizeof(K);
  23. typedef int sign_t;
  24. int main(void) {
  25. //[macro_commas
  26. void BOOST_LOCAL_FUNCTION(
  27. BOOST_IDENTITY_TYPE((const std::map<std::string, size_t>&)) m,
  28. BOOST_IDENTITY_TYPE((::sign_t)) sign,
  29. const size_t& factor,
  30. default (key_sizeof<std::string, size_t>::value),
  31. const std::string& separator, default cat(":", " ")
  32. ) {
  33. // Do something...
  34. } BOOST_LOCAL_FUNCTION_NAME(f)
  35. //]
  36. std::map<std::string, size_t> m;
  37. ::sign_t sign = -1;
  38. f(m, sign);
  39. return 0;
  40. }
  41. #endif // VARIADIC_MACROS