migrated std_pair_iterator and mpl_iterator to iterator_facade

[SVN r35321]
This commit is contained in:
Joel de Guzman
2006-09-25 13:56:22 +00:00
parent f017aa86ce
commit ac31f6d1cb
20 changed files with 328 additions and 743 deletions

View File

@ -8,39 +8,130 @@
#if !defined(FUSION_STD_PAIR_ITERATOR_09262005_0934)
#define FUSION_STD_PAIR_ITERATOR_09262005_0934
#include <boost/fusion/support/iterator_base.hpp>
#include <boost/fusion/sequence/adapted/std_pair/detail/advance_impl.hpp>
#include <boost/fusion/sequence/adapted/std_pair/detail/deref_impl.hpp>
#include <boost/fusion/sequence/adapted/std_pair/detail/distance_impl.hpp>
#include <boost/fusion/sequence/adapted/std_pair/detail/equal_to_impl.hpp>
#include <boost/fusion/sequence/adapted/std_pair/detail/next_impl.hpp>
#include <boost/fusion/sequence/adapted/std_pair/detail/prior_impl.hpp>
#include <boost/fusion/sequence/adapted/std_pair/detail/value_of_impl.hpp>
#include <boost/type_traits/add_const.hpp>
//~ #include <boost/fusion/support/iterator_base.hpp>
//~ #include <boost/fusion/sequence/adapted/std_pair/detail/advance_impl.hpp>
//~ #include <boost/fusion/sequence/adapted/std_pair/detail/deref_impl.hpp>
//~ #include <boost/fusion/sequence/adapted/std_pair/detail/distance_impl.hpp>
//~ #include <boost/fusion/sequence/adapted/std_pair/detail/equal_to_impl.hpp>
//~ #include <boost/fusion/sequence/adapted/std_pair/detail/next_impl.hpp>
//~ #include <boost/fusion/sequence/adapted/std_pair/detail/prior_impl.hpp>
//~ #include <boost/fusion/sequence/adapted/std_pair/detail/value_of_impl.hpp>
//~ #include <boost/type_traits/add_const.hpp>
#include <boost/fusion/iterator/iterator_facade.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/minus.hpp>
#include <utility>
namespace boost { namespace fusion
{
struct std_pair_iterator_tag;
struct random_access_traversal_tag;
template <typename Pair, int N>
struct std_pair_iterator_identity;
template <typename Pair, int N>
struct std_pair_iterator
: iterator_base<std_pair_iterator<Pair, N> >
: iterator_facade<std_pair_iterator<Pair, N>, random_access_traversal_tag>
{
BOOST_MPL_ASSERT_RELATION(N, >=, 0);
BOOST_MPL_ASSERT_RELATION(N, <=, 2);
typedef mpl::int_<N> index;
typedef std_pair_iterator_tag fusion_tag;
typedef random_access_traversal_tag category;
typedef std_pair_iterator_identity<
typename add_const<Pair>::type, N> identity;
typedef Pair pair_type;
std_pair_iterator(Pair& pair)
: pair(pair) {}
Pair& pair;
template <typename Iterator>
struct value_of;
template <typename Pair_>
struct value_of<std_pair_iterator<Pair_, 0> >
: mpl::identity<typename Pair_::first_type> {};
template <typename Pair_>
struct value_of<std_pair_iterator<Pair_, 1> >
: mpl::identity<typename Pair_::second_type> {};
template <typename Iterator>
struct deref;
template <typename Pair_>
struct deref<std_pair_iterator<Pair_, 0> >
{
typedef typename
mpl::if_<
is_const<Pair_>
, typename Pair_::first_type const&
, typename Pair_::first_type&
>::type
type;
static type
call(std_pair_iterator<Pair_, 0> const& iter)
{
return iter.pair.first;
}
};
template <typename Pair_>
struct deref<std_pair_iterator<Pair_, 1> >
{
typedef typename
mpl::if_<
is_const<Pair_>
, typename Pair_::second_type const&
, typename Pair_::second_type&
>::type
type;
static type
call(std_pair_iterator<Pair_, 1> const& iter)
{
return iter.pair.second;
}
};
template <typename Iterator, typename N>
struct advance
{
typedef typename Iterator::index index;
typedef typename Iterator::pair_type pair_type;
typedef std_pair_iterator<pair_type, index::value + N::value> type;
static type
call(Iterator const& iter)
{
return type(iter.pair);
}
};
template <typename Iterator>
struct next : advance<Iterator, mpl::int_<1> > {};
template <typename Iterator>
struct prior : advance<Iterator, mpl::int_<-1> > {};
template <typename I1, typename I2>
struct distance : mpl::minus<typename I2::index, typename I1::index>
{
typedef typename
mpl::minus<
typename I2::index, typename I1::index
>::type
type;
static type
call(I1 const&, I2 const&)
{
return type();
}
};
};
}}

