Files
iterator/test/shared_iterator_test.cpp

78 lines
1.7 KiB
C++
Raw Permalink Normal View History

2017-05-29 19:10:46 +03:00
// Copyright 2003 The Trustees of Indiana University.
2020-03-04 01:06:45 +03:00
// Use, modification and distribution is subject to the Boost Software
2017-05-29 19:10:46 +03:00
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
2020-03-04 01:06:45 +03:00
// Shared container iterator adaptor
2017-05-29 19:10:46 +03:00
// Author: Ronald Garcia
2020-03-04 01:06:45 +03:00
// See http://boost.org/libs/utility/shared_container_iterator.html
// for documentation.
2017-05-29 19:10:46 +03:00
//
// shared_iterator_test.cpp - Regression tests for shared_container_iterator.
//
#include <boost/iterator/shared_container_iterator.hpp>
#include <boost/shared_ptr.hpp>
#include <boost/core/lightweight_test.hpp>
2017-05-29 19:10:46 +03:00
#include <vector>
#include <memory>
2017-05-29 19:10:46 +03:00
struct resource
{
2017-05-29 19:10:46 +03:00
static int count;
resource() { ++count; }
resource(resource const&) { ++count; }
~resource() { --count; }
};
int resource::count = 0;
typedef std::vector< resource > resources_t;
2017-05-29 19:10:46 +03:00
typedef boost::shared_container_iterator< resources_t > iterator;
template< typename SharedPtr >
void set_range(iterator& i, iterator& end)
{
SharedPtr objs(new resources_t());
2017-05-29 19:10:46 +03:00
for (int j = 0; j != 6; ++j)
objs->push_back(resource());
2020-03-04 01:06:45 +03:00
i = iterator(objs->begin(), objs);
end = iterator(objs->end(), objs);
BOOST_TEST_EQ(resource::count, 6);
2017-05-29 19:10:46 +03:00
}
int main() {
BOOST_TEST_EQ(resource::count, 0);
2020-03-04 01:06:45 +03:00
2017-05-29 19:10:46 +03:00
{
iterator i;
{
iterator end;
set_range< boost::shared_ptr< resources_t > >(i, end);
BOOST_TEST_EQ(resource::count, 6);
}
BOOST_TEST_EQ(resource::count, 6);
}
BOOST_TEST_EQ(resource::count, 0);
{
iterator i;
{
iterator end;
set_range< std::shared_ptr< resources_t > >(i, end);
BOOST_TEST_EQ(resource::count, 6);
2017-05-29 19:10:46 +03:00
}
BOOST_TEST_EQ(resource::count, 6);
2017-05-29 19:10:46 +03:00
}
BOOST_TEST_EQ(resource::count, 0);
2020-03-04 01:06:45 +03:00
return boost::report_errors();
2017-05-29 19:10:46 +03:00
}