]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/forward_list/debug/swap.cc
1 // { dg-do run { target c++11 } }
3 // Copyright (C) 2010-2019 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 3, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
20 // Check that iterators ownership is correctly manage on swap.
22 #include <forward_list>
24 #include <testsuite_hooks.h>
29 std::forward_list
<int> fl1
{1, 3, 5};
30 std::forward_list
<int> fl2
{2, 4, 6};
32 std::vector
<std::forward_list
<int>::iterator
> fl1_its
;
33 fl1_its
.push_back(fl1
.before_begin());
34 for (std::forward_list
<int>::iterator it
= fl1
.begin();
35 it
!= fl1
.end(); ++it
)
37 fl1_its
.push_back(it
);
39 fl1_its
.push_back(fl1
.end());
41 std::vector
<std::forward_list
<int>::iterator
> fl2_its
;
42 fl2_its
.push_back(fl2
.before_begin());
43 for (std::forward_list
<int>::iterator it
= fl2
.begin();
44 it
!= fl2
.end(); ++it
)
46 fl2_its
.push_back(it
);
48 fl2_its
.push_back(fl2
.end());
52 auto fit
= fl1
.before_begin();
53 // before-begin iterator is not transfered:
54 // TODO: Validate with LWG group how before begin should be
56 VERIFY( fit
== fl1_its
[0] );
57 // All other iterators are, even paste-the-end ones:
58 for (size_t i
= 1; i
!= fl2_its
.size(); ++i
)
60 VERIFY( ++fit
== fl2_its
[i
] );
63 fit
= fl2
.before_begin();
64 // TODO: Validate with LWG group how before begin should be
66 VERIFY( fit
== fl2_its
[0] );
67 for (size_t i
= 1; i
!= fl1_its
.size(); ++i
)
69 VERIFY( ++fit
== fl1_its
[i
] );