block/include/nil/crypto3/block/accumulators/bits_count.hpp
Go to the documentation of this file.
1 //---------------------------------------------------------------------------//
2 // Copyright (c) 2018-2020 Mikhail Komarov <nemo@nil.foundation>
3 // Copyright (c) 2019 Aleksey Moskvin <zerg1996@yandex.ru>
4 //
5 // MIT License
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy
8 // of this software and associated documentation files (the "Software"), to deal
9 // in the Software without restriction, including without limitation the rights
10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 // copies of the Software, and to permit persons to whom the Software is
12 // furnished to do so, subject to the following conditions:
13 //
14 // The above copyright notice and this permission notice shall be included in all
15 // copies or substantial portions of the Software.
16 //
17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 // SOFTWARE.
24 //---------------------------------------------------------------------------//
25 
26 #ifndef CRYPTO3_BITS_COUNT_HPP
27 #define CRYPTO3_BITS_COUNT_HPP
28 
29 #include <boost/mpl/always.hpp>
30 
31 #include <boost/accumulators/framework/accumulator_base.hpp>
32 #include <boost/accumulators/framework/extractor.hpp>
33 #include <boost/accumulators/framework/depends_on.hpp>
34 #include <boost/accumulators/framework/parameters/sample.hpp>
35 
37 
38 namespace nil {
39  namespace crypto3 {
40  namespace accumulators {
41  namespace impl {
42 
44  // bits_count_impl
45  struct bits_count_impl : boost::accumulators::accumulator_base {
46  // for boost::result_of
47  typedef std::size_t result_type;
48 
49  bits_count_impl(boost::accumulators::dont_care) : cnt(0) {
50  }
51 
52  template<typename ArgumentPack>
53  inline void operator()(const ArgumentPack &args) {
54  resolve_type(args[boost::accumulators::sample], args[bits | std::size_t()]);
55  }
56 
57  inline result_type result(boost::accumulators::dont_care) const {
58  return cnt;
59  }
60 
61  protected:
62  template<typename Block>
63  inline void resolve_type(const Block &value, std::size_t bits) {
64  cnt += bits;
65  }
66 
67  std::size_t cnt;
68  };
69 
70  } // namespace impl
71 
73  // tag::count
74  //
75  namespace tag {
76  struct bits_count : boost::accumulators::depends_on<> {
79  typedef boost::mpl::always<accumulators::impl::bits_count_impl> impl;
80  };
81  } // namespace tag
82 
84  // extract::count
85  //
86  namespace extract {
87  boost::accumulators::extractor<tag::bits_count> const bits_count = {};
88 
89  BOOST_ACCUMULATORS_IGNORE_GLOBAL(bits_count)
90  } // namespace extract
91 
92  } // namespace accumulators
93  } // namespace crypto3
94 } // namespace nil
95 #endif // CRYPTO3_BLOCK_BITS_COUNT_HPP
boost::accumulators::extractor< tag::bits_count > const bits_count
Definition: block/include/nil/crypto3/block/accumulators/bits_count.hpp:87
Definition: pair.hpp:31
Definition: block/include/nil/crypto3/block/accumulators/bits_count.hpp:45
std::size_t result_type
Definition: block/include/nil/crypto3/block/accumulators/bits_count.hpp:47
std::size_t cnt
Definition: block/include/nil/crypto3/block/accumulators/bits_count.hpp:67
void resolve_type(const Block &value, std::size_t bits)
Definition: block/include/nil/crypto3/block/accumulators/bits_count.hpp:63
result_type result(boost::accumulators::dont_care) const
Definition: block/include/nil/crypto3/block/accumulators/bits_count.hpp:57
bits_count_impl(boost::accumulators::dont_care)
Definition: block/include/nil/crypto3/block/accumulators/bits_count.hpp:49
void operator()(const ArgumentPack &args)
Definition: block/include/nil/crypto3/block/accumulators/bits_count.hpp:53
Definition: block/include/nil/crypto3/block/accumulators/bits_count.hpp:76
boost::mpl::always< accumulators::impl::bits_count_impl > impl
Definition: block/include/nil/crypto3/block/accumulators/bits_count.hpp:79