decrypted.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation>
3 //
4 // MIT License
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a copy
7 // of this software and associated documentation files (the "Software"), to deal
8 // in the Software without restriction, including without limitation the rights
9 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 // copies of the Software, and to permit persons to whom the Software is
11 // furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in all
14 // copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 // SOFTWARE.
23 //---------------------------------------------------------------------------//
24 
25 #ifndef CRYPTO3_DECRYPTED_HPP
26 #define CRYPTO3_DECRYPTED_HPP
27 
28 #include <boost/range/adaptor/argument_fwd.hpp>
29 #include <boost/range/detail/default_constructible_unary_fn.hpp>
30 #include <boost/range/iterator_range.hpp>
31 #include <boost/range/concepts.hpp>
32 #include <boost/iterator/transform_iterator.hpp>
33 #include <boost/utility/result_of.hpp>
34 
35 namespace nil {
36  namespace range_detail {
37  // A type generator to produce the transform_iterator type conditionally
38  // including a wrapped predicate as appropriate.
39  template<typename P, typename It>
41  typedef transform_iterator<
42  typename default_constructible_unary_fn_gen<P, typename transform_iterator<P, It>::reference>::type,
43  It>
45  };
46 
47  template<class F, class R>
49  : public boost::iterator_range<typename transform_iterator_gen<F, typename range_iterator<R>::type>::type> {
50  private:
51  typedef typename transform_iterator_gen<F, typename range_iterator<R>::type>::type transform_iter_t;
52 
53  typedef boost::iterator_range<transform_iter_t> base;
54 
55  public:
56  typedef typename default_constructible_unary_fn_gen<
57  F,
58  typename transform_iterator<F, typename range_iterator<R>::type>::reference>::type transform_fn_type;
59 
60  typedef R source_range_type;
61 
63  base(transform_iter_t(boost::begin(r), f), transform_iter_t(boost::end(r), f)) {
64  }
65  };
66 
67  template<class T>
68  struct transform_holder : holder<T> {
69  transform_holder(T r) : holder<T>(r) {
70  }
71  };
72 
73  template<class SinglePassRange, class UnaryFunction>
76  BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<SinglePassRange>));
77 
79  }
80 
81  template<class SinglePassRange, class UnaryFunction>
84  BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<const SinglePassRange>));
85 
87  }
88 
89  } // namespace range_detail
90 
91  using range_detail::decoded_range;
92 
93  namespace adaptors {
94  namespace {
95  const range_detail::forwarder<range_detail::transform_holder> decoded =
96  range_detail::forwarder<range_detail::transform_holder>();
97  }
98 
99  template<class UnaryFunction, class SinglePassRange>
100  inline decoded_range<UnaryFunction, SinglePassRange> transform(SinglePassRange &rng, UnaryFunction fn) {
101  BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<SinglePassRange>));
102 
104  }
105 
106  template<class UnaryFunction, class SinglePassRange>
108  UnaryFunction fn) {
109  BOOST_RANGE_CONCEPT_ASSERT((SinglePassRangeConcept<const SinglePassRange>));
110 
112  }
113  } // namespace adaptors
114 
115 } // namespace nil
116 
117 #endif // CRYPTO3_DECRYPTED_HPP
decoded_range< UnaryFunction, SinglePassRange > transform(SinglePassRange &rng, UnaryFunction fn)
Definition: decrypted.hpp:100
decoded_range< UnaryFunction, SinglePassRange > operator|(SinglePassRange &r, const transform_holder< UnaryFunction > &f)
Definition: decrypted.hpp:74
Definition: pair.hpp:31
Definition: decrypted.hpp:49
default_constructible_unary_fn_gen< F, typename transform_iterator< F, typename range_iterator< R >::type >::reference >::type transform_fn_type
Definition: decrypted.hpp:58
R source_range_type
Definition: decrypted.hpp:60
decoded_range(transform_fn_type f, R &r)
Definition: decrypted.hpp:62
Definition: decrypted.hpp:68
transform_holder(T r)
Definition: decrypted.hpp:69
Definition: decrypted.hpp:40
transform_iterator< typename default_constructible_unary_fn_gen< P, typename transform_iterator< P, It >::reference >::type, It > type
Definition: decrypted.hpp:44