blob: 14f876568eef903e0b2372a5b178e47b7d799b9c [file] [log] [blame]
Jeff Thompsona28eed82013-08-22 16:21:10 -07001
Jeff Thompson3d613fd2013-10-15 15:39:04 -07002#ifndef NDNBOOST_MPL_ITER_FOLD_IF_HPP_INCLUDED
3#define NDNBOOST_MPL_ITER_FOLD_IF_HPP_INCLUDED
Jeff Thompsona28eed82013-08-22 16:21:10 -07004
5// Copyright Aleksey Gurtovoy 2003-2004
6// Copyright Eric Friedman 2003
7//
8// Distributed under the Boost Software License, Version 1.0.
9// (See accompanying file LICENSE_1_0.txt or copy at
10// http://www.boost.org/LICENSE_1_0.txt)
11//
12// See http://www.boost.org/libs/mpl for documentation.
13
14// $Id: iter_fold_if.hpp 49267 2008-10-11 06:19:02Z agurtovoy $
15// $Date: 2008-10-10 23:19:02 -0700 (Fri, 10 Oct 2008) $
16// $Revision: 49267 $
17
18#include <ndnboost/mpl/begin_end.hpp>
19#include <ndnboost/mpl/logical.hpp>
20#include <ndnboost/mpl/always.hpp>
21#include <ndnboost/mpl/eval_if.hpp>
22#include <ndnboost/mpl/if.hpp>
23#include <ndnboost/mpl/pair.hpp>
24#include <ndnboost/mpl/apply.hpp>
25#include <ndnboost/mpl/aux_/iter_fold_if_impl.hpp>
26#include <ndnboost/mpl/aux_/na_spec.hpp>
27#include <ndnboost/mpl/aux_/lambda_support.hpp>
28#include <ndnboost/mpl/aux_/config/forwarding.hpp>
29#include <ndnboost/mpl/aux_/config/workaround.hpp>
30
31#include <ndnboost/type_traits/is_same.hpp>
32
33namespace ndnboost { namespace mpl {
34
35namespace aux {
36
37template< typename Predicate, typename LastIterator >
38struct iter_fold_if_pred
39{
40 template< typename State, typename Iterator > struct apply
Jeff Thompson3d613fd2013-10-15 15:39:04 -070041#if !defined(NDNBOOST_MPL_CFG_NO_NESTED_FORWARDING)
Jeff Thompsona28eed82013-08-22 16:21:10 -070042 : and_<
43 not_< is_same<Iterator,LastIterator> >
44 , apply1<Predicate,Iterator>
45 >
46 {
47#else
48 {
49 typedef and_<
50 not_< is_same<Iterator,LastIterator> >
51 , apply1<Predicate,Iterator>
52 > type;
53#endif
54 };
55};
56
57} // namespace aux
58
59template<
Jeff Thompson3d613fd2013-10-15 15:39:04 -070060 typename NDNBOOST_MPL_AUX_NA_PARAM(Sequence)
61 , typename NDNBOOST_MPL_AUX_NA_PARAM(State)
62 , typename NDNBOOST_MPL_AUX_NA_PARAM(ForwardOp)
63 , typename NDNBOOST_MPL_AUX_NA_PARAM(ForwardPredicate)
64 , typename NDNBOOST_MPL_AUX_NA_PARAM(BackwardOp)
65 , typename NDNBOOST_MPL_AUX_NA_PARAM(BackwardPredicate)
Jeff Thompsona28eed82013-08-22 16:21:10 -070066 >
67struct iter_fold_if
68{
69
70 typedef typename begin<Sequence>::type first_;
71 typedef typename end<Sequence>::type last_;
72
73 typedef typename eval_if<
74 is_na<BackwardPredicate>
75 , if_< is_na<BackwardOp>, always<false_>, always<true_> >
76 , identity<BackwardPredicate>
77 >::type backward_pred_;
78
79// cwpro8 doesn't like 'cut-off' type here (use typedef instead)
Jeff Thompson3d613fd2013-10-15 15:39:04 -070080#if !NDNBOOST_WORKAROUND(__MWERKS__, NDNBOOST_TESTED_AT(0x3003)) && !NDNBOOST_WORKAROUND(__IBMCPP__, NDNBOOST_TESTED_AT(600))
Jeff Thompsona28eed82013-08-22 16:21:10 -070081 struct result_ :
82#else
83 typedef
84#endif
85 aux::iter_fold_if_impl<
86 first_
87 , State
88 , ForwardOp
89 , protect< aux::iter_fold_if_pred< ForwardPredicate,last_ > >
90 , BackwardOp
91 , backward_pred_
92 >
Jeff Thompson3d613fd2013-10-15 15:39:04 -070093#if !NDNBOOST_WORKAROUND(__MWERKS__, NDNBOOST_TESTED_AT(0x3003)) && !NDNBOOST_WORKAROUND(__IBMCPP__, NDNBOOST_TESTED_AT(600))
Jeff Thompsona28eed82013-08-22 16:21:10 -070094 { };
95#else
96 result_;
97#endif
98
99public:
100
101 typedef pair<
102 typename result_::state
103 , typename result_::iterator
104 > type;
105
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700106 NDNBOOST_MPL_AUX_LAMBDA_SUPPORT(
Jeff Thompsona28eed82013-08-22 16:21:10 -0700107 6
108 , iter_fold_if
109 , (Sequence,State,ForwardOp,ForwardPredicate,BackwardOp,BackwardPredicate)
110 )
111};
112
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700113NDNBOOST_MPL_AUX_NA_SPEC(6, iter_fold_if)
Jeff Thompsona28eed82013-08-22 16:21:10 -0700114
115}}
116
Jeff Thompson3d613fd2013-10-15 15:39:04 -0700117#endif // NDNBOOST_MPL_ITER_FOLD_IF_HPP_INCLUDED