// { dg-do run { target c++20 } }
// Copyright (C) 2020-2025 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// terms of the GNU General Public License as published by the
// Free Software Foundation; either version 3, or (at your option)
// any later version.
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License along
// with this library; see the file COPYING3. If not see
// .
// Tuple
#include
#include
using namespace std;
template
bool self_consistent(const T& x)
{
return std::is_eq(x <=> x) && x == x && !(x != x) && x <= x && !(x < x);
}
void
test01()
{
int i=0;
int j=0;
int k=2;
tuple a(0, 0, 0);
tuple b(0, 0, 1);
tuple c(i,j,k);
tuple d(c);
VERIFY( self_consistent(a) );
VERIFY( self_consistent(b) );
VERIFY( self_consistent(c) );
VERIFY( self_consistent(d) );
VERIFY( !(a > a) && !(b > b) );
VERIFY( a >= a && b >= b );
VERIFY( a < b && !(b < a) && a <= b && !(b <= a) );
VERIFY( b > a && !(a > b) && b >= a && !(a >= b) );
VERIFY( std::is_lt(a <=> b) );
VERIFY( std::is_gt(b <=> a) );
VERIFY( std::is_gt(c <=> a) );
VERIFY( std::is_eq(c <=> d) );
static_assert( std::is_same_v d), std::strong_ordering> );
}
template
constexpr bool
check_compare(T&& t, U&& u, C c)
{
using R = std::compare_three_way_result_t;
static_assert( std::same_as );
return (t <=> u) == c;
}
void
test02()
{
using std::strong_ordering;
using std::weak_ordering;
using std::partial_ordering;
using T0 = std::tuple<>;
static_assert( check_compare(T0(), T0(), strong_ordering::equal) );
using Ti = std::tuple;
using Tu = std::tuple;
static_assert( check_compare(Ti(1), Tu(1u), weak_ordering::equivalent) );
static_assert( check_compare(Ti(1), Tu(2u), weak_ordering::less) );
static_assert( check_compare(Ti(-1), Tu(1u), weak_ordering::greater) );
using Tii = std::tuple;
using Tlu = std::tuple;
static_assert( check_compare(Tii(1, 2), Tlu(2l, 1u), weak_ordering::less) );
using Tid = std::tuple;
static_assert( check_compare(Tii(3, 4), Tid(2, 0.9), partial_ordering::greater) );
static_assert( !std::three_way_comparable_with );
static_assert( !std::three_way_comparable_with );
static_assert( !std::three_way_comparable_with );
}
int main()
{
test01();
test02();
}