[libcxx] [NFC] fpos Requirements (p0759r1).

Implements p0759r1. Test-only change. Adds explicit test for table 106 and type checking.

Differential Review: https://reviews.llvm.org/D60491
This commit is contained in:
zoecarver 2020-05-07 14:01:58 -07:00
parent 5a4ddbd69d
commit df73e36dc6
2 changed files with 102 additions and 1 deletions

View File

@ -0,0 +1,101 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "test_macros.h"
#include <string>
#include <cassert>
#include <type_traits>
// <string>
// template <class stateT>
// class fpos;
template<class T, class = void>
struct is_equality_comparable : std::false_type { };
template<class T>
struct is_equality_comparable
<T, typename std::enable_if<true, decltype(std::declval<T const&>() == std::declval<T const&>(),
(void)0)>::type
> : std::true_type { };
template<class T>
void test_traits()
{
static_assert(std::is_default_constructible <std::fpos<T> >::value, "");
static_assert(std::is_copy_constructible <std::fpos<T> >::value, "");
static_assert(std::is_copy_assignable <std::fpos<T> >::value, "");
static_assert(std::is_destructible <std::fpos<T> >::value, "");
static_assert(is_equality_comparable <std::fpos<T> >::value, "");
static_assert(std::is_trivially_copy_constructible<T>::value ==
std::is_trivially_copy_constructible<std::fpos<T> >::value, "");
static_assert(std::is_trivially_copy_assignable<T>::value ==
std::is_trivially_copy_assignable<std::fpos<T> >::value, "");
static_assert(std::is_trivially_destructible<T>::value ==
std::is_trivially_destructible<std::fpos<T> >::value, "");
}
struct Foo { };
int main(int, char**)
{
test_traits<std::mbstate_t>();
test_traits<int>();
test_traits<Foo>();
// Position type requirements table 106 (in order):
std::streampos p1(42);
std::streamoff o1(p1);
{
assert(o1 == 42);
}
{
std::streampos p2(42);
std::streampos q1(43);
std::streampos const p3(44);
std::streampos const q2(45);
assert(p2 != q1);
assert(p3 != q2);
assert(p2 != q2);
assert(p3 != q1);
}
{
std::streampos p2 = p1 + o1;
assert(p2 == 84);
}
{
std::streampos& p2 = p1 += o1;
assert(p2 == 84);
assert(p1 == 84);
}
{
std::streampos p2 = p1 - o1;
assert(p2 == 42);
}
{
std::streampos& p2 = p1 -= o1;
assert(p2 == 42);
assert(p1 == 42);
}
{
std::streampos p2 = o1 + p1;
assert(p2 == 84);
}
{
std::streampos q1(42);
std::streamoff o2 = q1 - p1;
assert(o2 == 0);
}
return 0;
}

View File

@ -93,7 +93,7 @@
<tr><td><a href="https://wg21.link/P0646R1">P0646R1</a></td><td>LWG</td><td>Improving the Return Value of Erase-Like Algorithms</td><td>Rapperswil</td><td>Complete</td><td>10.0</td></tr>
<tr><td><a href="https://wg21.link/P0722R3">P0722R3</a></td><td>CWG</td><td>Efficient sized delete for variable sized classes</td><td>Rapperswil</td><td>Complete</td><td>9.0</td></tr>
<tr><td><a href="https://wg21.link/P0758R1">P0758R1</a></td><td>LWG</td><td>Implicit conversion traits and utility functions</td><td>Rapperswil</td><td>Complete</td><td></td></tr>
<tr><td><a href="https://wg21.link/P0759R1">P0759R1</a></td><td>LWG</td><td>fpos Requirements</td><td>Rapperswil</td><td></td><td></td></tr>
<tr><td><a href="https://wg21.link/P0759R1">P0759R1</a></td><td>LWG</td><td>fpos Requirements</td><td>Rapperswil</td><td>Complete</td><td>11.0</td></tr>
<tr><td><a href="https://wg21.link/P0769R2">P0769R2</a></td><td>LWG</td><td>Add shift to &lt;algorithm&gt;</td><td>Rapperswil</td><td></td><td></td></tr>
<tr><td><a href="https://wg21.link/P0788R3">P0788R3</a></td><td>LWG</td><td>Standard Library Specification in a Concepts and Contracts World</td><td>Rapperswil</td><td></td><td></td></tr>
<tr><td><a href="https://wg21.link/P0879R0">P0879R0</a></td><td>LWG</td><td>Constexpr for swap and swap related functions Also resolves LWG issue 2800.</td><td>Rapperswil</td><td></td><td></td></tr>