View File

@ -12,6 +12,7 @@
#include <boost/mpl/if.hpp>
#include <boost/mpl/int.hpp>
#include <boost/static_assert.hpp>
#include <boost/fusion/support/detail/access.hpp>
namespace boost { namespace fusion {

View File

@ -1,47 +0,0 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
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_ADVANCE_IMPL_09302005_1847)
#define FUSION_ADVANCE_IMPL_09302005_1847
#include <boost/static_assert.hpp>
namespace boost { namespace fusion
{
struct std_pair_iterator_tag;
template <typename Vector, int N>
struct std_pair_iterator;
namespace extension
{
template <typename Tag>
struct advance_impl;
template <>
struct advance_impl<std_pair_iterator_tag>
{
template <typename Iterator, typename N>
struct apply
{
typedef typename Iterator::index index;
typedef typename Iterator::pair_type pair_type;
typedef std_pair_iterator<pair_type, index::value+N::value> type;
BOOST_STATIC_ASSERT(
(index::value+N::value) >= 0 &&(index::value+N::value) < 2);
static type
call(Iterator const& i)
{
return type(i.vec);
}
};
};
}
}}
#endif

View File

@ -12,6 +12,7 @@
#include <boost/mpl/if.hpp>
#include <boost/mpl/int.hpp>
#include <boost/static_assert.hpp>
#include <boost/fusion/support/detail/access.hpp>
namespace boost { namespace fusion {

View File

@ -1,74 +0,0 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
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_DEREF_IMPL_09302005_1846)
#define FUSION_DEREF_IMPL_09302005_1846
#include <boost/fusion/support/detail/access.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/static_assert.hpp>
#include <boost/mpl/if.hpp>
namespace boost { namespace fusion
{
struct std_pair_iterator_tag;
namespace extension
{
template <typename Tag>
struct deref_impl;
template <>
struct deref_impl<std_pair_iterator_tag>
{
template <typename Iterator>
struct apply
{
typedef typename Iterator::pair_type pair_type;
typedef typename Iterator::index index;
static int const index_val = index::value;
BOOST_STATIC_ASSERT(index_val >= 0 && index_val <= 2);
typedef typename
mpl::if_c<
(index::value == 0)
, typename pair_type::first_type
, typename pair_type::second_type
>
element;
typedef typename
mpl::eval_if<
is_const<pair_type>
, fusion::detail::cref_result<element>
, fusion::detail::ref_result<element>
>::type
type;
template <typename RT>
static RT get(pair_type& p, mpl::int_<0>)
{
return p.first;
}
template <typename RT>
static RT get(pair_type& p, mpl::int_<1>)
{
return p.second;
}
static type
call(Iterator const& iter)
{
return get<type>(iter.pair, index());
}
};
};
}
}}
#endif

View File

@ -1,42 +0,0 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
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_DISTANCE_IMPL_09302005_1846)
#define FUSION_DISTANCE_IMPL_09302005_1846
#include <boost/mpl/minus.hpp>
namespace boost { namespace fusion
{
struct std_pair_iterator_tag;
namespace extension
{
template <typename Tag>
struct distance_impl;
template <>
struct distance_impl<std_pair_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
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_EQUAL_TO_IMPL_09302005_1847)
#define FUSION_EQUAL_TO_IMPL_09302005_1847
#include <boost/type_traits/is_same.hpp>
#include <boost/mpl/equal_to.hpp>
#include <boost/mpl/and.hpp>
namespace boost { namespace fusion
{
struct std_pair_iterator_tag;
namespace extension
{
template <typename Tag>
struct equal_to_impl;
template <>
struct equal_to_impl<std_pair_iterator_tag>
{
template <typename I1, typename I2>
struct apply
: is_same<
typename I1::identity
, typename I2::identity
>
{
};
};
}
}}
#endif

View File

@ -1,46 +0,0 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
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_09302005_1847)
#define FUSION_NEXT_IMPL_09302005_1847
#include <boost/static_assert.hpp>
namespace boost { namespace fusion
{
struct std_pair_iterator_tag;
template <typename Vector, int N>
struct std_pair_iterator;
namespace extension
{
template <typename Tag>
struct next_impl;
template <>
struct next_impl<std_pair_iterator_tag>
{
template <typename Iterator>
struct apply
{
typedef typename Iterator::pair_type pair_type;
typedef typename Iterator::index index;
static int const index_val = index::value;
typedef std_pair_iterator<pair_type, index_val+1> type;
BOOST_STATIC_ASSERT((index_val+1) >= 0 &&(index_val+1) <= 2);
static type
call(Iterator const& i)
{
return type(i.pair);
}
};
};
}
}}
#endif

View File

@ -1,46 +0,0 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
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_09302005_1847)
#define FUSION_PRIOR_IMPL_09302005_1847
#include <boost/static_assert.hpp>
namespace boost { namespace fusion
{
struct std_pair_iterator_tag;
template <typename Vector, int N>
struct std_pair_iterator;
namespace extension
{
template <typename Tag>
struct prior_impl;
template <>
struct prior_impl<std_pair_iterator_tag>
{
template <typename Iterator>
struct apply
{
typedef typename Iterator::pair_type pair_type;
typedef typename Iterator::index index;
static int const index_val = index::value;
typedef std_pair_iterator<pair_type, index_val-1> type;
BOOST_STATIC_ASSERT((index_val-1) >= 0 &&(index_val-1) <= 2);
static type
call(Iterator const& i)
{
return type(i.pair);
}
};
};
}
}}
#endif

View File

@ -1,46 +0,0 @@
/*=============================================================================
Copyright (c) 2001-2006 Joel de Guzman
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_VALUE_OF_IMPL_09302005_1847)
#define FUSION_VALUE_OF_IMPL_09302005_1847
#include <boost/static_assert.hpp>
#include <boost/mpl/if.hpp>
namespace boost { namespace fusion
{
struct std_pair_iterator_tag;
namespace extension
{
template <typename Tag>
struct value_of_impl;
template <>
struct value_of_impl<std_pair_iterator_tag>
{
template <typename Iterator>
struct apply
{
typedef typename Iterator::pair_type pair_type;
typedef typename Iterator::index index;
static int const index_value = index::value;
BOOST_STATIC_ASSERT(index_value >= 0 && index_value <= 2);
typedef typename
mpl::if_c<
(index_value == 0)
, typename pair_type::first_type
, typename pair_type::second_type
>::type
type;
};
};
}
}}
#endif

View File

@ -8,39 +8,130 @@
#if !defined(FUSION_STD_PAIR_ITERATOR_09262005_0934)
#define FUSION_STD_PAIR_ITERATOR_09262005_0934
#include <boost/fusion/support/iterator_base.hpp>
#include <boost/fusion/sequence/adapted/std_pair/detail/advance_impl.hpp>
#include <boost/fusion/sequence/adapted/std_pair/detail/deref_impl.hpp>
#include <boost/fusion/sequence/adapted/std_pair/detail/distance_impl.hpp>
#include <boost/fusion/sequence/adapted/std_pair/detail/equal_to_impl.hpp>
#include <boost/fusion/sequence/adapted/std_pair/detail/next_impl.hpp>
#include <boost/fusion/sequence/adapted/std_pair/detail/prior_impl.hpp>
#include <boost/fusion/sequence/adapted/std_pair/detail/value_of_impl.hpp>
#include <boost/type_traits/add_const.hpp>
//~ #include <boost/fusion/support/iterator_base.hpp>
//~ #include <boost/fusion/sequence/adapted/std_pair/detail/advance_impl.hpp>
//~ #include <boost/fusion/sequence/adapted/std_pair/detail/deref_impl.hpp>
//~ #include <boost/fusion/sequence/adapted/std_pair/detail/distance_impl.hpp>
//~ #include <boost/fusion/sequence/adapted/std_pair/detail/equal_to_impl.hpp>
//~ #include <boost/fusion/sequence/adapted/std_pair/detail/next_impl.hpp>
//~ #include <boost/fusion/sequence/adapted/std_pair/detail/prior_impl.hpp>
//~ #include <boost/fusion/sequence/adapted/std_pair/detail/value_of_impl.hpp>
//~ #include <boost/type_traits/add_const.hpp>
#include <boost/fusion/iterator/iterator_facade.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/int.hpp>
#include <boost/mpl/minus.hpp>
#include <utility>
namespace boost { namespace fusion
{
struct std_pair_iterator_tag;
struct random_access_traversal_tag;
template <typename Pair, int N>
struct std_pair_iterator_identity;
template <typename Pair, int N>
struct std_pair_iterator
: iterator_base<std_pair_iterator<Pair, N> >
: iterator_facade<std_pair_iterator<Pair, N>, random_access_traversal_tag>
{
BOOST_MPL_ASSERT_RELATION(N, >=, 0);
BOOST_MPL_ASSERT_RELATION(N, <=, 2);
typedef mpl::int_<N> index;
typedef std_pair_iterator_tag fusion_tag;
typedef random_access_traversal_tag category;
typedef std_pair_iterator_identity<
typename add_const<Pair>::type, N> identity;
typedef Pair pair_type;
std_pair_iterator(Pair& pair)
: pair(pair) {}
Pair& pair;
template <typename Iterator>
struct value_of;
template <typename Pair_>
struct value_of<std_pair_iterator<Pair_, 0> >
: mpl::identity<typename Pair_::first_type> {};
template <typename Pair_>
struct value_of<std_pair_iterator<Pair_, 1> >
: mpl::identity<typename Pair_::second_type> {};
template <typename Iterator>
struct deref;
template <typename Pair_>
struct deref<std_pair_iterator<Pair_, 0> >
{
typedef typename
mpl::if_<
is_const<Pair_>
, typename Pair_::first_type const&
, typename Pair_::first_type&
>::type
type;
static type
call(std_pair_iterator<Pair_, 0> const& iter)
{
return iter.pair.first;
}
};
template <typename Pair_>
struct deref<std_pair_iterator<Pair_, 1> >
{
typedef typename
mpl::if_<
is_const<Pair_>
, typename Pair_::second_type const&
, typename Pair_::second_type&
>::type
type;
static type
call(std_pair_iterator<Pair_, 1> const& iter)
{
return iter.pair.second;
}
};
template <typename Iterator, typename N>
struct advance
{
typedef typename Iterator::index index;
typedef typename Iterator::pair_type pair_type;
typedef std_pair_iterator<pair_type, index::value + N::value> type;
static type
call(Iterator const& iter)
{
return type(iter.pair);
}
};
template <typename Iterator>
struct next : advance<Iterator, mpl::int_<1> > {};
template <typename Iterator>
struct prior : advance<Iterator, mpl::int_<-1> > {};
template <typename I1, typename I2>
struct distance : mpl::minus<typename I2::index, typename I1::index>
{
typedef typename
mpl::minus<
typename I2::index, typename I1::index
>::type
type;
static type
call(I1 const&, I2 const&)
{
return type();
}
};
};
}}