Publishing R5 content (#72)
[platform/upstream/dldt.git] / inference-engine / src / inference_engine / ie_algorithm.hpp
1 // Copyright (C) 2018 Intel Corporation
2 // SPDX-License-Identifier: Apache-2.0
3 //
4
5 #pragma once
6 #include <functional>
7 #include <algorithm>
8 #include <numeric>
9
10 namespace InferenceEngine {
11 namespace details {
12 /**
13  * @rationale - associative containers doesnt work with remove_if algorithm
14  * @tparam ContainerT
15  * @tparam PredicateT
16  * @param items
17  * @param predicate
18  */
19 template<typename Container, typename PredicateT>
20 inline void erase_if(Container &data, const PredicateT &predicate) {
21     for (auto it = std::begin(data); it != std::end(data);) {
22         if (predicate(*it)) {
23             it = data.erase(it);
24         } else {
25             ++it;
26         }
27     }
28 }
29 /**
30  * @brief multiply vector's values
31  * @param vec - vector with values
32  * @return result of multiplication
33  */
34
35 template<typename TIterator>
36 auto product(TIterator beg, TIterator en) -> typename std::remove_reference<decltype(*beg)>::type {
37     return std::accumulate(beg, en,
38                            static_cast<typename std::remove_reference<decltype(*beg)>::type>(1),
39                            std::multiplies<typename std::remove_reference<decltype(*beg)>::type>());
40 }
41 }  // namespace details
42 }  // namespace InferenceEngine