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