Line data Source code
1 : /**
2 : * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3 : * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4 : * CANN Open Software License Agreement Version 2.0 (the "License").
5 : * Please refer to the License for details. You may not use this file except in compliance with the License.
6 : * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7 : * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 : * See LICENSE in the root of the software repository for the full text of the License.
9 : */
10 :
11 : #ifndef HCCLV2_ITERATOR_UNCONST_H
12 : #define HCCLV2_ITERATOR_UNCONST_H
13 :
14 : namespace Hccl {
15 : using namespace std;
16 :
17 : template <template <class U, typename _Alloc = std::allocator<U>> class Sequence, typename T, typename Enable = void>
18 : class BaseIterator {};
19 :
20 : template <template <class U, typename _Alloc = std::allocator<U>> class Sequence, typename T>
21 : class BaseIterator<Sequence, T, typename enable_if<IsSharedPtr<T>::value || IsUniquePtr<T>::value>::type> {
22 : public:
23 : using V = typename T::element_type;
24 :
25 : BaseIterator() : iter(nullptr), end(nullptr) {};
26 :
27 23 : explicit BaseIterator(Sequence<T>& seq) : iter(seq.begin()), end(seq.end()) {};
28 29 : virtual ~BaseIterator() {};
29 :
30 6 : virtual V& operator*() { return *(*iter); };
31 :
32 19 : virtual V* operator->() { return (*iter).get(); };
33 :
34 1 : virtual BaseIterator& Next()
35 : {
36 1 : iter++;
37 1 : return *this;
38 : };
39 :
40 15 : virtual BaseIterator& operator++()
41 : {
42 15 : iter++;
43 15 : return *this;
44 : }
45 :
46 32 : virtual bool HasNext() { return iter != end; };
47 :
48 : protected:
49 : typename Sequence<T>::iterator iter;
50 : typename Sequence<T>::iterator end;
51 : };
52 :
53 : } // namespace Hccl
54 :
55 : #endif // HCCLV2_ITERATOR_H
|