Skip to content

Conversation

Berrysoft
Copy link
Contributor

@Berrysoft Berrysoft commented Jun 25, 2020

Fixes #15

  • Add declarations.
  • Add implementations
    • with rvalue
    • others
  • Add tests

@cbezault cbezault self-assigned this Jun 25, 2020
@StephanTLavavej StephanTLavavej added the cxx20 C++20 feature label Jun 26, 2020
@Berrysoft
Copy link
Contributor Author

Berrysoft commented Jun 26, 2020

There're two questions I cannot decide:

  • According to the standard, the method basic_stringbuf::str() const should be changed to basic_stringbuf::str() const&. I'm not sure if it is an ABI-breaking change.
  • basic_stringbuf uses a custom buffer, different from basic_string. I try to not change ABI, but it is somehow difficult and dirty, when it comes to small string optimization, and readonly mode of basic_stringbuf. I'm not sure if the current solution is acceptable:
    • In readonly mode, copy the string, as the current implementation doesn't recognize the reserved space in readonly mode.
    • Otherwise, move the buffer, or copy the string in small mode.

@Berrysoft Berrysoft marked this pull request as ready for review June 26, 2020 13:50
@Berrysoft Berrysoft requested a review from a team as a code owner June 26, 2020 13:50
@Berrysoft

This comment has been minimized.

@StephanTLavavej

This comment has been minimized.

Copy link
Member

@StephanTLavavej StephanTLavavej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I have some initial comments after reviewing all of the files (although I haven't done a line-by-line comparison of the product code to the Standardese yet).

@cpplearner

This comment has been minimized.

@mnatsuhara

This comment has been minimized.

@StephanTLavavej

This comment has been minimized.

Copy link
Member

@StephanTLavavej StephanTLavavej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I have a number of comments but the issues I found were localized - to save time, I will work on fixing them later today.

Comment on lines +1505 to +1509
#if _HAS_CXX20
template <class _Ty>
concept _Allocator = _Is_allocator<_Ty>::value;
#endif // _HAS_CXX20

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks OK to me. I think the unusual part is that this is actually a concept. Elsewhere, we've used SFINAE to implement constraints in C++20 features, except when concepts are absolutely unavoidable (for example <ranges>; also <span> has a conformant concepts and fallback SFINAE implementation). This is because EDG has certain bugs that prevent us from fully enabling concepts at this time.

Given that the tests are passing, and that we ultimately do want to use concepts in C++20 mode, I think this is OK. If we encounter issues with EDG, replacing this concept with SFINAE should be a targeted change.

Separately, it would be possible to implement this concept "directly" instead of by referring to the SFINAE implementation that I wrote for CTAD; however I am not sure that there are any throughput benefits to doing so, and duplicating that somewhat complicated definition would be undesirable, so the centralized approach seems ideal.

_Construct_in_place(_My_data._Bx._Ptr, _Fancy_right);
return true;
} else {
_Traits::copy(_My_data._Bx._Buf, _Right, _Res);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure whether we should copy _Res characters, or _Size + 1 for just the characters that are actually stored (+ 1 for the null terminator).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is a correctness issue, so I don't want to risk damaging the code. No change requested.

} else {
// use _BUF_SIZE + 1 to avoid SSO, if the buffer is assigned back
_Result._Ptr = _Al.allocate(_BUF_SIZE + 1);
_Traits::copy(_Unfancy(_Result._Ptr), _My_data._Bx._Buf, _BUF_SIZE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, I am unsure whether we should copy the entire _BUF_SIZE, or just _My_data._Mysize + 1 for the actually stored characters plus the null terminator.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto no change requested.

@StephanTLavavej StephanTLavavej removed their assignment Jan 15, 2021
@Berrysoft
Copy link
Contributor Author

I think the review request to @BillyONeal was a mishandling by myself, but I don't know how to cancel it.

@StephanTLavavej
Copy link
Member

@Berrysoft No problem, it won’t block merging. I plan to get a quick double-check from another maintainer tomorrow, then prepare an internal MSVC-PR port.

@StephanTLavavej StephanTLavavej removed the request for review from BillyONeal January 15, 2021 08:14
@StephanTLavavej StephanTLavavej self-assigned this Jan 15, 2021
@StephanTLavavej StephanTLavavej merged commit 6c9f6da into microsoft:master Jan 16, 2021
@StephanTLavavej
Copy link
Member

Merged! Thanks again for implementing this feature, which will ship in VS 2019 16.10 Preview 1. 🚀 😺 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cxx20 C++20 feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

P0408R7 Efficient Access To basic_stringbuf's Buffer
9 participants