1 /*=============================================================================
2 Copyright (c) 2006 Eric Niebler
4 Use, modification and distribution is subject to the Boost Software
5 License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
6 http://www.boost.org/LICENSE_1_0.txt)
7 ==============================================================================*/
8 #ifndef FUSION_BINARY_TREE_EAN_05032006_1027
9 #define FUSION_BINARY_TREE_EAN_05032006_1027
11 #include <boost/mpl/if.hpp>
12 #include <boost/type_traits/is_const.hpp>
13 #include <boost/type_traits/add_const.hpp>
14 #include <boost/type_traits/add_reference.hpp>
15 #include <boost/fusion/support/is_sequence.hpp>
16 #include <boost/fusion/sequence/intrinsic/at.hpp>
17 #include <boost/fusion/view/single_view.hpp>
18 #include <boost/fusion/container/list/cons.hpp> // for nil
19 #include <boost/fusion/container/vector/vector10.hpp>
20 #include <boost/fusion/support/sequence_base.hpp>
21 #include <boost/fusion/sequence/intrinsic/ext_/segments.hpp>
22 #include <boost/fusion/support/ext_/is_segmented.hpp>
23 #include <boost/fusion/view/ext_/segmented_iterator.hpp>
25 namespace boost
{ namespace fusion
31 template<typename T
, bool IsConst
>
32 struct reference
: add_reference
<T
> {};
35 struct reference
<T
, true> : reference
<typename add_const
<T
>::type
, false> {};
38 struct reference
<T
&, true> : reference
<T
, false> {};
41 template<typename Data
, typename Left
= nil
, typename Right
= nil
>
43 : sequence_base
<tree
<Data
, Left
, Right
> >
45 typedef Data data_type
;
46 typedef Left left_type
;
47 typedef Right right_type
;
48 typedef tree_tag fusion_tag
;
49 typedef forward_traversal_tag category
;
50 typedef mpl::false_ is_view
;
52 typedef typename
mpl::if_
<
53 traits::is_sequence
<Data
>
59 typename
fusion::detail::call_param
<Data
>::type data_
60 , typename
fusion::detail::call_param
<Left
>::type left_
= Left()
61 , typename
fusion::detail::call_param
<Right
>::type right_
= Right()
63 : segments(left_
, data_view(data_
), right_
)
66 typedef vector3
<Left
, data_view
, Right
> segments_type
;
67 segments_type segments
;
70 template<typename Data
>
71 tree
<Data
> make_tree(Data
const &data
)
73 return tree
<Data
>(data
);
76 template<typename Data
, typename Left
, typename Right
>
77 tree
<Data
, Left
, Right
> make_tree(Data
const &data
, Left
const &left
, Right
const &right
)
79 return tree
<Data
, Left
, Right
>(data
, left
, right
);
85 struct is_segmented_impl
<tree_tag
>
87 template<typename Sequence
>
88 struct apply
: mpl::true_
{};
92 struct segments_impl
<tree_tag
>
94 template<typename Sequence
>
97 typedef typename
mpl::if_
<
99 , typename
Sequence::segments_type
const &
100 , typename
Sequence::segments_type
&
103 static type
call(Sequence
&seq
)
111 struct begin_impl
<tree_tag
>
113 template<typename Sequence
>
115 : segmented_begin
<Sequence
>
120 struct end_impl
<tree_tag
>
122 template<typename Sequence
>
124 : segmented_end
<Sequence
>