From 9ae717c43375e48db0b2d354c02c5b8cac75ebc8 Mon Sep 17 00:00:00 2001 From: Brad Chase Date: Thu, 18 May 2017 13:05:58 -0400 Subject: [PATCH] Move tagged_integer to ripple/basics --- Builds/VisualStudio2015/RippleD.vcxproj | 12 +- .../VisualStudio2015/RippleD.vcxproj.filters | 12 +- src/ripple/basics/tagged_integer.h | 223 ++++++++++++++++ src/ripple/beast/utility/tagged_integer.h | 243 ------------------ src/ripple/core/Job.h | 1 + src/test/basics/tagged_integer_test.cpp | 239 +++++++++++++++++ src/test/beast/beast_tagged_integer_test.cpp | 154 ----------- src/test/unity/basics_test_unity.cpp | 1 + src/test/unity/beast_test_unity2.cpp | 1 - 9 files changed, 476 insertions(+), 410 deletions(-) create mode 100644 src/ripple/basics/tagged_integer.h delete mode 100644 src/ripple/beast/utility/tagged_integer.h create mode 100644 src/test/basics/tagged_integer_test.cpp delete mode 100644 src/test/beast/beast_tagged_integer_test.cpp diff --git a/Builds/VisualStudio2015/RippleD.vcxproj b/Builds/VisualStudio2015/RippleD.vcxproj index 0ad8cb7dd26..d73f5dc2c35 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj +++ b/Builds/VisualStudio2015/RippleD.vcxproj @@ -1529,6 +1529,8 @@ + + @@ -1827,8 +1829,6 @@ True True - - @@ -4403,6 +4403,10 @@ True True + + True + True + True True @@ -4435,10 +4439,6 @@ True True - - True - True - True True diff --git a/Builds/VisualStudio2015/RippleD.vcxproj.filters b/Builds/VisualStudio2015/RippleD.vcxproj.filters index c5f03a53597..326781e37c7 100644 --- a/Builds/VisualStudio2015/RippleD.vcxproj.filters +++ b/Builds/VisualStudio2015/RippleD.vcxproj.filters @@ -2085,6 +2085,9 @@ ripple\basics + + ripple\basics + ripple\basics @@ -2463,9 +2466,6 @@ ripple\beast\utility\src - - ripple\beast\utility - ripple\beast\utility @@ -5184,6 +5184,9 @@ test\basics + + test\basics + test\beast @@ -5208,9 +5211,6 @@ test\beast - - test\beast - test\beast diff --git a/src/ripple/basics/tagged_integer.h b/src/ripple/basics/tagged_integer.h new file mode 100644 index 00000000000..b713ecc491c --- /dev/null +++ b/src/ripple/basics/tagged_integer.h @@ -0,0 +1,223 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright 2014, Nikolaos D. Bougalis + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#ifndef BEAST_UTILITY_TAGGED_INTEGER_H_INCLUDED +#define BEAST_UTILITY_TAGGED_INTEGER_H_INCLUDED + +#include +#include +#include +#include +#include +#include + +namespace ripple { + +/** A type-safe wrap around standard integral types + + The tag is used to implement type safety, catching mismatched types at + compile time. Multiple instantiations wrapping the same underlying integral + type are distinct types (distinguished by tag) and will not interoperate. A + tagged_integer supports all the usual assignment, arithmetic, comparison and + shifting operations defined for the underlying type + + The tag is not meant as a unit, which would require restricting the set of + allowed arithmetic operations. +*/ +template +class tagged_integer : boost::operators> + , boost::shiftable> +{ +private: + Int m_value; + +public: + using value_type = Int; + using tag_type = Tag; + + tagged_integer() = default; + + template < + class OtherInt, + class = typename std::enable_if< + std::is_integral::value && + sizeof(OtherInt) <= sizeof(Int)>::type> + explicit + /* constexpr */ + tagged_integer(OtherInt value) noexcept + : m_value(value) + { + } + + bool + operator<(const tagged_integer & rhs) const noexcept + { + return m_value < rhs.m_value; + } + + bool + operator==(const tagged_integer & rhs) const noexcept + { + return m_value == rhs.m_value; + } + + tagged_integer& + operator+=(tagged_integer const& rhs) noexcept + { + m_value += rhs.m_value; + return *this; + } + + tagged_integer& + operator-=(tagged_integer const& rhs) noexcept + { + m_value -= rhs.m_value; + return *this; + } + + tagged_integer& + operator*=(tagged_integer const& rhs) noexcept + { + m_value *= rhs.m_value; + return *this; + } + + tagged_integer& + operator/=(tagged_integer const& rhs) noexcept + { + m_value /= rhs.m_value; + return *this; + } + + tagged_integer& + operator%=(tagged_integer const& rhs) noexcept + { + m_value %= rhs.m_value; + return *this; + } + + tagged_integer& + operator|=(tagged_integer const& rhs) noexcept + { + m_value |= rhs.m_value; + return *this; + } + + tagged_integer& + operator&=(tagged_integer const& rhs) noexcept + { + m_value &= rhs.m_value; + return *this; + } + + tagged_integer& + operator^=(tagged_integer const& rhs) noexcept + { + m_value ^= rhs.m_value; + return *this; + } + + tagged_integer& + operator<<=(const tagged_integer& rhs) noexcept + { + m_value <<= rhs.m_value; + return *this; + } + + tagged_integer& + operator>>=(const tagged_integer& rhs) noexcept + { + m_value >>= rhs.m_value; + return *this; + } + + tagged_integer + operator~() const noexcept + { + return tagged_integer{~m_value}; + } + + tagged_integer + operator+() const noexcept + { + return *this; + } + + tagged_integer + operator-() const noexcept + { + return tagged_integer{-m_value}; + } + + tagged_integer& + operator++ () noexcept + { + ++m_value; + return *this; + } + + tagged_integer& + operator-- () noexcept + { + --m_value; + return *this; + } + + explicit + operator Int() const noexcept + { + return m_value; + } + + friend + std::ostream& + operator<< (std::ostream& s, tagged_integer const& t) + { + s << t.m_value; + return s; + } + + friend + std::istream& + operator>> (std::istream& s, tagged_integer& t) + { + s >> t.m_value; + return s; + } + + friend + std::string + to_string(tagged_integer const& t) + { + return std::to_string(t.m_value); + } +}; + +} // ripple + +namespace beast { +template +struct is_contiguously_hashable, HashAlgorithm> + : public is_contiguously_hashable +{ +}; + +} // beast +#endif + diff --git a/src/ripple/beast/utility/tagged_integer.h b/src/ripple/beast/utility/tagged_integer.h deleted file mode 100644 index 01e95e53750..00000000000 --- a/src/ripple/beast/utility/tagged_integer.h +++ /dev/null @@ -1,243 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2014, Nikolaos D. Bougalis - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#ifndef BEAST_UTILITY_TAGGED_INTEGER_H_INCLUDED -#define BEAST_UTILITY_TAGGED_INTEGER_H_INCLUDED - -#include - -#include -#include -#include -#include - -namespace beast { - -/** A type-safe wrap around standard unsigned integral types - - The tag is used to implement type safety, catching mismatched types at - compile time. Multiple instantiations wrapping the same underlying integral - type are distinct types (distinguished by tag) and will not interoperate. - - A tagged_integer supports all the comparison operators that are available - for the underlying integral type. It only supports a subset of arithmetic - operators, restricting mutation to only safe and meaningful types. -*/ -template -class tagged_integer -{ -private: - static_assert (std::is_unsigned ::value, - "The specified Int type must be unsigned"); - - Int m_value; - -public: - using value_type = Int; - using tag_type = Tag; - - tagged_integer() = default; - - template < - class OtherInt, - class = typename std::enable_if < - std::is_integral ::value && - sizeof (OtherInt) <= sizeof (Int) - >::type - > - explicit - /* constexpr */ - tagged_integer (OtherInt value) noexcept - : m_value (value) - { - } - - // Arithmetic operators - tagged_integer& - operator++ () noexcept - { - ++m_value; - return *this; - } - - tagged_integer - operator++ (int) noexcept - { - tagged_integer orig (*this); - ++(*this); - return orig; - } - - tagged_integer& - operator-- () noexcept - { - --m_value; - return *this; - } - - tagged_integer - operator-- (int) noexcept - { - tagged_integer orig (*this); - --(*this); - return orig; - } - - template - typename std::enable_if < - std::is_integral ::value && - sizeof (OtherInt) <= sizeof (Int), - tagged_integer >::type& - operator+= (OtherInt rhs) noexcept - { - m_value += rhs; - return *this; - } - - template - typename std::enable_if < - std::is_integral ::value && - sizeof (OtherInt) <= sizeof (Int), - tagged_integer >::type& - operator-= (OtherInt rhs) noexcept - { - m_value -= rhs; - return *this; - } - - template - friend - typename std::enable_if < - std::is_integral ::value && - sizeof (OtherInt) <= sizeof (Int), - tagged_integer >::type - operator+ (tagged_integer const& lhs, - OtherInt rhs) noexcept - { - return tagged_integer (lhs.m_value + rhs); - } - - template - friend - typename std::enable_if < - std::is_integral ::value && - sizeof (OtherInt) <= sizeof (Int), - tagged_integer >::type - operator+ (OtherInt lhs, - tagged_integer const& rhs) noexcept - { - return tagged_integer (lhs + rhs.m_value); - } - - template - friend - typename std::enable_if < - std::is_integral ::value && - sizeof (OtherInt) <= sizeof (Int), - tagged_integer >::type - operator- (tagged_integer const& lhs, - OtherInt rhs) noexcept - { - return tagged_integer (lhs.m_value - rhs); - } - - friend - Int - operator- (tagged_integer const& lhs, - tagged_integer const& rhs) noexcept - { - return lhs.m_value - rhs.m_value; - } - - // Comparison operators - friend - bool - operator== (tagged_integer const& lhs, - tagged_integer const& rhs) noexcept - { - return lhs.m_value == rhs.m_value; - } - - friend - bool - operator!= (tagged_integer const& lhs, - tagged_integer const& rhs) noexcept - { - return lhs.m_value != rhs.m_value; - } - - friend - bool - operator< (tagged_integer const& lhs, - tagged_integer const& rhs) noexcept - { - return lhs.m_value < rhs.m_value; - } - - friend - bool - operator<= (tagged_integer const& lhs, - tagged_integer const& rhs) noexcept - { - return lhs.m_value <= rhs.m_value; - } - - friend - bool - operator> (tagged_integer const& lhs, - tagged_integer const& rhs) noexcept - { - return lhs.m_value > rhs.m_value; - } - - friend - bool - operator>= (tagged_integer const& lhs, - tagged_integer const& rhs) noexcept - { - return lhs.m_value >= rhs.m_value; - } - - friend - std::ostream& - operator<< (std::ostream& s, tagged_integer const& t) - { - s << t.m_value; - return s; - } - - friend - std::istream& - operator>> (std::istream& s, tagged_integer& t) - { - s >> t.m_value; - return s; - } -}; - -template -struct is_contiguously_hashable, HashAlgorithm> - : public is_contiguously_hashable -{ -}; - -} - -#endif - diff --git a/src/ripple/core/Job.h b/src/ripple/core/Job.h index 93850817022..c06e463ec1f 100644 --- a/src/ripple/core/Job.h +++ b/src/ripple/core/Job.h @@ -21,6 +21,7 @@ #define RIPPLE_CORE_JOB_H_INCLUDED #include +#include #include diff --git a/src/test/basics/tagged_integer_test.cpp b/src/test/basics/tagged_integer_test.cpp new file mode 100644 index 00000000000..1a86b45ba10 --- /dev/null +++ b/src/test/basics/tagged_integer_test.cpp @@ -0,0 +1,239 @@ +//------------------------------------------------------------------------------ +/* + This file is part of rippled: https://github.com/ripple/rippled + Copyright 2014, Nikolaos D. Bougalis + + + Permission to use, copy, modify, and/or distribute this software for any + purpose with or without fee is hereby granted, provided that the above + copyright notice and this permission notice appear in all copies. + + THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. +*/ +//============================================================================== + +#include +#include +#include +#include + +namespace ripple { +namespace test { + +class tagged_integer_test + : public beast::unit_test::suite +{ +private: + struct Tag1 { }; + struct Tag2 { }; + + // Static checks that types are not interoperable + + using TagUInt1 = tagged_integer ; + using TagUInt2 = tagged_integer ; + using TagUInt3 = tagged_integer ; + + // Check construction of tagged_integers + static_assert (std::is_constructible::value, + "TagUInt1 should be constructible using a std::uint32_t"); + + static_assert (!std::is_constructible::value, + "TagUInt1 should not be constructible using a std::uint64_t"); + + static_assert (std::is_constructible::value, + "TagUInt3 should be constructible using a std::uint32_t"); + + static_assert (std::is_constructible::value, + "TagUInt3 should be constructible using a std::uint64_t"); + + // Check assignment of tagged_integers + static_assert (!std::is_assignable::value, + "TagUInt1 should not be assignable with a std::uint32_t"); + + static_assert (!std::is_assignable::value, + "TagUInt1 should not be assignable with a std::uint64_t"); + + static_assert (!std::is_assignable::value, + "TagUInt3 should not be assignable with a std::uint32_t"); + + static_assert (!std::is_assignable::value, + "TagUInt3 should not be assignable with a std::uint64_t"); + + static_assert (std::is_assignable::value, + "TagUInt1 should be assignable with a TagUInt1"); + + static_assert (!std::is_assignable::value, + "TagUInt1 should not be assignable with a TagUInt2"); + + static_assert (std::is_assignable::value, + "TagUInt3 should be assignable with a TagUInt1"); + + static_assert (!std::is_assignable::value, + "TagUInt1 should not be assignable with a TagUInt3"); + + static_assert (!std::is_assignable::value, + "TagUInt3 should not be assignable with a TagUInt1"); + + // Check convertibility of tagged_integers + static_assert (!std::is_convertible::value, + "std::uint32_t should not be convertible to a TagUInt1"); + + static_assert (!std::is_convertible::value, + "std::uint32_t should not be convertible to a TagUInt3"); + + static_assert (!std::is_convertible::value, + "std::uint64_t should not be convertible to a TagUInt3"); + + static_assert (!std::is_convertible::value, + "std::uint64_t should not be convertible to a TagUInt2"); + + static_assert (!std::is_convertible::value, + "TagUInt1 should not be convertible to TagUInt2"); + + static_assert (!std::is_convertible::value, + "TagUInt1 should not be convertible to TagUInt3"); + + static_assert (!std::is_convertible::value, + "TagUInt2 should not be convertible to a TagUInt3"); + + +public: + void run () + { + using TagInt = tagged_integer; + + { + testcase ("Comparison Operators"); + + TagInt const zero(0); + TagInt const one(1); + + BEAST_EXPECT(one == one); + BEAST_EXPECT(!(one == zero)); + + BEAST_EXPECT(one != zero); + BEAST_EXPECT(!(one != one)); + + BEAST_EXPECT(zero < one); + BEAST_EXPECT(!(one < zero)); + + BEAST_EXPECT(one > zero); + BEAST_EXPECT(!(zero > one)); + + BEAST_EXPECT(one >= one); + BEAST_EXPECT(one >= zero); + BEAST_EXPECT(!(zero >= one)); + + BEAST_EXPECT(zero <= one); + BEAST_EXPECT(zero <= zero); + BEAST_EXPECT(!(one <= zero)); + } + + { + testcase ("Increment/Decrement Operators"); + TagInt const zero(0); + TagInt const one(1); + TagInt a{0}; + ++a; + BEAST_EXPECT(a == one); + --a; + BEAST_EXPECT(a == zero); + a++; + BEAST_EXPECT(a == one); + a--; + BEAST_EXPECT(a == zero); + } + + + { + testcase ("Arithmetic Operators"); + TagInt a{-2}; + BEAST_EXPECT(+a == TagInt{-2}); + BEAST_EXPECT(-a == TagInt{2}); + BEAST_EXPECT(TagInt{-3} + TagInt{4} == TagInt{1}); + BEAST_EXPECT(TagInt{-3} - TagInt{4} == TagInt{-7}); + BEAST_EXPECT(TagInt{-3} * TagInt{4} == TagInt{-12}); + BEAST_EXPECT(TagInt{8}/TagInt{4} == TagInt{2}); + BEAST_EXPECT(TagInt{7} %TagInt{4} == TagInt{3}); + + BEAST_EXPECT(~TagInt{8} == TagInt{~TagInt::value_type{8}}); + BEAST_EXPECT((TagInt{6} & TagInt{3}) == TagInt{2}); + BEAST_EXPECT((TagInt{6} | TagInt{3}) == TagInt{7}); + BEAST_EXPECT((TagInt{6} ^ TagInt{3}) == TagInt{5}); + + BEAST_EXPECT((TagInt{4} << TagInt{2}) == TagInt{16}); + BEAST_EXPECT((TagInt{16} >> TagInt{2}) == TagInt{4}); + } + { + testcase ("Assignment Operators"); + TagInt a{-2}; + TagInt b{0}; + b = a; + BEAST_EXPECT(b == TagInt{-2}); + + // -3 + 4 == 1 + a = TagInt{-3}; + a += TagInt{4}; + BEAST_EXPECT(a == TagInt{1}); + + // -3 - 4 == -7 + a = TagInt{-3}; + a -= TagInt{4}; + BEAST_EXPECT(a == TagInt{-7}); + + // -3 * 4 == -12 + a = TagInt{-3}; + a *= TagInt{4}; + BEAST_EXPECT(a == TagInt{-12}); + + // 8/4 == 2 + a = TagInt{8}; + a /= TagInt{4}; + BEAST_EXPECT(a == TagInt{2}); + + // 7 % 4 == 3 + a = TagInt{7}; + a %= TagInt{4}; + BEAST_EXPECT(a == TagInt{3}); + + // 6 & 3 == 2 + a = TagInt{6}; + a /= TagInt{3}; + BEAST_EXPECT(a == TagInt{2}); + + // 6 | 3 == 7 + a = TagInt{6}; + a |= TagInt{3}; + BEAST_EXPECT(a == TagInt{7}); + + // 6 ^ 3 == 5 + a = TagInt{6}; + a ^= TagInt{3}; + BEAST_EXPECT(a == TagInt{5}); + + // 4 << 2 == 16 + a = TagInt{4}; + a <<= TagInt{2}; + BEAST_EXPECT(a == TagInt{16}); + + // 16 >> 2 == 4 + a = TagInt{16}; + a >>= TagInt{2}; + BEAST_EXPECT(a == TagInt{4}); + } + + + + } +}; + +BEAST_DEFINE_TESTSUITE(tagged_integer,ripple_basics,ripple); + +} // test +} // ripple diff --git a/src/test/beast/beast_tagged_integer_test.cpp b/src/test/beast/beast_tagged_integer_test.cpp deleted file mode 100644 index 29c103dc2cf..00000000000 --- a/src/test/beast/beast_tagged_integer_test.cpp +++ /dev/null @@ -1,154 +0,0 @@ -//------------------------------------------------------------------------------ -/* - This file is part of Beast: https://github.com/vinniefalco/Beast - Copyright 2014, Nikolaos D. Bougalis - - Permission to use, copy, modify, and/or distribute this software for any - purpose with or without fee is hereby granted, provided that the above - copyright notice and this permission notice appear in all copies. - - THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -*/ -//============================================================================== - -#if BEAST_INCLUDE_BEASTCONFIG -#include -#endif - -#include - -#include -#include - -namespace beast { - -class tagged_integer_test - : public unit_test::suite -{ -private: - struct Tag1 { }; - struct Tag2 { }; - - using TagInt1 = tagged_integer ; - using TagInt2 = tagged_integer ; - using TagInt3 = tagged_integer ; - - // Check construction of tagged_integers - static_assert (std::is_constructible::value, - "TagInt1 should be constructible using a std::uint32_t"); - - static_assert (!std::is_constructible::value, - "TagInt1 should not be constructible using a std::uint64_t"); - - static_assert (std::is_constructible::value, - "TagInt3 should be constructible using a std::uint32_t"); - - static_assert (std::is_constructible::value, - "TagInt3 should be constructible using a std::uint64_t"); - - // Check assignment of tagged_integers - static_assert (!std::is_assignable::value, - "TagInt1 should not be assignable with a std::uint32_t"); - - static_assert (!std::is_assignable::value, - "TagInt1 should not be assignable with a std::uint64_t"); - - static_assert (!std::is_assignable::value, - "TagInt3 should not be assignable with a std::uint32_t"); - - static_assert (!std::is_assignable::value, - "TagInt3 should not be assignable with a std::uint64_t"); - - static_assert (std::is_assignable::value, - "TagInt1 should be assignable with a TagInt1"); - - static_assert (!std::is_assignable::value, - "TagInt1 should not be assignable with a TagInt2"); - - static_assert (std::is_assignable::value, - "TagInt3 should be assignable with a TagInt1"); - - static_assert (!std::is_assignable::value, - "TagInt1 should not be assignable with a TagInt3"); - - static_assert (!std::is_assignable::value, - "TagInt3 should not be assignable with a TagInt1"); - - // Check convertibility of tagged_integers - static_assert (!std::is_convertible::value, - "std::uint32_t should not be convertible to a TagInt1"); - - static_assert (!std::is_convertible::value, - "std::uint32_t should not be convertible to a TagInt3"); - - static_assert (!std::is_convertible::value, - "std::uint64_t should not be convertible to a TagInt3"); - - static_assert (!std::is_convertible::value, - "std::uint64_t should not be convertible to a TagInt2"); - - static_assert (!std::is_convertible::value, - "TagInt1 should not be convertible to TagInt2"); - - static_assert (!std::is_convertible::value, - "TagInt1 should not be convertible to TagInt3"); - - static_assert (!std::is_convertible::value, - "TagInt2 should not be convertible to a TagInt3"); - -public: - void run () - { - TagInt1 const zero (0); - TagInt1 const one (1); - - testcase ("Comparison Operators"); - - expect (zero >= zero, "Should be greater than or equal"); - expect (zero == zero, "Should be equal"); - - expect (one > zero, "Should be greater"); - expect (one >= zero, "Should be greater than or equal"); - expect (one != zero, "Should not be equal"); - - unexpected (one < zero, "Should be greater"); - unexpected (one <= zero, "Should not be greater than or equal"); - unexpected (one == zero, "Should not be equal"); - - testcase ("Arithmetic Operators"); - - TagInt1 tmp; - - tmp = zero + 0u; - expect (tmp == zero, "Should be equal"); - - tmp = 1u + zero; - expect (tmp == one, "Should be equal"); - - expect(--tmp == zero, "Should be equal"); - expect(tmp++ == zero, "Should be equal"); - expect(tmp == one, "Should be equal"); - - expect(tmp-- == one, "Should be equal"); - expect(tmp == zero, "Should be equal"); - expect(++tmp == one, "Should be equal"); - - tmp = zero; - - tmp += 1u; - expect(tmp == one, "Should be equal"); - - tmp -= 1u; - expect(tmp == zero, "Should be equal"); - } -}; - -BEAST_DEFINE_TESTSUITE(tagged_integer,utility,beast); - -} // beast diff --git a/src/test/unity/basics_test_unity.cpp b/src/test/unity/basics_test_unity.cpp index 19ea1463857..fe4357c0973 100644 --- a/src/test/unity/basics_test_unity.cpp +++ b/src/test/unity/basics_test_unity.cpp @@ -29,3 +29,4 @@ #include #include #include +#include diff --git a/src/test/unity/beast_test_unity2.cpp b/src/test/unity/beast_test_unity2.cpp index f31297d4f72..bcf8d469a74 100644 --- a/src/test/unity/beast_test_unity2.cpp +++ b/src/test/unity/beast_test_unity2.cpp @@ -18,7 +18,6 @@ */ //============================================================================== -#include #include #include #include