num_list2.qbk 1.1 KB

123456789101112131415161718192021222324252627282930
  1. [/==============================================================================
  2. Copyright (C) 2001-2011 Joel de Guzman
  3. Copyright (C) 2001-2011 Hartmut Kaiser
  4. Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  6. ===============================================================================/]
  7. [section Number List - stuffing numbers into a std::vector]
  8. This sample demonstrates a parser for a comma separated list of numbers. The
  9. numbers are inserted in a vector using phoenix.
  10. [import ../../example/qi/num_list2.cpp]
  11. [tutorial_numlist2]
  12. The full cpp file for this example can be found here: [@../../example/qi/num_list2.cpp]
  13. This, again, is the same parser as before. This time, instead of summing up the
  14. numbers, we stuff them in a `std::vector`. `push_back` is supplied by
  15. __phoenix__. The expression:
  16. push_back(ref(v), _1)
  17. appends the parsed number. Like before, `_1` is a __phoenix__ placeholder for
  18. the parsed result attribute. Also, like before, `ref(v)` tells __phoenix__ that
  19. `v`, the `std::vector`, is a mutable reference.
  20. [endsect]