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// <ios>
10
11// template <class stateT>
12// class fpos;
13
14#include <cassert>
15#include <ios>
16#include <type_traits>
17
18#include "test_macros.h"
19
20template<class T, class = void>
21struct is_equality_comparable : std::false_type { };
22
23template<class T>
24struct is_equality_comparable
25<T, typename std::enable_if<true, decltype(std::declval<T const&>() == std::declval<T const&>(),
26 (void)0)>::type
27> : std::true_type { };
28
29template<class T>
30void test_traits()
31{
32 static_assert(std::is_default_constructible <std::fpos<T> >::value, "");
33 static_assert(std::is_copy_constructible <std::fpos<T> >::value, "");
34 static_assert(std::is_copy_assignable <std::fpos<T> >::value, "");
35 static_assert(std::is_destructible <std::fpos<T> >::value, "");
36 static_assert(is_equality_comparable <std::fpos<T> >::value, "");
37
38 static_assert(std::is_trivially_copy_constructible<T>::value ==
39 std::is_trivially_copy_constructible<std::fpos<T> >::value, "");
40 static_assert(std::is_trivially_copy_assignable<T>::value ==
41 std::is_trivially_copy_assignable<std::fpos<T> >::value, "");
42 static_assert(std::is_trivially_destructible<T>::value ==
43 std::is_trivially_destructible<std::fpos<T> >::value, "");
44}
45
46struct Foo { };
47
48int main(int, char**)
49{
50 test_traits<std::mbstate_t>();
51 test_traits<int>();
52 test_traits<Foo>();
53
54 // Position type requirements table 106 (in order):
55
56 std::streampos p1(42);
57 std::streamoff o1(p1);
58
59 {
60 assert(o1 == 42);
61 }
62 {
63 std::streampos p2(42);
64 std::streampos q1(43);
65 std::streampos const p3(44);
66 std::streampos const q2(45);
67 assert(p2 != q1);
68 assert(p3 != q2);
69 assert(p2 != q2);
70 assert(p3 != q1);
71 }
72 {
73 std::streampos p2 = p1 + o1;
74 assert(p2 == 84);
75 }
76 {
77 std::streampos& p2 = p1 += o1;
78 assert(p2 == 84);
79 assert(p1 == 84);
80 }
81 {
82 std::streampos p2 = p1 - o1;
83 assert(p2 == 42);
84 }
85 {
86 std::streampos& p2 = p1 -= o1;
87 assert(p2 == 42);
88 assert(p1 == 42);
89 }
90 {
91 std::streampos p2 = o1 + p1;
92 assert(p2 == 84);
93 }
94 {
95 std::streampos q1(42);
96 std::streamoff o2 = q1 - p1;
97 assert(o2 == 0);
98 }
99
100 return 0;
101}
102

source code of libcxx/test/std/input.output/iostreams.base/fpos/fpos.operations/fpos.pass.cpp