From 9f754b788b872f9768af8c3a4f9e001a588e011a Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Sun, 29 Aug 2021 13:06:40 +0300 Subject: [PATCH] Use integer types from --- source/core/inttypes.h | 72 +++--------------- source/core/typelist.h | 130 --------------------------------- source/fs/unix/filemonitor.cpp | 1 + source/strings/lexicalcast.cpp | 2 +- 4 files changed, 13 insertions(+), 192 deletions(-) delete mode 100644 source/core/typelist.h diff --git a/source/core/inttypes.h b/source/core/inttypes.h index c0af5ca..68b870c 100644 --- a/source/core/inttypes.h +++ b/source/core/inttypes.h @@ -1,70 +1,20 @@ #ifndef MSP_CORE_INTTYPES_H_ #define MSP_CORE_INTTYPES_H_ -#include -#include "typelist.h" +#include namespace Msp { -// Define lists of standard types, both signed and unsigned variants -typedef TypeList::Type StandardSignedTypes; -typedef TypeList::Type StandardUnsignedTypes; - -// Then add possible nonstandard types -#if defined(__GNUC__) -#if (__GNUC__>4 || (__GNUC__==4 && __GNUC_MINOR__>=6)) && defined(__LP64__) -#pragma GCC diagnostic push -#if __GNUC__>=5 -#pragma GCC diagnostic ignored "-Wpedantic" -#else -#pragma GCC diagnostic ignored "-pedantic" -#endif -typedef TypeList::Type PlatformSignedTypes; -typedef TypeList::Type PlatformUnsignedTypes; -#pragma GCC diagnostic pop -#else -typedef TypeList::Type PlatformSignedTypes; -typedef TypeList::Type PlatformUnsignedTypes; -#endif -#elif defined(_MSC_VER) -typedef TypeList::Type PlatformSignedTypes; -typedef TypeList::Type PlatformUnsignedTypes; -#else -typedef StandardSignedTypes PlatformSignedTypes; -typedef StandardUnsignedTypes PlatformUnsignedTypes; -#endif - -/** A helper for choosing an integer type of a specific size. The size -parameter is in bits. The resulting types can be obtained from the SignedType -and UnsignedType typedefs. */ -template -struct Int -{ - template - struct Predicate - { - enum { value = (sizeof(T)*CHAR_BIT==size) }; - }; - - typedef typename TypeChooser::Type SignedType; - typedef typename TypeChooser::Type UnsignedType; -}; - -/** A helper for choosing an integer that's the same size as another type. */ -template -struct MatchingInt: Int -{ }; - -// Finally define convenient shorthands for the actual integer types -typedef Int<8>::SignedType Int8; -typedef Int<8>::UnsignedType UInt8; -typedef Int<16>::SignedType Int16; -typedef Int<16>::UnsignedType UInt16; -typedef Int<32>::SignedType Int32; -typedef Int<32>::UnsignedType UInt32; -typedef Int<64>::SignedType Int64; -typedef Int<64>::UnsignedType UInt64; -typedef MatchingInt::UnsignedType IntPtr; +// These typedefs will be deprecated at some point +typedef std::int8_t Int8; +typedef std::uint8_t UInt8; +typedef std::int16_t Int16; +typedef std::uint16_t UInt16; +typedef std::int32_t Int32; +typedef std::uint32_t UInt32; +typedef std::int64_t Int64; +typedef std::uint64_t UInt64; +typedef std::intptr_t IntPtr; } // namespace Msp diff --git a/source/core/typelist.h b/source/core/typelist.h deleted file mode 100644 index ecc28fa..0000000 --- a/source/core/typelist.h +++ /dev/null @@ -1,130 +0,0 @@ -#ifndef MSP_CORE_TYPELIST_H_ -#define MSP_CORE_TYPELIST_H_ - -namespace Msp { - -/** Sentinel type for type lists */ -struct NullType { }; - - -/** A "cons cell" for types. Composed of a head and a tail. To construct -longer lists, use another TypeCons as the tail. The tail of the last TypeCons -should by NullType. */ -template -struct TypeCons -{ - typedef H Head; - typedef T Tail; -}; - - -/** Basic terminated type list of one element. */ -template -struct TypeList1 -{ - typedef TypeCons Type; -}; - -/** Specialization to avoid creating a TypeCons with two NullTypes. */ -template<> -struct TypeList1 -{ - typedef NullType Type; -}; - -/** Specialization to avoid creating a TypeCons with another TypeCons as its -head. */ -template -struct TypeList1 > -{ - typedef TypeCons Type; -}; - -/** Basic terminated type list of two elements. */ -template -struct TypeList2 -{ - typedef TypeCons::Type> Type; -}; - -/** Specialization to ignore an initial NullType. */ -template -struct TypeList2 -{ - typedef typename TypeList1::Type Type; -}; - -/** Specialization to flatten an initial TypeCons. */ -template -struct TypeList2, T3> -{ - typedef typename TypeList2::Type>::Type Type; -}; - - -/** A terminated type list of five elements. Use the typedef Type inside to -obtain the actual list type. If any of the types is a type list itself, the -entire structure is flattened to a single list. */ -template -struct TypeList -{ - typedef typename TypeList::Type>::Type Type; -}; - -/** Specialization of TypeList for one element. */ -template -struct TypeList -{ - typedef typename TypeList1::Type Type; -}; - -/** Specialization of TypeList for two elements. */ -template -struct TypeList -{ - typedef typename TypeList2::Type Type; -}; - -/** Specialization of TypeList for three elements. */ -template -struct TypeList -{ - typedef typename TypeList::Type>::Type Type; -}; - -/** Specialization of TypeList for four elements. */ -template -struct TypeList -{ - typedef typename TypeList::Type>::Type Type; -}; - - -/** A helper for selecting a type from a list based on a predicate. The -predicate should be a template taking a single type argument and defining a -compile-time constant with the name "value", which evaluates to true if the -type is considered a match. The result can be obtained from the member -typedef Type. If the list contains no matching type, an ugly and confusing -compiler error will result. */ -template class P, bool f = P::value> -struct TypeChooser; - -/** Specialization for a matching type. Picks the head of the list as the -result. */ -template class P> -struct TypeChooser -{ - typedef typename L::Head Type; -}; - -/** Specialization for a non-matchin type. Recursively inspects the tail of -the list. */ -template class P> -struct TypeChooser -{ - typedef typename TypeChooser::Type Type; -}; - -} // namespace Msp - -#endif diff --git a/source/fs/unix/filemonitor.cpp b/source/fs/unix/filemonitor.cpp index 68cd7ae..e2ca3b7 100644 --- a/source/fs/unix/filemonitor.cpp +++ b/source/fs/unix/filemonitor.cpp @@ -1,4 +1,5 @@ #include +#include #include #include #include "filemonitor.h" diff --git a/source/strings/lexicalcast.cpp b/source/strings/lexicalcast.cpp index 8789544..f5b3a95 100644 --- a/source/strings/lexicalcast.cpp +++ b/source/strings/lexicalcast.cpp @@ -59,7 +59,7 @@ char *int_to_str(T v, const Fmt &f, char *end) const char *digits = (f.get_uppercase() ? udigits : ldigits); if(v) { - typename MatchingInt::UnsignedType w = Absolute::eval(v); + typename std::make_unsigned::type w = Absolute::eval(v); while(w) { *--ptr = digits[w%base]; -- 2.43.0