support for boost::tuples

[SVN r35350]
This commit is contained in:
Joel de Guzman
2006-09-27 00:42:32 +00:00
parent 798c527173
commit 3f27fbe969
24 changed files with 645 additions and 4 deletions

View File

@ -0,0 +1,113 @@
/*=============================================================================
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_BOOST_TUPLE_ITERATOR_09262006_1851)
#define FUSION_BOOST_TUPLE_ITERATOR_09262006_1851
#include <boost/fusion/iterator/iterator_facade.hpp>
#include <boost/type_traits/is_const.hpp>
#include <boost/type_traits/add_const.hpp>
#include <boost/mpl/identity.hpp>
#include <boost/mpl/if.hpp>
#include <boost/mpl/eval_if.hpp>
#include <boost/tuple/tuple.hpp>
namespace boost { namespace fusion
{
struct forward_traversal_tag;
template <typename Cons = tuples::null_type>
struct boost_tuple_iterator
: iterator_facade<boost_tuple_iterator<Cons>, forward_traversal_tag>
{
typedef Cons cons_type;
explicit boost_tuple_iterator(Cons& cons)
: cons(cons) {}
Cons& cons;
template <typename Iterator>
struct value_of : mpl::identity<typename Iterator::cons_type::head_type> {};
template <typename Iterator>
struct deref
{
typedef typename value_of<Iterator>::type element;
typedef typename
mpl::if_<
is_const<typename Iterator::cons_type>
, typename tuples::access_traits<element>::const_type
, typename tuples::access_traits<element>::non_const_type
>::type
type;
static type
call(Iterator const& iter)
{
return iter.cons.get_head();
}
};
template <typename Iterator>
struct next
{
typedef typename Iterator::cons_type cons_type;
typedef typename cons_type::tail_type tail_type;
typedef boost_tuple_iterator<
typename mpl::eval_if<
is_const<cons_type>
, add_const<tail_type>
, mpl::identity<tail_type>
>::type>
type;
static type
call(Iterator const& iter)
{
return type(iter.cons.get_tail());
}
};
};
template <>
struct boost_tuple_iterator<tuples::null_type>
: iterator_facade<boost_tuple_iterator<tuples::null_type>, forward_traversal_tag>
{
template <typename Cons>
explicit boost_tuple_iterator(Cons const&) {}
};
template <>
struct boost_tuple_iterator<tuples::null_type const>
: iterator_facade<boost_tuple_iterator<tuples::null_type const>, forward_traversal_tag>
{
template <typename Cons>
explicit boost_tuple_iterator(Cons const&) {}
};
template <>
struct boost_tuple_iterator<tuples::tuple<> >
: iterator_facade<boost_tuple_iterator<tuples::tuple<> >, forward_traversal_tag>
{
template <typename Cons>
explicit boost_tuple_iterator(Cons const&) {}
};
template <>
struct boost_tuple_iterator<tuples::tuple<> const>
: iterator_facade<boost_tuple_iterator<tuples::tuple<> const>, forward_traversal_tag>
{
template <typename Cons>
explicit boost_tuple_iterator(Cons const&) {}
};
}}
#endif

View File

@ -0,0 +1,51 @@
/*=============================================================================
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(BOOST_FUSION_AT_IMPL_09262006_1920)
#define BOOST_FUSION_AT_IMPL_09262006_1920
#include <boost/tuple/tuple.hpp>
#include <boost/mpl/if.hpp>
namespace boost { namespace fusion
{
struct boost_tuple_tag;
namespace extension
{
template<typename T>
struct at_impl;
template <>
struct at_impl<boost_tuple_tag>
{
template <typename Sequence, typename N>
struct apply
{
typedef typename
tuples::element<N::value, Sequence>::type
element;
typedef typename
mpl::if_<
is_const<Sequence>
, typename tuples::access_traits<element>::const_type
, typename tuples::access_traits<element>::non_const_type
>::type
type;
static type
call(Sequence& seq)
{
return tuples::get<N::value>(seq);
}
};
};
}
}}
#endif

View File

@ -0,0 +1,40 @@
/*=============================================================================
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(BOOST_FUSION_BEGIN_IMPL_09272006_0719)
#define BOOST_FUSION_BEGIN_IMPL_09272006_0719
#include <boost/fusion/sequence/adapted/boost_tuple/boost_tuple_iterator.hpp>
namespace boost { namespace fusion
{
struct boost_tuple_tag;
namespace extension
{
template<typename T>
struct begin_impl;
template <>
struct begin_impl<boost_tuple_tag>
{
template <typename Sequence>
struct apply
{
typedef boost_tuple_iterator<Sequence> type;
static type
call(Sequence& v)
{
return type(v);
}
};
};
}
}}
#endif

View File

@ -0,0 +1,33 @@
/*=============================================================================
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(BOOST_FUSION_CATEGORY_OF_IMPL_09272006_0726)
#define BOOST_FUSION_CATEGORY_OF_IMPL_09272006_0726
namespace boost { namespace fusion
{
struct boost_tuple_tag;
struct forward_traversal_tag;
namespace extension
{
template<typename T>
struct category_of_impl;
template<>
struct category_of_impl<boost_tuple_tag>
{
template<typename T>
struct apply
{
typedef forward_traversal_tag type;
};
};
}
}}
#endif

View File

@ -0,0 +1,55 @@
/*=============================================================================
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(BOOST_FUSION_END_IMPL_09272006_0721)
#define BOOST_FUSION_END_IMPL_09272006_0721
#include <boost/fusion/sequence/adapted/boost_tuple/boost_tuple_iterator.hpp>
#include <boost/mpl/if.hpp>
#include <boost/type_traits/is_const.hpp>
namespace boost { namespace tuples
{
struct null_type;
}}
namespace boost { namespace fusion
{
struct boost_tuple_tag;
namespace extension
{
template <typename Tag>
struct end_impl;
template <>
struct end_impl<boost_tuple_tag>
{
template <typename Sequence>
struct apply
{
typedef
boost_tuple_iterator<
typename mpl::if_<
is_const<Sequence>
, tuples::null_type const
, tuples::null_type
>::type
>
type;
static type
call(Sequence& seq)
{
return type(seq);
}
};
};
}
}}
#endif

View File

@ -0,0 +1,31 @@
/*=============================================================================
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(BOOST_FUSION_IS_SEQUENCE_IMPL_09272006_0726)
#define BOOST_FUSION_IS_SEQUENCE_IMPL_09272006_0726
#include <boost/mpl/bool.hpp>
namespace boost { namespace fusion
{
struct boost_tuple_tag;
namespace extension
{
template<typename Tag>
struct is_sequence_impl;
template<>
struct is_sequence_impl<boost_tuple_tag>
{
template<typename Sequence>
struct apply : mpl::true_ {};
};
}
}}
#endif

View File

@ -0,0 +1,31 @@
/*=============================================================================
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(BOOST_FUSION_IS_VIEW_IMPL_09272006_0725)
#define BOOST_FUSION_IS_VIEW_IMPL_09272006_0725
#include <boost/mpl/bool.hpp>
namespace boost { namespace fusion
{
struct boost_tuple_tag;
namespace extension
{
template<typename Tag>
struct is_view_impl;
template<>
struct is_view_impl<boost_tuple_tag>
{
template<typename T>
struct apply : mpl::false_ {};
};
}
}}
#endif

View File

@ -0,0 +1,32 @@
/*=============================================================================
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(BOOST_FUSION_SIZE_IMPL_09272006_0724)
#define BOOST_FUSION_SIZE_IMPL_09272006_0724
#include <boost/tuple/tuple.hpp>
#include <boost/mpl/int.hpp>
namespace boost { namespace fusion
{
struct boost_tuple_tag;
namespace extension
{
template<typename T>
struct size_impl;
template <>
struct size_impl<boost_tuple_tag>
{
template <typename Sequence>
struct apply : mpl::int_<tuples::length<Sequence>::value> {};
};
}
}}
#endif

View File

@ -0,0 +1,31 @@
/*=============================================================================
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(BOOST_FUSION_VALUE_AT_IMPL_09262006_1926)
#define BOOST_FUSION_VALUE_AT_IMPL_09262006_1926
#include <boost/tuple/tuple.hpp>
namespace boost { namespace fusion
{
struct boost_tuple_tag;
namespace extension
{
template<typename T>
struct value_at_impl;
template <>
struct value_at_impl<boost_tuple_tag>
{
template <typename Sequence, typename N>
struct apply : tuples::element<N::value, Sequence> {};
};
}
}}
#endif

View File

@ -0,0 +1,56 @@
/*=============================================================================
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(BOOST_FUSION_TAG_OF_09262006_1900)
#define BOOST_FUSION_TAG_OF_09262006_1900
#include <boost/fusion/support/tag_of_fwd.hpp>
namespace boost { namespace tuples
{
struct null_type;
template <
class T0, class T1, class T2, class T3, class T4,
class T5, class T6, class T7, class T8, class T9
>
class tuple;
template <class Head, class Tail>
struct cons;
}}
namespace boost { namespace fusion
{
struct boost_tuple_tag;
namespace traits
{
template <
class T0, class T1, class T2, class T3, class T4,
class T5, class T6, class T7, class T8, class T9
>
struct tag_of<tuples::tuple<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> >
{
typedef boost_tuple_tag type;
};
template <class Head, class Tail>
struct tag_of<tuples::cons<Head, Tail> >
{
typedef boost_tuple_tag type;
};
template <>
struct tag_of<tuples::null_type>
{
typedef boost_tuple_tag type;
};
}
}}
#endif