macro_commas_seq.cpp 1.3 KB

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