/src/glslang/glslang/MachineIndependent/span.h
Line | Count | Source |
1 | | #pragma once |
2 | | |
3 | | // |
4 | | // Copyright (C) 2023 LunarG, Inc. |
5 | | // |
6 | | // All rights reserved. |
7 | | // |
8 | | // Redistribution and use in source and binary forms, with or without |
9 | | // modification, are permitted provided that the following conditions |
10 | | // are met: |
11 | | // |
12 | | // Redistributions of source code must retain the above copyright |
13 | | // notice, this list of conditions and the following disclaimer. |
14 | | // |
15 | | // Redistributions in binary form must reproduce the above |
16 | | // copyright notice, this list of conditions and the following |
17 | | // disclaimer in the documentation and/or other materials provided |
18 | | // with the distribution. |
19 | | // |
20 | | // Neither the name of 3Dlabs Inc. Ltd. nor the names of its |
21 | | // contributors may be used to endorse or promote products derived |
22 | | // from this software without specific prior written permission. |
23 | | // |
24 | | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
25 | | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
26 | | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
27 | | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
28 | | // COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
29 | | // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
30 | | // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
31 | | // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
32 | | // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
33 | | // LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN |
34 | | // ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
35 | | // POSSIBILITY OF SUCH DAMAGE. |
36 | | // |
37 | | |
38 | | // Partial implementation of std::span for C++11 |
39 | | // Replace with std::span if repo standard is bumped to C++20 |
40 | | // |
41 | | // This code was copied from https://github.com/KhronosGroup/Vulkan-ValidationLayers/blob/main/layers/containers/custom_containers.h |
42 | | template <typename T> |
43 | | class span { |
44 | | public: |
45 | | using pointer = T *; |
46 | | using const_pointer = T const *; |
47 | | using iterator = pointer; |
48 | | using const_iterator = const_pointer; |
49 | | |
50 | 90 | span() = default; |
51 | | span(pointer start, size_t n) : data_(start), count_(n) {} |
52 | | template <typename Iterator> |
53 | | span(Iterator start, Iterator end) : data_(&(*start)), count_(end - start) {} |
54 | | template <typename Container> |
55 | 167 | span(Container &c) : data_(c.data()), count_(c.size()) {}Initialize.cpp:span<glslang::(anonymous namespace)::Versioning const>::span<std::__1::array<glslang::(anonymous namespace)::Versioning, 2ul> const>(std::__1::array<glslang::(anonymous namespace)::Versioning, 2ul> const&) Line | Count | Source | 55 | 68 | span(Container &c) : data_(c.data()), count_(c.size()) {} |
Initialize.cpp:span<glslang::(anonymous namespace)::BuiltInFunction const>::span<std::__1::array<glslang::(anonymous namespace)::BuiltInFunction, 79ul> const>(std::__1::array<glslang::(anonymous namespace)::BuiltInFunction, 79ul> const&) Line | Count | Source | 55 | 46 | span(Container &c) : data_(c.data()), count_(c.size()) {} |
Initialize.cpp:span<glslang::(anonymous namespace)::BuiltInFunction const>::span<std::__1::array<glslang::(anonymous namespace)::BuiltInFunction, 3ul> const>(std::__1::array<glslang::(anonymous namespace)::BuiltInFunction, 3ul> const&) Line | Count | Source | 55 | 53 | span(Container &c) : data_(c.data()), count_(c.size()) {} |
|
56 | | |
57 | | iterator begin() { return data_; } |
58 | 1.66k | const_iterator begin() const { return data_; }Initialize.cpp:span<glslang::(anonymous namespace)::BuiltInFunction const>::begin() const Line | Count | Source | 58 | 99 | const_iterator begin() const { return data_; } |
Initialize.cpp:span<glslang::(anonymous namespace)::Versioning const>::begin() const Line | Count | Source | 58 | 1.56k | const_iterator begin() const { return data_; } |
|
59 | | |
60 | | iterator end() { return data_ + count_; } |
61 | 1.66k | const_iterator end() const { return data_ + count_; }Initialize.cpp:span<glslang::(anonymous namespace)::BuiltInFunction const>::end() const Line | Count | Source | 61 | 99 | const_iterator end() const { return data_ + count_; } |
Initialize.cpp:span<glslang::(anonymous namespace)::Versioning const>::end() const Line | Count | Source | 61 | 1.56k | const_iterator end() const { return data_ + count_; } |
|
62 | | |
63 | | T &operator[](int i) { return data_[i]; } |
64 | | const T &operator[](int i) const { return data_[i]; } |
65 | | |
66 | | T &front() { return *data_; } |
67 | | const T &front() const { return *data_; } |
68 | | |
69 | | T &back() { return *(data_ + (count_ - 1)); } |
70 | | const T &back() const { return *(data_ + (count_ - 1)); } |
71 | | |
72 | | size_t size() const { return count_; } |
73 | 3.79k | bool empty() const { return count_ == 0; } |
74 | | |
75 | | pointer data() { return data_; } |
76 | | const_pointer data() const { return data_; } |
77 | | |
78 | | private: |
79 | | pointer data_ = {}; |
80 | | size_t count_ = 0; |
81 | | }; |
82 | | |
83 | | // |
84 | | // Allow type inference that using the constructor doesn't allow in C++11 |
85 | | template <typename T> |
86 | | span<T> make_span(T *begin, size_t count) { |
87 | | return span<T>(begin, count); |
88 | | } |
89 | | template <typename T> |
90 | | span<T> make_span(T *begin, T *end) { |
91 | | return make_span<T>(begin, end); |
92 | | } |