// Copyright 2023 The Dawn & Tint Authors // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // 1. Redistributions of source code must retain the above copyright notice, this // list of conditions and the following disclaimer. // // 2. Redistributions in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // 3. Neither the name of the copyright holder nor the names of its // contributors may be used to endorse or promote products derived from // this software without specific prior written permission. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef SRC_TINT_UTILS_CONTAINERS_SLICE_H_ #define SRC_TINT_UTILS_CONTAINERS_SLICE_H_ #include <array> #include <cstdint> #include <iterator> #include "src/tint/utils/ice/ice.h" #include "src/tint/utils/memory/bitcast.h" #include "src/tint/utils/rtti/castable.h" #include "src/tint/utils/traits/traits.h" namespace tint { /// A type used to indicate an empty array. struct EmptyType { … }; /// An instance of the EmptyType. static constexpr EmptyType Empty; /// Mode enumerator for ReinterpretSlice enum class ReinterpretMode { … }; namespace detail { ConstRemoved; /// Private implementation of tint::CanReinterpretSlice. /// Specialized for the case of TO equal to FROM, which is the common case, and avoids inspection of /// the base classes, which can be troublesome if the slice is of an incomplete type. template <ReinterpretMode MODE, typename TO, typename FROM> struct CanReinterpretSlice { … }; /// Specialization of 'CanReinterpretSlice' for when TO and FROM are equal types. CanReinterpretSlice<MODE, T, T>; } // namespace detail /// Evaluates whether a `Slice<FROM>` and be reinterpreted as a `Slice<TO>`. /// Slices can be reinterpreted if: /// * TO has the same or more 'constness' than FROM. /// * And either: /// * `FROM` and `TO` are pointers to the same type /// * `FROM` and `TO` are pointers to CastableBase (or derived), and the pointee type of `TO` is of /// the same type as, or is an ancestor of the pointee type of `FROM`. CanReinterpretSlice; /// A slice represents a contigious array of elements of type T. template <typename T> struct Slice { … }; /// Deduction guide for Slice from c-array /// @param elements the input elements template <typename T, size_t N> Slice(T (&elements)[N]) -> Slice<T>; } // namespace tint #endif // SRC_TINT_UTILS_CONTAINERS_SLICE_H_