Building Fix for a negative value check for gcc < 4.8

This commit is contained in:
Markus Gans 2018-10-26 07:43:23 +02:00
parent c4e333bc8b
commit 96edb762c7
12 changed files with 46 additions and 17 deletions

View File

@ -1,3 +1,6 @@
2018-10-26 Markus Gans <guru.mail@muenster.de>
* Building Fix for a negative value check (gcc < 4.8)
2018-10-21 Markus Gans <guru.mail@muenster.de>
* Moving static attributes from FApplication to FWidget

View File

@ -1192,7 +1192,7 @@ bool FString::operator > (const FString& s) const
//----------------------------------------------------------------------
const FString& FString::insert (const FString& s, int pos)
{
if ( pos < 0 || uInt(pos) > length )
if ( isNegative(pos) || uInt(pos) > length )
throw std::out_of_range("");
_insert (uInt(pos), s.length, s.string);

View File

@ -49,6 +49,7 @@
#include <cwchar>
#include <cwctype>
#include <limits>
#include <iostream>
#include <new>
#include <stdexcept>
@ -134,9 +135,9 @@ class FString
const FString& operator >> (float&);
template <typename IndexT>
wchar_t& operator [] (IndexT);
wchar_t& operator [] (const IndexT);
template <typename IndexT>
const wchar_t& operator [] (IndexT) const;
const wchar_t& operator [] (const IndexT) const;
const FString& operator () ();
bool operator < (const FString&) const;
@ -289,9 +290,9 @@ inline const char* FString::getClassName()
//----------------------------------------------------------------------
template <typename IndexT>
inline wchar_t& FString::operator [] (IndexT pos)
inline wchar_t& FString::operator [] (const IndexT pos)
{
if ( pos < 0 || pos >= IndexT(length) )
if ( isNegative(pos) || pos >= IndexT(length) )
throw std::out_of_range(""); // Invalid index position
return string[std::size_t(pos)];
@ -299,9 +300,9 @@ inline wchar_t& FString::operator [] (IndexT pos)
//----------------------------------------------------------------------
template <typename IndexT>
inline const wchar_t& FString::operator [] (IndexT pos) const
inline const wchar_t& FString::operator [] (const IndexT pos) const
{
if ( pos < 0 || pos >= IndexT(length) )
if ( isNegative(pos) || pos >= IndexT(length) )
throw std::out_of_range(""); // Invalid index position
return string[std::size_t(pos)];

View File

@ -30,6 +30,7 @@
#include <stdint.h>
#include <sys/types.h>
#include <limits>
#include <string>
#define null NULL
@ -60,6 +61,30 @@ typedef long double lDouble;
namespace finalcut
{
template <typename T, bool is_signed>
struct is_negative
{
inline bool operator () (const T& x)
{
return x < 0;
}
};
template <typename T>
struct is_negative<T,false>
{
inline bool operator () (const T&)
{
return false;
}
};
template <typename T>
inline bool isNegative (const T& x)
{
return is_negative<T, std::numeric_limits<T>::is_signed>()(x);
}
namespace fc
{
#pragma pack(push)