encrypted.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_ENCRYPTED_HPP
26 #define CRYPTO3_ENCRYPTED_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 crypto3 {
37  namespace detail {
38  // A type generator to produce the transform_iterator type conditionally
39  // including a wrapped predicate as appropriate.
40  template<typename P, typename It>
42  typedef boost::transform_iterator<typename boost::range_detail::default_constructible_unary_fn_gen<
43  P,
44  typename boost::transform_iterator<P, It>::reference>::type,
45  It>
47  };
48 
49  template<class F, class R>
51  : public boost::iterator_range<
52  typename transform_iterator_gen<F, typename boost::range_iterator<R>::type>::type> {
53  private:
54  typedef
56 
57  typedef boost::iterator_range<transform_iter_t> base;
58 
59  public:
60  typedef typename boost::range_detail::default_constructible_unary_fn_gen<
61  F,
62  typename boost::transform_iterator<F, typename boost::range_iterator<R>::type>::reference>::type
64 
65  typedef R source_range_type;
66 
68  base(transform_iter_t(boost::begin(r), f), transform_iter_t(boost::end(r), f)) {
69  }
70  };
71 
72  template<class T>
73  struct encode_holder : boost::range_detail::holder<T> {
74  encode_holder(T r) : boost::range_detail::holder<T>(r) {
75  }
76  };
77 
78  template<class SinglePassRange, class UnaryFunction>
81  BOOST_RANGE_CONCEPT_ASSERT((boost::SinglePassRangeConcept<SinglePassRange>));
82 
84  }
85 
86  template<class SinglePassRange, class UnaryFunction>
88  operator|(const SinglePassRange &r, const encode_holder<UnaryFunction> &f) {
89  BOOST_RANGE_CONCEPT_ASSERT((boost::SinglePassRangeConcept<const SinglePassRange>));
90 
92  }
93 
94  } // namespace detail
95 
96  using detail::encoded_range;
97 
98  namespace adaptors {
99  namespace {
100  const range_detail::forwarder<detail::encode_holder> encoded =
101  detail::forwarder<detail::encode_holder>();
102  }
103 
104  template<class UnaryFunction, class SinglePassRange>
105  inline encoded_range<UnaryFunction, SinglePassRange> transform(SinglePassRange &rng, UnaryFunction fn) {
106  BOOST_RANGE_CONCEPT_ASSERT((boost::SinglePassRangeConcept<SinglePassRange>));
107 
109  }
110 
111  template<class UnaryFunction, class SinglePassRange>
113  UnaryFunction fn) {
114  BOOST_RANGE_CONCEPT_ASSERT((boost::SinglePassRangeConcept<const SinglePassRange>));
115 
117  }
118  } // namespace adaptors
119  } // namespace crypto3
120 } // namespace nil
121 
122 #endif // CRYPTO3_ENCRYPTED_HPP
encoded_range< UnaryFunction, SinglePassRange > transform(SinglePassRange &rng, UnaryFunction fn)
Definition: encrypted.hpp:105
encoded_range< UnaryFunction, SinglePassRange > operator|(SinglePassRange &r, const encode_holder< UnaryFunction > &f)
Definition: encrypted.hpp:79
Definition: pair.hpp:31
Definition: encrypted.hpp:73
encode_holder(T r)
Definition: encrypted.hpp:74
Definition: encrypted.hpp:52
boost::range_detail::default_constructible_unary_fn_gen< F, typename boost::transform_iterator< F, typename boost::range_iterator< R >::type >::reference >::type transform_fn_type
Definition: encrypted.hpp:63
R source_range_type
Definition: encrypted.hpp:65
encoded_range(transform_fn_type f, R &r)
Definition: encrypted.hpp:67
boost::transform_iterator< typename boost::range_detail::default_constructible_unary_fn_gen< P, typename boost::transform_iterator< P, It >::reference >::type, It > type
Definition: encrypted.hpp:46