1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 #ifndef META_BASE_ALGORITHMS_H
16 #define META_BASE_ALGORITHMS_H
17 
18 #include <stdint.h>
19 
20 #include <base/containers/type_traits.h>
21 #include <base/containers/vector.h>
22 
23 #include <meta/base/namespace.h>
24 
25 META_BEGIN_NAMESPACE()
26 
27 constexpr size_t NPOS = -1;
28 
29 template<typename Type>
30 size_t FindFirstOf(const BASE_NS::vector<Type>& vec, const Type& value, size_t pos = 0)
31 {
32     for (; pos < vec.size(); ++pos) {
33         if (vec[pos] == value) {
34             return pos;
35         }
36     }
37     return NPOS;
38 }
39 
40 META_END_NAMESPACE()
41 
42 #endif
43