context.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /*=============================================================================
  2. Copyright (c) 2001-2013 Joel de Guzman
  3. Distributed under the Boost Software License, Version 1.0. (See accompanying
  4. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. =============================================================================*/
  6. #include <boost/spirit/home/x3/support/context.hpp>
  7. #include <iostream>
  8. using boost::spirit::x3::make_context;
  9. using boost::spirit::x3::get;
  10. int bb;
  11. int cc;
  12. struct b_ctx;
  13. struct c_ctx;
  14. template <typename Context>
  15. void a(Context const& context)
  16. {
  17. bb = get<b_ctx>(context);
  18. cc = get<c_ctx>(context);
  19. }
  20. template <typename Context>
  21. void b(Context const& context)
  22. {
  23. int bi = 123;
  24. a(make_context<b_ctx>(bi, context));
  25. }
  26. void c()
  27. {
  28. int ci = 456;
  29. b(make_context<c_ctx>(ci));
  30. }
  31. void test()
  32. {
  33. c();
  34. // MSVC generates this code:
  35. // mov DWORD PTR ?bb@@3HA, 123
  36. // mov DWORD PTR ?cc@@3HA, 456
  37. //
  38. // GCC generates this code:
  39. // movl $123, _bb
  40. // movl $456, _cc
  41. }