Ticket #2073: slist_swap_test.cpp

File slist_swap_test.cpp, 1.2 KB (added by Hartmut Kaiser, 14 years ago)

Test code demonstrating problem.

Line 
1// Copyright (c) 2008 Hartmut Kaiser
2//
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/detail/lightweight_test.hpp>
7#include <boost/intrusive/slist.hpp>
8
9struct queue_entry
10{
11 typedef boost::intrusive::slist_member_hook<
12 boost::intrusive::link_mode<boost::intrusive::normal_link>
13 > hook_type;
14
15 queue_entry(int id)
16 : id_(id)
17 {}
18
19 int id_;
20 hook_type slist_hook_;
21};
22
23typedef boost::intrusive::member_hook<
24 queue_entry, queue_entry::hook_type, &queue_entry::slist_hook_
25> slist_option_type;
26
27typedef boost::intrusive::slist<
28 queue_entry, slist_option_type,
29 boost::intrusive::cache_last<true>,
30 boost::intrusive::constant_time_size<true>
31> queue_type;
32
33int main()
34{
35 queue_type queue1, queue2;
36
37 queue_entry e1(0), e2(2), e3(3), e4(4);
38 queue1.push_back(e1);
39 queue1.push_back(e2);
40 queue1.push_back(e3);
41 queue1.push_back(e4);
42
43// queue2.swap(queue1); // this works
44 queue1.swap(queue2); // this doesn't work
45
46 BOOST_TEST(!queue2.empty());
47 return boost::report_errors();
48}