]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/23_containers/forward_list/debug/swap.cc
1 // { dg-options "-std=gnu++11" }
3 // Copyright (C) 2010-2016 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 bool test
__attribute__((unused
)) = true;
30 std::forward_list
<int> fl1
{1, 3, 5};
31 std::forward_list
<int> fl2
{2, 4, 6};
33 std::vector
<std::forward_list
<int>::iterator
> fl1_its
;
34 fl1_its
.push_back(fl1
.before_begin());
35 for (std::forward_list
<int>::iterator it
= fl1
.begin();
36 it
!= fl1
.end(); ++it
)
38 fl1_its
.push_back(it
);
40 fl1_its
.push_back(fl1
.end());
42 std::vector
<std::forward_list
<int>::iterator
> fl2_its
;
43 fl2_its
.push_back(fl2
.before_begin());
44 for (std::forward_list
<int>::iterator it
= fl2
.begin();
45 it
!= fl2
.end(); ++it
)
47 fl2_its
.push_back(it
);
49 fl2_its
.push_back(fl2
.end());
53 auto fit
= fl1
.before_begin();
54 // before-begin iterator is not transfered:
55 // TODO: Validate with LWG group how before begin should be
57 VERIFY( fit
== fl1_its
[0] );
58 // All other iterators are, even paste-the-end ones:
59 for (size_t i
= 1; i
!= fl2_its
.size(); ++i
)
61 VERIFY( ++fit
== fl2_its
[i
] );
64 fit
= fl2
.before_begin();
65 // TODO: Validate with LWG group how before begin should be
67 VERIFY( fit
== fl2_its
[0] );
68 for (size_t i
= 1; i
!= fl1_its
.size(); ++i
)
70 VERIFY( ++fit
== fl1_its
[i
] );