// Add macro to check the lifetime of initializer_list arguments. initializer_list has a very // short life span, and can only be used as a parameter, and not as a variable. #ifdefined(__clang__) && defined(__has_cpp_attribute) && __has_cpp_attribute(clang::lifetimebound) #define SK_CHECK_IL_LIFETIME [[clang::lifetimebound]] #else #define SK_CHECK_IL_LIFETIME #endif
/** * SkSpan holds a reference to contiguous data of type T along with a count. SkSpan does not own * the data itself but is merely a reference, therefore you must take care with the lifetime of * the underlying data. * * SkSpan is a count and a pointer into existing array or data type that stores its data in * contiguous memory like std::vector. Any container that works with std::size() and std::data() * can be used. * * SkSpan makes a convenient parameter for a routine to accept array like things. This allows you to * write the routine without overloads for all different container types. * * Example: * void routine(SkSpan<const int> a) { ... } * * std::vector v = {1, 2, 3, 4, 5}; * * routine(a); * * A word of caution when working with initializer_list, initializer_lists have a lifetime that is * limited to the current statement. The following is correct and safe: * * Example: * routine({1,2,3,4,5}); * * The following is undefined, and will result in erratic execution: * * Bad Example: * initializer_list l = {1, 2, 3, 4, 5}; // The data behind l dies at the ;. * routine(l);
*/ template <typename T> class SkSpan { public:
constexpr SkSpan() : fPtr{nullptr}, fSize{0} {}
// Should read offset + count > size(), but that could overflow. We know that safeOffset // is <= size, therefore the subtraction will not overflow. if (count > this->size() - safeOffset) SK_UNLIKELY { // The count is too large.
SkUNREACHABLE;
} return SkSpan{fPtr + safeOffset, count};
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.