From 0130dfac4139989c4860a7159573c03ed345d11a Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Wed, 9 Mar 2011 09:32:03 +0000 Subject: [PATCH] First attempt at solving signed/ unsigned issue with int literals --- internal/catch_unsigned.hpp | 105 ++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 internal/catch_unsigned.hpp diff --git a/internal/catch_unsigned.hpp b/internal/catch_unsigned.hpp new file mode 100644 index 00000000..38989bef --- /dev/null +++ b/internal/catch_unsigned.hpp @@ -0,0 +1,105 @@ +/* + * catch_unsigned.hpp + * Catch + * + * Created by Phil on 04/03/2011. + * Copyright 2011 Two Blue Cubes Ltd. All rights reserved. + * + * Distributed under the Boost Software License, Version 1.0. (See accompanying + * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + * + */ + +#ifndef TWOBLUECUBES_CATCH_UNSIGNED_HPP_INCLUDED +#define TWOBLUECUBES_CATCH_UNSIGNED_HPP_INCLUDED + +#include + +namespace Catch +{ + template + struct SignTraits{}; + + template<> + struct SignTraits + { + typedef int SignedType; + typedef unsigned int UnsignedType; + }; + template<> + struct SignTraits : SignTraits{}; + + template<> + struct SignTraits + { + typedef long SignedType; + typedef unsigned long UnsignedType; + }; + template<> + struct SignTraits : SignTraits{}; + + template<> + struct SignTraits + { + typedef char SignedType; + typedef unsigned char UnsignedType; + }; + template<> + struct SignTraits : SignTraits{}; + + template + struct IsType + { + enum{ result = false }; + }; + + template + struct IsType + { + enum{ result = true }; + }; + + template + struct MatchedSigns + { + static const T1& castLhs( const T1& lhs ) + { + return lhs; + } + static const T2& castRhs( const T2& rhs ) + { + return rhs; + } + }; + + template + struct MatchedSigns + { + typedef typename SignTraits::SignedType Type1; + typedef typename SignTraits::SignedType Type2; + + static Type1 castLhs( T1 lhs ) + { + return static_cast( lhs ); + } + static Type2 castRhs( T2 rhs ) + { + return static_cast( rhs ); + } + }; + + template + struct MatchSign + : MatchedSigns< T1, T2, + ( !IsType::result && + !IsType::result && + !IsType::result && + !IsType::result ) || + !std::numeric_limits::is_integer || + !std::numeric_limits::is_integer || + std::numeric_limits::is_signed == std::numeric_limits::is_signed > + { + }; +} + +#endif // TWOBLUECUBES_CATCH_UNSIGNED_HPP_INCLUDED