diff options
author | Dmitry Potapov <potapov.d@gmail.com> | 2022-02-10 16:46:39 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:39 +0300 |
commit | 536101ea75c9ff5df10d01c2f460b1f6e12311b3 (patch) | |
tree | 115291277ad61b2cdcf5044d210fb103b5e1647e /util | |
parent | 5036b5f2122001f9aef8a0e4cd85440d73ea6b9f (diff) | |
download | ydb-536101ea75c9ff5df10d01c2f460b1f6e12311b3.tar.gz |
Restoring authorship annotation for Dmitry Potapov <potapov.d@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'util')
-rw-r--r-- | util/generic/cast.h | 34 | ||||
-rw-r--r-- | util/generic/string.h | 8 | ||||
-rw-r--r-- | util/generic/typelist.h | 2 | ||||
-rw-r--r-- | util/generic/yexception.h | 4 | ||||
-rw-r--r-- | util/generic/ylimits.h | 36 | ||||
-rw-r--r-- | util/generic/ylimits_ut.cpp | 12 | ||||
-rw-r--r-- | util/memory/blob.cpp | 6 | ||||
-rw-r--r-- | util/string/cast.h | 66 | ||||
-rw-r--r-- | util/string/cast_ut.cpp | 4 |
9 files changed, 86 insertions, 86 deletions
diff --git a/util/generic/cast.h b/util/generic/cast.h index 0d4a41f385..0d680f90bd 100644 --- a/util/generic/cast.h +++ b/util/generic/cast.h @@ -1,14 +1,14 @@ #pragma once #include "typetraits.h" -#include "yexception.h" +#include "yexception.h" #include <util/system/compat.h> #include <util/system/type_name.h> #include <util/system/unaligned_mem.h> #include <util/system/yassert.h> -#include <cstdlib> +#include <cstdlib> template <class T, class F> static inline T VerifyDynamicCast(F f) { @@ -87,7 +87,7 @@ constexpr bool IsNegative(const TType value) noexcept { return TInteger<std::is_unsigned<TType>::value>::IsNegative(value); } -namespace NPrivate { +namespace NPrivate { template <class T> using TUnderlyingTypeOrSelf = typename std::conditional< std::is_enum<T>::value, @@ -96,21 +96,21 @@ namespace NPrivate { >::type::type; // Left ::type is for std::conditional, right ::type is for underlying_type/enable_if template <class TSmall, class TLarge> - struct TSafelyConvertible { + struct TSafelyConvertible { using TSmallInt = TUnderlyingTypeOrSelf<TSmall>; using TLargeInt = TUnderlyingTypeOrSelf<TLarge>; static constexpr bool Result = std::is_integral<TSmallInt>::value && std::is_integral<TLargeInt>::value && ((std::is_signed<TSmallInt>::value == std::is_signed<TLargeInt>::value && sizeof(TSmallInt) >= sizeof(TLargeInt)) || (std::is_signed<TSmallInt>::value && sizeof(TSmallInt) > sizeof(TLargeInt))); - }; -} - + }; +} + template <class TSmallInt, class TLargeInt> constexpr std::enable_if_t<::NPrivate::TSafelyConvertible<TSmallInt, TLargeInt>::Result, TSmallInt> SafeIntegerCast(TLargeInt largeInt) noexcept { return static_cast<TSmallInt>(largeInt); -} - +} + template <class TSmall, class TLarge> inline std::enable_if_t<!::NPrivate::TSafelyConvertible<TSmall, TLarge>::Result, TSmall> SafeIntegerCast(TLarge largeInt) { using TSmallInt = ::NPrivate::TUnderlyingTypeOrSelf<TSmall>; @@ -127,7 +127,7 @@ inline std::enable_if_t<!::NPrivate::TSafelyConvertible<TSmall, TLarge>::Result, TSmallInt smallInt = TSmallInt(largeInt); if (std::is_signed<TSmallInt>::value && std::is_unsigned<TLargeInt>::value) { - if (IsNegative(smallInt)) { + if (IsNegative(smallInt)) { ythrow TBadCastException() << "Conversion '" << TypeName<TLarge>() << '{' << TLargeInt(largeInt) << "}' to '" << TypeName<TSmallInt>() << "', positive value converted to negative"; @@ -141,15 +141,15 @@ inline std::enable_if_t<!::NPrivate::TSafelyConvertible<TSmall, TLarge>::Result, return static_cast<TSmall>(smallInt); } - -template <class TSmallInt, class TLargeInt> + +template <class TSmallInt, class TLargeInt> inline TSmallInt IntegerCast(TLargeInt largeInt) noexcept { - try { - return SafeIntegerCast<TSmallInt>(largeInt); - } catch (const yexception& exc) { + try { + return SafeIntegerCast<TSmallInt>(largeInt); + } catch (const yexception& exc) { Y_FAIL("IntegerCast: %s", exc.what()); - } -} + } +} /* Convert given enum value to its underlying type. This is just a shortcut for * `static_cast<std::underlying_type_t<EEnum>>(enum_)`. diff --git a/util/generic/string.h b/util/generic/string.h index 8cd8aa6917..61a4bd55ef 100644 --- a/util/generic/string.h +++ b/util/generic/string.h @@ -864,7 +864,7 @@ public: */ friend TBasicString operator+(TBasicString&& s1, const TBasicString& s2) Y_WARN_UNUSED_RESULT { - s1 += s2; + s1 += s2; return std::move(s1); } @@ -880,17 +880,17 @@ public: return std::move(s2); } #endif - s1 += s2; + s1 += s2; return std::move(s1); } friend TBasicString operator+(TBasicString&& s1, const TBasicStringBuf<TCharType, TTraits> s2) Y_WARN_UNUSED_RESULT { - s1 += s2; + s1 += s2; return std::move(s1); } friend TBasicString operator+(TBasicString&& s1, const TCharType* s2) Y_WARN_UNUSED_RESULT { - s1 += s2; + s1 += s2; return std::move(s1); } diff --git a/util/generic/typelist.h b/util/generic/typelist.h index 5ce26ab97c..7f2a316748 100644 --- a/util/generic/typelist.h +++ b/util/generic/typelist.h @@ -80,7 +80,7 @@ namespace NTL { using TSignedInts = typename TConcat<TTypeList<T>, TS>::type; using TUnsignedInts = TU; }; - + template <class T, class TS, class TU> struct TTypeSelectorBase<false, T, TS, TU> { using TSignedInts = TS; diff --git a/util/generic/yexception.h b/util/generic/yexception.h index b0c604e8c4..51f7bde050 100644 --- a/util/generic/yexception.h +++ b/util/generic/yexception.h @@ -129,8 +129,8 @@ class TFileError: public TIoSystemError { * TBadArgumentException. */ struct TBadArgumentException: public virtual yexception { -}; - +}; + /** * TBadCastException should be thrown to indicate the failure of some type casting procedure * (e.g. reading an integer parameter from string). diff --git a/util/generic/ylimits.h b/util/generic/ylimits.h index fe42b4dfc0..599effa481 100644 --- a/util/generic/ylimits.h +++ b/util/generic/ylimits.h @@ -15,30 +15,30 @@ template <class T> static constexpr T Min() noexcept { return std::numeric_limits<T>::min(); } - -namespace NPrivate { - struct TMax { - template <class T> + +namespace NPrivate { + struct TMax { + template <class T> constexpr operator T() const { - return Max<T>(); - } - }; - - struct TMin { - template <class T> + return Max<T>(); + } + }; + + struct TMin { + template <class T> constexpr operator T() const { - return Min<T>(); - } - }; -} - + return Min<T>(); + } + }; +} + static constexpr ::NPrivate::TMax Max() noexcept { return {}; -} - +} + static constexpr ::NPrivate::TMin Min() noexcept { return {}; -} +} namespace NPrivate { template <unsigned long long N> diff --git a/util/generic/ylimits_ut.cpp b/util/generic/ylimits_ut.cpp index f1b3c6858c..3a0a70adc9 100644 --- a/util/generic/ylimits_ut.cpp +++ b/util/generic/ylimits_ut.cpp @@ -1,4 +1,4 @@ -#include "cast.h" +#include "cast.h" #include "ylimits.h" #include <library/cpp/testing/unittest/registar.h> @@ -42,11 +42,11 @@ static inline bool TestIntegralLimits(const T&, bool unknownSign = true, bool is CHECK_COND((unknownSign && ((lim::is_signed && (lim::min() != 0)) || (!lim::is_signed && (lim::min() == 0)))) || (!unknownSign && ((lim::is_signed && isSigned) || (!lim::is_signed && !isSigned)))); - T min = Min(); - UNIT_ASSERT_EQUAL(lim::min(), min); - T max = Max(); - UNIT_ASSERT_EQUAL(lim::max(), max); - + T min = Min(); + UNIT_ASSERT_EQUAL(lim::min(), min); + T max = Max(); + UNIT_ASSERT_EQUAL(lim::max(), max); + if (unknownSign) { CHECK_COND(ValidSignInfo(lim::is_signed, T())); } diff --git a/util/memory/blob.cpp b/util/memory/blob.cpp index 91da5cadca..879522ed47 100644 --- a/util/memory/blob.cpp +++ b/util/memory/blob.cpp @@ -363,7 +363,7 @@ static inline TBlob ConstructFromBuffer(TBuffer& in) { template <class TCounter> static inline TBlob ConstructFromStream(IInputStream& in) { - TBuffer buf; + TBuffer buf; { TBufferOutput out(buf); @@ -375,11 +375,11 @@ static inline TBlob ConstructFromStream(IInputStream& in) { } TBlob TBlob::FromStreamSingleThreaded(IInputStream& in) { - return ConstructFromStream<TSimpleCounter>(in); + return ConstructFromStream<TSimpleCounter>(in); } TBlob TBlob::FromStream(IInputStream& in) { - return ConstructFromStream<TAtomicCounter>(in); + return ConstructFromStream<TAtomicCounter>(in); } TBlob TBlob::FromBufferSingleThreaded(TBuffer& in) { diff --git a/util/string/cast.h b/util/string/cast.h index 90e925c194..f1e2f06abb 100644 --- a/util/string/cast.h +++ b/util/string/cast.h @@ -180,41 +180,41 @@ inline T FromString(const TUtf16String& s) { return ::FromString<T, wchar16>(s.data(), s.size()); } -namespace NPrivate { - template <typename TChar> - class TFromString { - const TChar* const Data; - const size_t Len; - - public: - inline TFromString(const TChar* data, size_t len) - : Data(data) - , Len(len) - { - } - - template <typename T> - inline operator T() const { - return FromString<T, TChar>(Data, Len); - } - }; -} - -template <typename TChar> -inline ::NPrivate::TFromString<TChar> FromString(const TChar* data, size_t len) { - return ::NPrivate::TFromString<TChar>(data, len); -} - -template <typename TChar> -inline ::NPrivate::TFromString<TChar> FromString(const TChar* data) { +namespace NPrivate { + template <typename TChar> + class TFromString { + const TChar* const Data; + const size_t Len; + + public: + inline TFromString(const TChar* data, size_t len) + : Data(data) + , Len(len) + { + } + + template <typename T> + inline operator T() const { + return FromString<T, TChar>(Data, Len); + } + }; +} + +template <typename TChar> +inline ::NPrivate::TFromString<TChar> FromString(const TChar* data, size_t len) { + return ::NPrivate::TFromString<TChar>(data, len); +} + +template <typename TChar> +inline ::NPrivate::TFromString<TChar> FromString(const TChar* data) { return ::NPrivate::TFromString<TChar>(data, std::char_traits<TChar>::length(data)); -} - -template <typename T> -inline ::NPrivate::TFromString<typename T::TChar> FromString(const T& s) { +} + +template <typename T> +inline ::NPrivate::TFromString<typename T::TChar> FromString(const T& s) { return ::NPrivate::TFromString<typename T::TChar>(s.data(), s.size()); -} - +} + // Conversion exception free versions template <typename T, typename TChar> bool TryFromStringImpl(const TChar* data, size_t len, T& result); diff --git a/util/string/cast_ut.cpp b/util/string/cast_ut.cpp index 033450c38c..949f09486b 100644 --- a/util/string/cast_ut.cpp +++ b/util/string/cast_ut.cpp @@ -4,7 +4,7 @@ #include <util/charset/wide.h> #include <util/system/defaults.h> - + #include <limits> // positive test (return true or no exception) @@ -319,7 +319,7 @@ Y_UNIT_TEST_SUITE(TCastTest) { Y_UNIT_TEST(TestLiteral) { UNIT_ASSERT_VALUES_EQUAL(ToString("abc"), TString("abc")); } - + Y_UNIT_TEST(TestFromStringStringBuf) { TString a = "xyz"; TStringBuf b = FromString<TStringBuf>(a); |