brintos

brintos / llvm-project-archived public Read only

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