mirror of
https://github.com/boostorg/iterator.git
synced 2025-11-03 18:01:37 +01:00
С++03 support was deprecated in 1.85 and now can be removed. This PR clears many of workarounds, which are no longer needed now. * Remove unused workaround macros (many of). * Remove BOOST_STATIC_ASSERT usages. * Minimize Boost::type_traits dependency (in favour of STL's type_traits). Closes https://github.com/boostorg/iterator/pull/82. Squashed commit of the following: commit741a627b73Author: Georgy Guminov <gogagum@gmail.com> Date: Sat Jan 25 12:13:05 2025 +0300 Replace testers with standard metafunctions. commitbf4cce6114Author: Georgy Guminov <gogagum@gmail.com> Date: Sat Jan 25 11:51:32 2025 +0300 Refactor is_lvalue_iterator.hpp. commit8d080c6c58Author: Georgy Guminov <gogagum@gmail.com> Date: Sat Jan 25 10:27:32 2025 +0300 Remove more workarounds. commit5a4ba24d36Author: Georgy Guminov <gogagum@gmail.com> Date: Sun Jan 19 16:38:30 2025 +0300 Fixes. commitfdfafce2b9Author: Georgy Guminov <gogagum@gmail.com> Date: Sat Oct 26 15:06:43 2024 +0300 Remove BOOST_NO_STRICT_ITERATOR_INTEROPERABILITY Correct static_assert messages. Fix messages & replace is_standard_layout with is_copy_constructible. commitc69ac1408aAuthor: Georgy Guminov <gogagum@gmail.com> Date: Sat Oct 26 14:48:51 2024 +0300 Correct static_assert messages. commitb5df827151Author: Georqy Guminov <gogagum@gmail.com> Date: Sun Jun 23 16:12:29 2024 +0300 Fixes. Remove some Boost.MPL usages. Remove unused includes. commit01fd35e9f8Author: Georgiy Guminov <gogagum@gmail.com> Date: Wed Jun 12 17:14:21 2024 +0300 abstract conjunction. commitc02def8acfAuthor: Georgiy Guminov <gogagum@gmail.com> Date: Wed Jun 12 16:35:43 2024 +0300 return addressof & conjunction. commit3b3d162575Author: Georgiy Guminov <gogagum@gmail.com> Date: Wed Jun 12 16:30:44 2024 +0300 Make macro more readable. commit4ab19e045fAuthor: Georgiy Guminov <gogagum@gmail.com> Date: Wed Jun 12 15:56:49 2024 +0300 Add static_assert messages. commit82b5c44cd3Author: Georgiy Guminov <gogagum@gmail.com> Date: Wed Jun 12 14:12:10 2024 +0300 Return is iterator CXX17 test. commit2d58d65462Author: Georgiy Guminov <gogagum@gmail.com> Date: Tue Jun 11 14:04:17 2024 +0300 Omitted. commita0d04d9491Author: Georgiy Guminov <gogagum@gmail.com> Date: Tue Jun 11 14:00:35 2024 +0300 Replace move with static_cast commit4a49b8a1a2Author: Georgiy Guminov <gogagum@gmail.com> Date: Mon Jun 10 21:38:53 2024 +0300 Return BOOST_NOEXCEPT commit054c013bbaAuthor: Georgiy Guminov <gogagum@gmail.com> Date: Sun Jun 9 15:20:41 2024 +0300 CXX11
292 lines
7.8 KiB
C++
292 lines
7.8 KiB
C++
// (C) Copyright Thomas Witt 2003.
|
|
// Distributed under the Boost Software License, Version 1.0. (See
|
|
// accompanying file LICENSE_1_0.txt or copy at
|
|
// http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
// See http://www.boost.org for most recent version including documentation.
|
|
|
|
#include <boost/config.hpp>
|
|
#include <iostream>
|
|
|
|
#include <algorithm>
|
|
#include <functional>
|
|
#include <numeric>
|
|
|
|
#include <boost/iterator/iterator_adaptor.hpp>
|
|
#include <boost/iterator/is_readable_iterator.hpp>
|
|
#include <boost/iterator/is_lvalue_iterator.hpp>
|
|
#include <boost/pending/iterator_tests.hpp>
|
|
|
|
# include <boost/core/lightweight_test.hpp>
|
|
|
|
#include <stdlib.h>
|
|
#include <vector>
|
|
#include <deque>
|
|
#include <set>
|
|
#include <list>
|
|
|
|
#include "static_assert_same.hpp"
|
|
|
|
using boost::dummyT;
|
|
|
|
typedef std::deque<int> storage;
|
|
typedef std::deque<int*> pointer_deque;
|
|
typedef std::set<storage::iterator> iterator_set;
|
|
|
|
template <class T> struct foo;
|
|
|
|
void blah(int) { }
|
|
|
|
struct my_gen
|
|
{
|
|
typedef int result_type;
|
|
my_gen() : n(0) { }
|
|
int operator()() { return ++n; }
|
|
int n;
|
|
};
|
|
|
|
template <class V>
|
|
struct ptr_iterator
|
|
: boost::iterator_adaptor<
|
|
ptr_iterator<V>
|
|
, V*
|
|
, V
|
|
, boost::random_access_traversal_tag
|
|
>
|
|
{
|
|
private:
|
|
typedef boost::iterator_adaptor<
|
|
ptr_iterator<V>
|
|
, V*
|
|
, V
|
|
, boost::random_access_traversal_tag
|
|
> super_t;
|
|
|
|
public:
|
|
ptr_iterator() { }
|
|
ptr_iterator(V* d) : super_t(d) { }
|
|
|
|
template <class V2>
|
|
ptr_iterator(
|
|
const ptr_iterator<V2>& x
|
|
, typename boost::enable_if_convertible<V2*, V*>::type* = 0
|
|
)
|
|
: super_t(x.base())
|
|
{}
|
|
};
|
|
|
|
// Non-functional iterator for category modification checking
|
|
template <class Iter, class Traversal>
|
|
struct modify_traversal
|
|
: boost::iterator_adaptor<
|
|
modify_traversal<Iter, Traversal>
|
|
, Iter
|
|
, boost::use_default
|
|
, Traversal
|
|
>
|
|
{};
|
|
|
|
template <class T>
|
|
struct fwd_iterator
|
|
: boost::iterator_adaptor<
|
|
fwd_iterator<T>
|
|
, boost::forward_iterator_archetype<T>
|
|
>
|
|
{
|
|
private:
|
|
typedef boost::iterator_adaptor<
|
|
fwd_iterator<T>
|
|
, boost::forward_iterator_archetype<T>
|
|
> super_t;
|
|
|
|
public:
|
|
fwd_iterator() { }
|
|
fwd_iterator(boost::forward_iterator_archetype<T> d) : super_t(d) { }
|
|
};
|
|
|
|
template <class T>
|
|
struct in_iterator
|
|
: boost::iterator_adaptor<
|
|
in_iterator<T>
|
|
, boost::input_iterator_archetype_no_proxy<T>
|
|
>
|
|
{
|
|
private:
|
|
typedef boost::iterator_adaptor<
|
|
in_iterator<T>
|
|
, boost::input_iterator_archetype_no_proxy<T>
|
|
> super_t;
|
|
|
|
public:
|
|
in_iterator() { }
|
|
in_iterator(boost::input_iterator_archetype_no_proxy<T> d) : super_t(d) { }
|
|
};
|
|
|
|
template <class Iter>
|
|
struct constant_iterator
|
|
: boost::iterator_adaptor<
|
|
constant_iterator<Iter>
|
|
, Iter
|
|
, typename std::iterator_traits<Iter>::value_type const
|
|
>
|
|
{
|
|
typedef boost::iterator_adaptor<
|
|
constant_iterator<Iter>
|
|
, Iter
|
|
, typename std::iterator_traits<Iter>::value_type const
|
|
> base_t;
|
|
|
|
constant_iterator() {}
|
|
constant_iterator(Iter it)
|
|
: base_t(it) {}
|
|
};
|
|
|
|
char (& traversal2(boost::incrementable_traversal_tag) )[1];
|
|
char (& traversal2(boost::single_pass_traversal_tag ) )[2];
|
|
char (& traversal2(boost::forward_traversal_tag ) )[3];
|
|
char (& traversal2(boost::bidirectional_traversal_tag) )[4];
|
|
char (& traversal2(boost::random_access_traversal_tag) )[5];
|
|
|
|
template <class Cat>
|
|
struct traversal3
|
|
{
|
|
static typename boost::iterator_category_to_traversal<Cat>::type x;
|
|
BOOST_STATIC_CONSTANT(std::size_t, value = sizeof(traversal2(x)));
|
|
typedef char (&type)[value];
|
|
};
|
|
|
|
template <class Cat>
|
|
typename traversal3<Cat>::type traversal(Cat);
|
|
|
|
template <class Iter, class Trav>
|
|
int static_assert_traversal(Iter* = 0, Trav* = 0)
|
|
{
|
|
typedef typename boost::iterator_category_to_traversal<
|
|
BOOST_DEDUCED_TYPENAME Iter::iterator_category
|
|
>::type t2;
|
|
|
|
return static_assert_same<Trav,t2>::value;
|
|
}
|
|
|
|
int
|
|
main()
|
|
{
|
|
dummyT array[] = { dummyT(0), dummyT(1), dummyT(2),
|
|
dummyT(3), dummyT(4), dummyT(5) };
|
|
const int N = sizeof(array)/sizeof(dummyT);
|
|
|
|
// sanity check, if this doesn't pass the test is buggy
|
|
boost::random_access_iterator_test(array, N, array);
|
|
|
|
// Test the iterator_adaptor
|
|
{
|
|
ptr_iterator<dummyT> i(array);
|
|
boost::random_access_iterator_test(i, N, array);
|
|
|
|
ptr_iterator<const dummyT> j(array);
|
|
boost::random_access_iterator_test(j, N, array);
|
|
boost::const_nonconst_iterator_test(i, ++j);
|
|
}
|
|
|
|
int test;
|
|
// Test the iterator_traits
|
|
{
|
|
// Test computation of defaults
|
|
typedef ptr_iterator<int> Iter1;
|
|
// don't use std::iterator_traits here to avoid VC++ problems
|
|
test = static_assert_same<Iter1::value_type, int>::value;
|
|
test = static_assert_same<Iter1::reference, int&>::value;
|
|
test = static_assert_same<Iter1::pointer, int*>::value;
|
|
test = static_assert_same<Iter1::difference_type, std::ptrdiff_t>::value;
|
|
static_assert(
|
|
std::is_convertible<Iter1::iterator_category, std::random_access_iterator_tag>::value,
|
|
"Iterator must have a random access category."
|
|
);
|
|
}
|
|
|
|
{
|
|
// Test computation of default when the Value is const
|
|
typedef ptr_iterator<int const> Iter1;
|
|
test = static_assert_same<Iter1::value_type, int>::value;
|
|
test = static_assert_same<Iter1::reference, const int&>::value;
|
|
|
|
static_assert(boost::is_readable_iterator<Iter1>::value, "Iter1 is expected to be readable.");
|
|
static_assert(boost::is_lvalue_iterator<Iter1>::value, "Iter1 is expected to be lvalue iterator.");
|
|
|
|
test = static_assert_same<Iter1::pointer, int const*>::value;
|
|
}
|
|
|
|
{
|
|
// Test constant iterator idiom
|
|
typedef ptr_iterator<int> BaseIter;
|
|
typedef constant_iterator<BaseIter> Iter;
|
|
|
|
test = static_assert_same<Iter::value_type, int>::value;
|
|
test = static_assert_same<Iter::reference, int const&>::value;
|
|
test = static_assert_same<Iter::pointer, int const*>::value;
|
|
|
|
static_assert(
|
|
boost::is_non_const_lvalue_iterator<BaseIter>::value,
|
|
"boost::is_non_const_lvalue_iterator<BaseIter>::value is expected to be true."
|
|
);
|
|
static_assert(
|
|
boost::is_lvalue_iterator<Iter>::value,
|
|
"boost::is_lvalue_iterator<Iter>::value is expected to be true."
|
|
);
|
|
|
|
typedef modify_traversal<BaseIter, boost::incrementable_traversal_tag> IncrementableIter;
|
|
|
|
static_assert_traversal<BaseIter,boost::random_access_traversal_tag>();
|
|
static_assert_traversal<IncrementableIter,boost::incrementable_traversal_tag>();
|
|
}
|
|
|
|
// Test the iterator_adaptor
|
|
{
|
|
ptr_iterator<dummyT> i(array);
|
|
boost::random_access_iterator_test(i, N, array);
|
|
|
|
ptr_iterator<const dummyT> j(array);
|
|
boost::random_access_iterator_test(j, N, array);
|
|
boost::const_nonconst_iterator_test(i, ++j);
|
|
}
|
|
|
|
// check operator-> with a forward iterator
|
|
{
|
|
boost::forward_iterator_archetype<dummyT> forward_iter;
|
|
|
|
typedef fwd_iterator<dummyT> adaptor_type;
|
|
|
|
adaptor_type i(forward_iter);
|
|
int zero = 0;
|
|
if (zero) // don't do this, just make sure it compiles
|
|
BOOST_TEST((*i).m_x == i->foo());
|
|
}
|
|
|
|
// check operator-> with an input iterator
|
|
{
|
|
boost::input_iterator_archetype_no_proxy<dummyT> input_iter;
|
|
typedef in_iterator<dummyT> adaptor_type;
|
|
adaptor_type i(input_iter);
|
|
int zero = 0;
|
|
if (zero) // don't do this, just make sure it compiles
|
|
BOOST_TEST((*i).m_x == i->foo());
|
|
}
|
|
|
|
// check that base_type is correct
|
|
{
|
|
// Test constant iterator idiom
|
|
typedef ptr_iterator<int> BaseIter;
|
|
|
|
test = static_assert_same<BaseIter::base_type,int*>::value;
|
|
test = static_assert_same<constant_iterator<BaseIter>::base_type,BaseIter>::value;
|
|
|
|
typedef modify_traversal<BaseIter, boost::incrementable_traversal_tag> IncrementableIter;
|
|
|
|
test = static_assert_same<IncrementableIter::base_type,BaseIter>::value;
|
|
}
|
|
|
|
std::cout << "test successful " << std::endl;
|
|
(void)test;
|
|
return boost::report_errors();
|
|
}
|