adapted/array is now using iterator_facade

[SVN r35317]
This commit is contained in:
Joel de Guzman
2006-09-25 09:06:15 +00:00
parent 654fd0918e
commit f017aa86ce
28 changed files with 281 additions and 491 deletions

View File

@ -10,45 +10,119 @@
#define BOOST_FUSION_ARRAY_ITERATOR_26122005_2250
#include <cstddef>
#include <boost/config.hpp>
#include <boost/mpl/size_t.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/type_traits/add_const.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/minus.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/fusion/iterator/iterator_facade.hpp>
#include <boost/fusion/support/iterator_base.hpp>
#include <boost/fusion/sequence/adapted/array/detail/next_impl.hpp>
#include <boost/fusion/sequence/adapted/array/detail/prior_impl.hpp>
#include <boost/fusion/sequence/adapted/array/detail/advance_impl.hpp>
#include <boost/fusion/sequence/adapted/array/detail/deref_impl.hpp>
#include <boost/fusion/sequence/adapted/array/detail/value_of_impl.hpp>
#include <boost/fusion/sequence/adapted/array/detail/distance_impl.hpp>
#include <boost/fusion/sequence/adapted/array/detail/equal_to_impl.hpp>
namespace boost { namespace fusion {
struct array_iterator_tag;
namespace boost { namespace fusion
{
struct random_access_traversal_tag;
template<typename Array, std::size_t Pos>
struct array_iterator
: iterator_base<array_iterator<Array, Pos> >
: iterator_facade<array_iterator<Array, Pos>, random_access_traversal_tag>
{
BOOST_MPL_ASSERT_RELATION(Pos,>=,0);
BOOST_MPL_ASSERT_RELATION(Pos,<=,std::size_t(Array::static_size));
typedef mpl::size_t<Pos> index;
typedef array_iterator_tag fusion_tag;
typedef random_access_traversal_tag category;
typedef Array array_type;
typedef array_iterator<
typename add_const<Array>::type, Pos> identity;
array_iterator(Array& a)
: array(a) {}
Array& array;
template <typename Iterator>
struct value_of
{
typedef typename Iterator::array_type array_type;
typedef typename array_type::value_type type;
};
template <typename Iterator>
struct deref
{
typedef typename Iterator::array_type array_type;
typedef typename
mpl::if_<
is_const<array_type>
, typename array_type::const_reference
, typename array_type::reference
>::type
type;
static type
call(Iterator const & it)
{
return it.array[Iterator::index::value];
}
};
template <typename Iterator>
struct next
{
typedef typename Iterator::array_type array_type;
typedef typename Iterator::index index;
static int const index_val = index::value;
typedef array_iterator<array_type, index_val + 1> type;
static type
call(Iterator const& i)
{
return type(i.array);
}
};
template <typename Iterator>
struct prior
{
typedef typename Iterator::array_type array_type;
typedef typename Iterator::index index;
static int const index_val = index::value;
typedef array_iterator<array_type, index_val - 1> type;
static type
call(Iterator const& i)
{
return type(i.array);
}
};
template <typename Iterator, typename N>
struct advance
{
typedef typename Iterator::index index;
typedef typename Iterator::array_type array_type;
typedef array_iterator<array_type, index::value + N::value> type;
static type
call(Iterator const& i)
{
return type(i.array);
}
};
template <typename First, typename Last>
struct distance : mpl::minus<typename Last::index, typename First::index>
{
typedef typename mpl::minus<
typename Last::index, typename First::index>::type
type;
static type
call(First const&, Last const&)
{
return type();
}
};
private:
array_iterator<Array, Pos> operator=(const array_iterator<Array, Pos>&);
};
}}

View File

@ -1,44 +0,0 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2005-2006 Dan Marsden
Use, modification and distribution is subject to 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)
==============================================================================*/
#if !defined(BOOST_FUSION_ADVANCE_IMPL_27122005_0938)
#define BOOST_FUSION_ADVANCE_IMPL_27122005_0938
namespace boost { namespace fusion {
struct array_iterator_tag;
template<typename Array, std::size_t Pos>
struct array_iterator;
namespace extension
{
template<typename Tag>
struct advance_impl;
template<>
struct advance_impl<array_iterator_tag>
{
template<typename Iterator, typename N>
struct apply
{
typedef typename Iterator::index index;
typedef typename Iterator::array_type array_type;
typedef array_iterator<array_type, index::value + N::value> type;
static type
call(Iterator const& i)
{
return type(i.array);
}
};
};
}
}}
#endif

View File

@ -1,49 +0,0 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2005-2006 Dan Marsden
Use, modification and distribution is subject to 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)
==============================================================================*/
#if !defined(BOOST_FUSION_DEREF_IMPL_27122005_0951)
#define BOOST_FUSION_DEREF_IMPL_27122005_0951
#include <boost/mpl/if.hpp>
#include <boost/type_traits/is_const.hpp>
namespace boost { namespace fusion {
struct array_iterator_tag;
template<typename Array, std::size_t Pos>
struct array_iterator;
namespace extension
{
template<typename Tag>
struct deref_impl;
template<>
struct deref_impl<array_iterator_tag>
{
template<typename Iterator>
struct apply
{
typedef typename Iterator::array_type array_type;
typedef typename mpl::if_<
is_const<array_type>,
typename array_type::const_reference,
typename array_type::reference>::type type;
static type
call(Iterator const & it)
{
return it.array[Iterator::index::value];
}
};
};
}
}}
#endif

