/// /// Wrap up an integer type so that we prevent accidental conversion to other integer types. /// /// e.g. /// typedef o3tl::strong_int<unsigned, struct MyIntTag> MyInt; /// /// \param UNDERLYING_TYPE the underlying scalar type /// \param PHANTOM_TYPE a type tag, used to distinguish this instantiation of the template /// from other instantiations with the same UNDERLYING_TYPE. /// template <typename UNDERLYING_TYPE, typename PHANTOM_TYPE> struct strong_int
{ public: // when compiling LO on macOS, debug builds will display a linking error where, see // <https://lists.freedesktop.org/archives/libreoffice/2024-February/091564.html>, "Our Clang // --enable-pch setup is known broken": #ifdefined MACOSX && defined __clang__ && (__clang_major__ == 16 || __clang_major__ == 17) && ENABLE_PCH explicit constexpr strong_int(unsignedlonglong value) : m_value(value) {} explicit constexpr strong_int(unsignedlong value) : m_value(value) {} explicit constexpr strong_int(long value) : m_value(value) {} explicit constexpr strong_int(int value) : m_value(value) {} explicit constexpr strong_int(unsignedint value) : m_value(value) {} #else template<typename T> explicit constexpr strong_int(
T value, typename std::enable_if<std::is_integral<T>::value, int>::type = 0):
m_value(value)
{ #if !defined(__COVERITY__) || __COVERITY_MAJOR__ > 2023 // catch attempts to pass in out-of-range values early
assert(detail::isInRange<UNDERLYING_TYPE>(value)
&& "out of range"); #endif
} #endif
strong_int() : m_value(0) {}
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.