Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 1 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 2 | #ifndef NDNBOOST_MPL_ITER_FOLD_IF_HPP_INCLUDED |
| 3 | #define NDNBOOST_MPL_ITER_FOLD_IF_HPP_INCLUDED |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 4 | |
| 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 | |
| 33 | namespace ndnboost { namespace mpl { |
| 34 | |
| 35 | namespace aux { |
| 36 | |
| 37 | template< typename Predicate, typename LastIterator > |
| 38 | struct iter_fold_if_pred |
| 39 | { |
| 40 | template< typename State, typename Iterator > struct apply |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 41 | #if !defined(NDNBOOST_MPL_CFG_NO_NESTED_FORWARDING) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 42 | : 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 | |
| 59 | template< |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 60 | 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 Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 66 | > |
| 67 | struct 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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 80 | #if !NDNBOOST_WORKAROUND(__MWERKS__, NDNBOOST_TESTED_AT(0x3003)) && !NDNBOOST_WORKAROUND(__IBMCPP__, NDNBOOST_TESTED_AT(600)) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 81 | 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 Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 93 | #if !NDNBOOST_WORKAROUND(__MWERKS__, NDNBOOST_TESTED_AT(0x3003)) && !NDNBOOST_WORKAROUND(__IBMCPP__, NDNBOOST_TESTED_AT(600)) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 94 | { }; |
| 95 | #else |
| 96 | result_; |
| 97 | #endif |
| 98 | |
| 99 | public: |
| 100 | |
| 101 | typedef pair< |
| 102 | typename result_::state |
| 103 | , typename result_::iterator |
| 104 | > type; |
| 105 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 106 | NDNBOOST_MPL_AUX_LAMBDA_SUPPORT( |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 107 | 6 |
| 108 | , iter_fold_if |
| 109 | , (Sequence,State,ForwardOp,ForwardPredicate,BackwardOp,BackwardPredicate) |
| 110 | ) |
| 111 | }; |
| 112 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 113 | NDNBOOST_MPL_AUX_NA_SPEC(6, iter_fold_if) |
Jeff Thompson | a28eed8 | 2013-08-22 16:21:10 -0700 | [diff] [blame] | 114 | |
| 115 | }} |
| 116 | |
Jeff Thompson | 3d613fd | 2013-10-15 15:39:04 -0700 | [diff] [blame^] | 117 | #endif // NDNBOOST_MPL_ITER_FOLD_IF_HPP_INCLUDED |