Index: include/string =================================================================== --- include/string +++ include/string @@ -16,30 +16,17 @@ namespace std { -template -class fpos -{ -private: - stateT st; +template +class fpos { public: - fpos(streamoff = streamoff()); - - operator streamoff() const; - + // [fpos.members], members stateT state() const; void state(stateT); - fpos& operator+=(streamoff); - fpos operator+ (streamoff) const; - fpos& operator-=(streamoff); - fpos operator- (streamoff) const; +private: + stateT st; // exposition only }; -template streamoff operator-(const fpos& x, const fpos& y); - -template bool operator==(const fpos& x, const fpos& y); -template bool operator!=(const fpos& x, const fpos& y); - template struct char_traits { @@ -540,33 +527,32 @@ _StateT __st_; streamoff __off_; public: - _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off = streamoff()) : __st_(), __off_(__off) {} + _LIBCPP_INLINE_VISIBILITY fpos() : __st_(), __off_(0 ) {} + _LIBCPP_INLINE_VISIBILITY fpos(streamoff __off) : __st_(), __off_(__off) {} _LIBCPP_INLINE_VISIBILITY operator streamoff() const {return __off_;} _LIBCPP_INLINE_VISIBILITY _StateT state() const {return __st_;} _LIBCPP_INLINE_VISIBILITY void state(_StateT __st) {__st_ = __st;} - _LIBCPP_INLINE_VISIBILITY fpos& operator+=(streamoff __off) {__off_ += __off; return *this;} - _LIBCPP_INLINE_VISIBILITY fpos operator+ (streamoff __off) const {fpos __t(*this); __t += __off; return __t;} - _LIBCPP_INLINE_VISIBILITY fpos& operator-=(streamoff __off) {__off_ -= __off; return *this;} - _LIBCPP_INLINE_VISIBILITY fpos operator- (streamoff __off) const {fpos __t(*this); __t -= __off; return __t;} -}; + _LIBCPP_INLINE_VISIBILITY fpos + operator+ (streamoff __off) const {return __off + __off_;} -template -inline _LIBCPP_INLINE_VISIBILITY -streamoff operator-(const fpos<_StateT>& __x, const fpos<_StateT>& __y) - {return streamoff(__x) - streamoff(__y);} + _LIBCPP_INLINE_VISIBILITY fpos& + operator+=(streamoff __off) {__off_ += __off; return *this;} -template -inline _LIBCPP_INLINE_VISIBILITY -bool operator==(const fpos<_StateT>& __x, const fpos<_StateT>& __y) - {return streamoff(__x) == streamoff(__y);} + _LIBCPP_INLINE_VISIBILITY fpos + operator- (streamoff __off) const {return __off_ - __off;} -template -inline _LIBCPP_INLINE_VISIBILITY -bool operator!=(const fpos<_StateT>& __x, const fpos<_StateT>& __y) - {return streamoff(__x) != streamoff(__y);} + _LIBCPP_INLINE_VISIBILITY fpos& + operator-=(streamoff __off) {__off_ -= __off; return *this;} + + _LIBCPP_INLINE_VISIBILITY bool + operator!=(fpos& __rhs) {return !(__rhs.__off_ == __off_);} + + _LIBCPP_INLINE_VISIBILITY bool + operator==(fpos& __rhs) {return __rhs.__off_ == __off_;} +}; // basic_string @@ -627,13 +613,13 @@ #else template ::value> struct __libcpp_string_gets_noexcept_iterator_impl : public _LIBCPP_BOOL_CONSTANT(( - noexcept(++(declval<_Iter&>())) && - is_nothrow_assignable<_Iter&, _Iter>::value && - noexcept(declval<_Iter>() == declval<_Iter>()) && + noexcept(++(declval<_Iter&>())) && + is_nothrow_assignable<_Iter&, _Iter>::value && + noexcept(declval<_Iter>() == declval<_Iter>()) && noexcept(*declval<_Iter>()) )) {}; -template +template struct __libcpp_string_gets_noexcept_iterator_impl<_Iter, false> : public false_type {}; #endif @@ -1420,7 +1406,7 @@ _LIBCPP_INLINE_VISIBILITY bool __invariants() const; _LIBCPP_INLINE_VISIBILITY void __clear_and_shrink() _NOEXCEPT; - + _LIBCPP_INLINE_VISIBILITY bool __is_long() const _NOEXCEPT {return bool(__r_.first().__s.__size_ & __short_mask);} @@ -1682,7 +1668,7 @@ -> basic_string<_CharT, _Traits, _Allocator>; #endif - + template inline void @@ -2525,7 +2511,7 @@ const basic_string __temp (__first, __last, __alloc()); append(__temp.data(), __temp.size()); } - else + else { if (__cap - __sz < __n) __grow_by(__cap, __sz + __n - __cap, __sz, __sz, 0); @@ -3824,7 +3810,7 @@ template inline -void +void basic_string<_CharT, _Traits, _Allocator>::__clear_and_shrink() _NOEXCEPT { clear(); @@ -3834,7 +3820,7 @@ __set_long_cap(0); __set_short_size(0); } -} +} // operator== @@ -4331,7 +4317,7 @@ _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string) _LIBCPP_EXTERN_TEMPLATE(class _LIBCPP_EXTERN_TEMPLATE_TYPE_VIS basic_string) -#if _LIBCPP_STD_VER > 11 +#if _LIBCPP_STD_VER > 11 // Literal suffixes for basic_string [basic.string.literals] inline namespace literals { Index: test/std/input.output/iostreams.base/fpos/fpos.operations/fpos.pass.cpp =================================================================== --- /dev/null +++ test/std/input.output/iostreams.base/fpos/fpos.operations/fpos.pass.cpp @@ -0,0 +1,102 @@ +//===----------------------------------------------------------------------===// +// +// 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 +#include +#include + +// + +// template +// class fpos; + +// UNSUPPORTED: c++98, c++03 + +template +struct is_equality_comparable : std::false_type { }; + +template +struct is_equality_comparable +() == std::declval(), (void)0)>::type +> : std::true_type { }; + +template +void test_traits() +{ + static_assert(std::is_default_constructible >::value); + static_assert(std::is_copy_constructible >::value); + static_assert(std::is_copy_assignable >::value); + static_assert(std::is_destructible >::value); + static_assert(is_equality_comparable >::value); + + static_assert(std::is_trivially_copy_constructible::value == + std::is_trivially_copy_constructible>::value); + static_assert(std::is_trivially_copy_assignable::value == + std::is_trivially_copy_assignable>::value); + static_assert(std::is_trivially_destructible::value == + std::is_trivially_destructible>::value); +} + +struct Foo { }; + +int main(int, char**) +{ + test_traits(); + test_traits(); // TODO: what other types should I add? + + // 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; +} Index: www/cxx2a_status.html =================================================================== --- www/cxx2a_status.html +++ www/cxx2a_status.html @@ -93,7 +93,7 @@ P0646R1LWGImproving the Return Value of Erase-Like AlgorithmsRapperswil P0722R3CWGEfficient sized delete for variable sized classesRapperswil P0758R1LWGImplicit conversion traits and utility functionsRapperswilComplete - P0759R1LWGfpos RequirementsRapperswil + P0759R1LWGfpos RequirementsRapperswilComplete P0769R2LWGAdd shift to <algorithm>Rapperswil P0788R3LWGStandard Library Specification in a Concepts and Contracts WorldRapperswil P0879R0LWGConstexpr for swap and swap related functions Also resolves LWG issue 2800.Rapperswil