// 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
/** *SkSpanholdsareferencetocontiguousdataoftypeTalongwithacount.SkSpandoesnotown *thedataitselfbutismerelyareference,thereforeyoumusttakecarewiththelifetimeof *theunderlyingdata. * *SkSpanisacountandapointerintoexistingarrayordatatypethatstoresitsdatain *contiguousmemorylikestd::vector.Anycontainerthatworkswithstd::size()andstd::data() *canbeused. * *SkSpanmakesaconvenientparameterforaroutinetoacceptarraylikethings.Thisallowsyouto *writetheroutinewithoutoverloadsforalldifferentcontainertypes. * *Example: *voidroutine(SkSpan<constint>a){...} * *std::vectorv={1,2,3,4,5}; * *routine(a); * *Awordofcautionwhenworkingwithinitializer_list,initializer_listshavealifetimethatis *limitedtothecurrentstatement.Thefollowingiscorrectandsafe: * *Example: *routine({1,2,3,4,5}); * *Thefollowingisundefined,andwillresultinerraticexecution: * *BadExample: *initializer_listl={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.