mirror of
https://github.com/boostorg/fusion.git
synced 2025-07-23 00:57:20 +02:00
fusion: merge of associative iterators/views and the new fold interface
[SVN r58618]
This commit is contained in:
@ -25,7 +25,7 @@ namespace boost { namespace fusion {
|
||||
template<typename Sequence>
|
||||
struct apply
|
||||
{
|
||||
struct type : random_access_traversal_tag, associative_sequence_tag {};
|
||||
struct type : random_access_traversal_tag, associative_tag {};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
30
example/extension/detail/deref_data_impl.hpp
Normal file
30
example/extension/detail/deref_data_impl.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2009 Christopher Schmidt
|
||||
|
||||
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)
|
||||
==============================================================================*/
|
||||
|
||||
#ifndef BOOST_FUSION_EXAMPLE_EXTENSION_DETAIL_DEREF_DATA_IMPL_HPP
|
||||
#define BOOST_FUSION_EXAMPLE_EXTENSION_DETAIL_DEREF_DATA_IMPL_HPP
|
||||
|
||||
namespace example
|
||||
{
|
||||
struct example_struct_iterator_tag;
|
||||
}
|
||||
|
||||
namespace boost { namespace fusion {
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename Tag>
|
||||
struct deref_data_impl;
|
||||
|
||||
template<>
|
||||
struct deref_data_impl<example::example_struct_iterator_tag>
|
||||
: deref_impl<example::example_struct_iterator_tag>
|
||||
{};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
42
example/extension/detail/key_of_impl.hpp
Normal file
42
example/extension/detail/key_of_impl.hpp
Normal file
@ -0,0 +1,42 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2009 Christopher Schmidt
|
||||
|
||||
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)
|
||||
==============================================================================*/
|
||||
|
||||
#ifndef BOOST_FUSION_EXAMPLE_EXTENSION_DETAIL_KEY_OF_IMPL_HPP
|
||||
#define BOOST_FUSION_EXAMPLE_EXTENSION_DETAIL_KEY_OF_IMPL_HPP
|
||||
|
||||
#include <boost/mpl/if.hpp>
|
||||
|
||||
namespace fields
|
||||
{
|
||||
struct name;
|
||||
struct age;
|
||||
}
|
||||
|
||||
namespace example
|
||||
{
|
||||
struct example_struct_iterator_tag;
|
||||
}
|
||||
|
||||
namespace boost { namespace fusion {
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename Tag>
|
||||
struct key_of_impl;
|
||||
|
||||
template<>
|
||||
struct key_of_impl<example::example_struct_iterator_tag>
|
||||
{
|
||||
template<typename It>
|
||||
struct apply
|
||||
: mpl::if_c<!It::index::value, fields::name, fields::age>
|
||||
{};
|
||||
};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
30
example/extension/detail/value_of_data_impl.hpp
Normal file
30
example/extension/detail/value_of_data_impl.hpp
Normal file
@ -0,0 +1,30 @@
|
||||
/*=============================================================================
|
||||
Copyright (c) 2009 Christopher Schmidt
|
||||
|
||||
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)
|
||||
==============================================================================*/
|
||||
|
||||
#ifndef BOOST_FUSION_EXAMPLE_EXTENSION_DETAIL_VALUE_OF_DATA_IMPL_HPP
|
||||
#define BOOST_FUSION_EXAMPLE_EXTENSION_DETAIL_VALUE_OF_DATA_IMPL_HPP
|
||||
|
||||
namespace example
|
||||
{
|
||||
struct example_struct_iterator_tag;
|
||||
}
|
||||
|
||||
namespace boost { namespace fusion {
|
||||
|
||||
namespace extension
|
||||
{
|
||||
template<typename Tag>
|
||||
struct value_of_data_impl;
|
||||
|
||||
template<>
|
||||
struct value_of_data_impl<example::example_struct_iterator_tag>
|
||||
: value_of_impl<example::example_struct_iterator_tag>
|
||||
{};
|
||||
}
|
||||
}}
|
||||
|
||||
#endif
|
@ -9,6 +9,7 @@
|
||||
#define BOOST_FUSION_EXAMPLE_STRUCT_ITERATOR
|
||||
|
||||
#include <boost/fusion/support/iterator_base.hpp>
|
||||
#include <boost/fusion/support/category_of.hpp>
|
||||
#include <boost/fusion/support/tag_of_fwd.hpp>
|
||||
#include <boost/mpl/int.hpp>
|
||||
#include <boost/type_traits/add_const.hpp>
|
||||
@ -21,6 +22,9 @@
|
||||
#include "./detail/distance_impl.hpp"
|
||||
#include "./detail/value_of_impl.hpp"
|
||||
#include "./detail/equal_to_impl.hpp"
|
||||
#include "./detail/key_of_impl.hpp"
|
||||
#include "./detail/value_of_data_impl.hpp"
|
||||
#include "./detail/deref_data_impl.hpp"
|
||||
|
||||
namespace example
|
||||
{
|
||||
@ -32,8 +36,6 @@ namespace example
|
||||
|
||||
namespace boost { namespace fusion {
|
||||
|
||||
struct random_access_traversal_tag;
|
||||
|
||||
namespace traits
|
||||
{
|
||||
template<typename Struct, int Pos>
|
||||
@ -52,7 +54,11 @@ namespace example {
|
||||
BOOST_STATIC_ASSERT(Pos >=0 && Pos < 3);
|
||||
typedef Struct struct_type;
|
||||
typedef boost::mpl::int_<Pos> index;
|
||||
typedef boost::fusion::random_access_traversal_tag category;
|
||||
|
||||
struct category
|
||||
: boost::fusion::random_access_traversal_tag
|
||||
, boost::fusion::associative_tag
|
||||
{};
|
||||
|
||||
example_struct_iterator(Struct& str)
|
||||
: struct_(str) {}
|
||||
|
@ -56,6 +56,9 @@ int main()
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<example::example_struct, fields::name>::type, std::string>));
|
||||
BOOST_MPL_ASSERT((boost::is_same<result_of::value_at_key<example::example_struct, fields::age>::type, int>));
|
||||
|
||||
BOOST_TEST(deref_data(begin(bert)) == "bert");
|
||||
BOOST_TEST(deref_data(next(begin(bert))) == 99);
|
||||
|
||||
BOOST_TEST(size(bert) == 2);
|
||||
|
||||
return boost::report_errors();
|
||||
|
Reference in New Issue
Block a user