brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.8 KiB · 226a358 Raw
124 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// <utility>10 11// template <class T1, class T2> struct pair12 13// template <class T1, class T2, class U1, class U2> bool operator==(const pair<T1,T2>&, const pair<U1,U2>&);14// template <class T1, class T2, class U1, class U2> bool operator!=(const pair<T1,T2>&, const pair<U1,U2>&);15// template <class T1, class T2, class U1, class U2> bool operator< (const pair<T1,T2>&, const pair<U1,U2>&);16// template <class T1, class T2, class U1, class U2> bool operator> (const pair<T1,T2>&, const pair<U1,U2>&);17// template <class T1, class T2, class U1, class U2> bool operator>=(const pair<T1,T2>&, const pair<U1,U2>&);18// template <class T1, class T2, class U1, class U2> bool operator<=(const pair<T1,T2>&, const pair<U1,U2>&);19 20#include <utility>21#include <cassert>22#include <concepts>23 24#include "test_comparisons.h"25#include "test_macros.h"26 27#if TEST_STD_VER >= 2628 29// Test SFINAE.30 31static_assert(std::equality_comparable<std::pair<EqualityComparable, EqualityComparable>>);32 33static_assert(!std::equality_comparable<std::pair<EqualityComparable, NonComparable>>);34static_assert(!std::equality_comparable<std::pair<NonComparable, EqualityComparable>>);35 36#endif // TEST_STD_VER >= 2637 38int main(int, char**)39{40    {41        typedef std::pair<int, short> P1;42        typedef std::pair<long, long> P2;43        P1 p1(3, static_cast<short>(4));44        P2 p2(3, 4);45        assert( (p1 == p2));46        assert(!(p1 != p2));47        assert(!(p1 <  p2));48        assert( (p1 <= p2));49        assert(!(p1 >  p2));50        assert( (p1 >= p2));51    }52    {53        typedef std::pair<int, short> P;54        P p1(3, static_cast<short>(4));55        P p2(3, static_cast<short>(4));56        assert( (p1 == p2));57        assert(!(p1 != p2));58        assert(!(p1 <  p2));59        assert( (p1 <= p2));60        assert(!(p1 >  p2));61        assert( (p1 >= p2));62    }63    {64        typedef std::pair<int, short> P;65        P p1(2, static_cast<short>(4));66        P p2(3, static_cast<short>(4));67        assert(!(p1 == p2));68        assert( (p1 != p2));69        assert( (p1 <  p2));70        assert( (p1 <= p2));71        assert(!(p1 >  p2));72        assert(!(p1 >= p2));73    }74    {75        typedef std::pair<int, short> P;76        P p1(3, static_cast<short>(2));77        P p2(3, static_cast<short>(4));78        assert(!(p1 == p2));79        assert( (p1 != p2));80        assert( (p1 <  p2));81        assert( (p1 <= p2));82        assert(!(p1 >  p2));83        assert(!(p1 >= p2));84    }85    {86        typedef std::pair<int, short> P;87        P p1(3, static_cast<short>(4));88        P p2(2, static_cast<short>(4));89        assert(!(p1 == p2));90        assert( (p1 != p2));91        assert(!(p1 <  p2));92        assert(!(p1 <= p2));93        assert( (p1 >  p2));94        assert( (p1 >= p2));95    }96    {97        typedef std::pair<int, short> P;98        P p1(3, static_cast<short>(4));99        P p2(3, static_cast<short>(2));100        assert(!(p1 == p2));101        assert( (p1 != p2));102        assert(!(p1 <  p2));103        assert(!(p1 <= p2));104        assert( (p1 >  p2));105        assert( (p1 >= p2));106    }107 108#if TEST_STD_VER > 11109    {110        typedef std::pair<int, short> P;111        constexpr P p1(3, static_cast<short>(4));112        constexpr P p2(3, static_cast<short>(2));113        static_assert(!(p1 == p2), "");114        static_assert( (p1 != p2), "");115        static_assert(!(p1 <  p2), "");116        static_assert(!(p1 <= p2), "");117        static_assert( (p1 >  p2), "");118        static_assert( (p1 >= p2), "");119    }120#endif121 122  return 0;123}124