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-exception
6//
7//===----------------------------------------------------------------------===//
8
9// <ratio>
10//
11// [ratio.general]/2
12// Throughout subclause [ratio], the names of template parameters are
13// used to express type requirements. If a template parameter is named
14// R1 or R2, and the template argument is not a specialization of the
15// ratio template, the program is ill-formed.
16//
17// Since all std::ratio_xxx_v variables use the same instantiation, only one
18// error will be generated. These values are tested in a separate test.
19
20#include <ratio>
21
22struct invalid {
23 static const int num = 1;
24 static const int den = 1;
25};
26
27using valid = std::ratio<1, 1>;
28
29namespace equal {
30using valid_valid = std::ratio_equal<valid, valid>::type;
31using invalid_valid =
32 std::ratio_equal<invalid, valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
33using valid_invalid =
34 std::ratio_equal<valid, invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
35} // namespace equal
36
37namespace not_equal {
38using valid_valid = std::ratio_not_equal<valid, valid>::type;
39using invalid_valid =
40 std::ratio_not_equal<invalid,
41 valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
42using valid_invalid =
43 std::ratio_not_equal<valid,
44 invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
45} // namespace not_equal
46
47namespace less {
48using valid_valid = std::ratio_less<valid, valid>::type;
49using invalid_valid =
50 std::ratio_less<invalid, valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
51using valid_invalid =
52 std::ratio_less<valid, invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
53} // namespace less
54
55namespace less_equal {
56using valid_valid = std::ratio_less_equal<valid, valid>::type;
57using invalid_valid =
58 std::ratio_less_equal<invalid,
59 valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
60using valid_invalid =
61 std::ratio_less_equal<valid,
62 invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
63} // namespace less_equal
64
65namespace greater {
66using valid_valid = std::ratio_greater<valid, valid>::type;
67using invalid_valid =
68 std::ratio_greater<invalid, valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
69using valid_invalid =
70 std::ratio_greater<valid, invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
71} // namespace greater
72
73namespace greater_equal {
74using valid_valid = std::ratio_greater_equal<valid, valid>::type;
75using invalid_valid =
76 std::ratio_greater_equal<invalid,
77 valid>::type; // expected-error@*:* {{R1 to be a specialisation of the ratio template}}
78using valid_invalid =
79 std::ratio_greater_equal<valid,
80 invalid>::type; // expected-error@*:* {{R2 to be a specialisation of the ratio template}}
81} // namespace greater_equal
82

source code of libcxx/test/std/utilities/ratio/ratio.comparison/R1_R2_requirement.verify.cpp