| 1 | //----------------------------------------------------------------------------- |
| 2 | // boost-libs variant/test/test-swap.cpp source file |
| 3 | // See http://www.boost.org for updates, documentation, and revision history. |
| 4 | //----------------------------------------------------------------------------- |
| 5 | // |
| 6 | // Copyright (c) 2009 ArtVPS Ltd. |
| 7 | // |
| 8 | // Distributed under the Boost Software License, Version 1.0. (See |
| 9 | // accompanying file LICENSE_1_0.txt or copy at |
| 10 | // http://www.boost.org/LICENSE_1_0.txt) |
| 11 | |
| 12 | #include "boost/test/minimal.hpp" |
| 13 | #include "boost/variant.hpp" |
| 14 | |
| 15 | #include <vector> |
| 16 | |
| 17 | void run() |
| 18 | { |
| 19 | |
| 20 | using boost::apply_visitor; |
| 21 | using boost::variant; |
| 22 | using std::cout; |
| 23 | using std::endl; |
| 24 | |
| 25 | typedef variant< int, std::vector<int>* > t_var; |
| 26 | |
| 27 | std::vector<int> vec; |
| 28 | t_var v0(23), v1(&vec); |
| 29 | |
| 30 | BOOST_REQUIRE(v0.which() == 0); |
| 31 | BOOST_REQUIRE(v1.which() == 1); |
| 32 | |
| 33 | swap(v0, v1); |
| 34 | |
| 35 | BOOST_CHECK(v0.which() == 1); |
| 36 | BOOST_CHECK(v1.which() == 0); |
| 37 | } |
| 38 | |
| 39 | |
| 40 | |
| 41 | int test_main(int , char* []) |
| 42 | { |
| 43 | run(); |
| 44 | return 0; |
| 45 | } |