| 1 | /*============================================================================= |
|---|
| 2 | Copyright (c) 2003 Joel de Guzman |
|---|
| 3 | |
|---|
| 4 | Use, modification and distribution is subject to the Boost Software |
|---|
| 5 | License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at |
|---|
| 6 | http://www.boost.org/LICENSE_1_0.txt) |
|---|
| 7 | ==============================================================================*/ |
|---|
| 8 | #include <boost/detail/lightweight_test.hpp> |
|---|
| 9 | #include <boost/spirit/fusion/sequence/tuple.hpp> |
|---|
| 10 | #include <boost/spirit/fusion/sequence/io.hpp> |
|---|
| 11 | #include <boost/spirit/fusion/sequence/make_tuple.hpp> |
|---|
| 12 | #include <boost/spirit/fusion/sequence/equal_to.hpp> |
|---|
| 13 | #include <boost/spirit/fusion/iterator/tuple_iterator.hpp> |
|---|
| 14 | #include <boost/spirit/fusion/algorithm/replace.hpp> |
|---|
| 15 | #include <boost/mpl/vector_c.hpp> |
|---|
| 16 | #include <boost/mpl/begin_end.hpp> |
|---|
| 17 | #include <boost/mpl/advance.hpp> |
|---|
| 18 | #include <boost/mpl/int.hpp> |
|---|
| 19 | #include <string> |
|---|
| 20 | |
|---|
| 21 | int |
|---|
| 22 | main() |
|---|
| 23 | { |
|---|
| 24 | using namespace boost::fusion; |
|---|
| 25 | using boost::mpl::vector_c; |
|---|
| 26 | using boost::mpl::advance; |
|---|
| 27 | using boost::mpl::int_; |
|---|
| 28 | namespace mpl = boost::mpl; |
|---|
| 29 | |
|---|
| 30 | std::cout << tuple_open('['); |
|---|
| 31 | std::cout << tuple_close(']'); |
|---|
| 32 | std::cout << tuple_delimiter(", "); |
|---|
| 33 | |
|---|
| 34 | /// Testing replace |
|---|
| 35 | |
|---|
| 36 | { |
|---|
| 37 | char const* s = "Ruby"; |
|---|
| 38 | typedef tuple<int, char, double, char const*> tuple_type; |
|---|
| 39 | tuple_type t(1, 'x', 3.3, s); |
|---|
| 40 | tuple_iterator<2, tuple_type> pos(t); |
|---|
| 41 | |
|---|
| 42 | std::cout << replace(t, pos, 123456) << std::endl; |
|---|
| 43 | BOOST_TEST((replace(t, pos, 123456) |
|---|
| 44 | == make_tuple(1, 'x', 123456, s))); |
|---|
| 45 | |
|---|
| 46 | std::cout << replace(t, begin(t), "happy") << std::endl; |
|---|
| 47 | BOOST_TEST((replace(t, begin(t), "happy") |
|---|
| 48 | == make_tuple(std::string("happy"), 'x', 3.3, s))); |
|---|
| 49 | } |
|---|
| 50 | |
|---|
| 51 | { |
|---|
| 52 | typedef vector_c<int, 1, 2, 3, 4, 5> mpl_vec; |
|---|
| 53 | typedef mpl::begin<mpl_vec>::type mpl_vec_begin; |
|---|
| 54 | typedef advance<mpl_vec_begin, int_<3> >::type mpl_vec_at3; |
|---|
| 55 | |
|---|
| 56 | std::cout << replace(mpl_vec(), mpl_vec_at3(), int_<66>()) << std::endl; |
|---|
| 57 | BOOST_TEST((replace(mpl_vec(), mpl_vec_at3(), int_<66>()) |
|---|
| 58 | == make_tuple(1, 2, 3, 66, 5))); |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | return boost::report_errors(); |
|---|
| 62 | } |
|---|
| 63 | |
|---|