View File

@ -1,43 +0,0 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2005-2006 Dan Marsden
Use, modification and distribution is subject to 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)
==============================================================================*/
#if !defined(BOOST_FUSION_DISTANCE_IMPL_27122005_1016)
#define BOOST_FUSION_DISTANCE_IMPL_27122005_1016
#include <boost/mpl/minus.hpp>
namespace boost { namespace fusion
{
struct array_iterator_tag;
namespace extension
{
template <typename Tag>
struct distance_impl;
template <>
struct distance_impl<array_iterator_tag>
{
template <typename First, typename Last>
struct apply : mpl::minus<typename Last::index, typename First::index>
{
static typename mpl::minus<
typename Last::index, typename First::index>::type
call(First const&, Last const&)
{
typedef typename mpl::minus<
typename Last::index, typename First::index>::type
result;
return result();
}
};
};
}
}}
#endif

View File

@ -1,40 +0,0 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2005-2006 Dan Marsden
Use, modification and distribution is subject to 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)
==============================================================================*/
#if !defined(BOOST_FUSION_EQUAL_TO_IMPL_27122005_1020)
#define BOOST_FUSION_EQUAL_TO_IMPL_27122005_1020
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/and.hpp>
namespace boost { namespace fusion
{
struct array_iterator_tag;
namespace extension
{
template <typename Tag>
struct equal_to_impl;
template <>
struct equal_to_impl<array_iterator_tag>
{
template <typename I1, typename I2>
struct apply
: is_same<
typename I1::identity
, typename I2::identity
>
{};
};
}
}}
#endif

View File

@ -1,47 +0,0 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2005-2006 Dan Marsden
Use, modification and distribution is subject to 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)
==============================================================================*/
#if !defined(FUSION_NEXT_IMPL_27122005_0927)
#define FUSION_NEXT_IMPL_27122005_0927
#include <cstddef>
namespace boost { namespace fusion {
struct array_iterator_tag;
template<typename Array, std::size_t Pos>
struct array_iterator;
namespace extension
{
template<typename Tag>
struct next_impl;
template<>
struct next_impl<array_iterator_tag>
{
template<typename Iterator>
struct apply
{
typedef typename Iterator::array_type array_type;
typedef typename Iterator::index index;
static int const index_val = index::value;
typedef array_iterator<array_type, index_val + 1> type;
static type
call(Iterator const& i)
{
return type(i.array);
}
};
};
}
}}
#endif

View File

@ -1,45 +0,0 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2005-2006 Dan Marsden
Use, modification and distribution is subject to 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)
==============================================================================*/
#if !defined(FUSION_PRIOR_IMPL_27122005_0935)
#define FUSION_PRIOR_IMPL_27122005_0935
namespace boost { namespace fusion {
struct array_iterator_tag;
template<typename Array, std::size_t Pos>
struct array_iterator;
namespace extension
{
template<typename Tag>
struct prior_impl;
template<>
struct prior_impl<array_iterator_tag>
{
template<typename Iterator>
struct apply
{
typedef typename Iterator::array_type array_type;
typedef typename Iterator::index index;
static int const index_val = index::value;
typedef array_iterator<array_type, index_val - 1> type;
static type
call(Iterator const& i)
{
return type(i.array);
}
};
};
}
}}
#endif

View File

@ -1,34 +0,0 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
Copyright (c) 2005-2006 Dan Marsden
Use, modification and distribution is subject to 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)
==============================================================================*/
#if !defined(BOOST_FUSION_VALUE_OF_IMPL_27122005_1011)
#define BOOST_FUSION_VALUE_OF_IMPL_27122005_1011
namespace boost { namespace fusion
{
struct array_iterator_tag;
namespace extension
{
template <typename Tag>
struct value_of_impl;
template <>
struct value_of_impl<array_iterator_tag>
{
template <typename Iterator>
struct apply
{
typedef typename Iterator::array_type array_type;
typedef typename array_type::value_type type;
};
};
}
}}
#endif