Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First draft of cetl::pf17::string_view #142

Merged
merged 4 commits into from
Oct 22, 2024

Conversation

serges147
Copy link
Contributor

@serges147 serges147 commented Oct 17, 2024

Copy link
Member

@pavel-kirienko pavel-kirienko left a comment

Choose a reason for hiding this comment

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

Are the docs omitted on purpose?


enum : size_type
{
npos = static_cast<size_type>(-1)
Copy link
Member

Choose a reason for hiding this comment

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

Why not static constexpr?

Copy link
Contributor Author

@serges147 serges147 Oct 18, 2024

Choose a reason for hiding this comment

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

c++14 and ODR issue

Could you please show me an example if you know a nicer syntax which is compatible with c++14.

@@ -0,0 +1,323 @@
/// @file
Copy link
Member

Choose a reason for hiding this comment

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

It's critical that we start with type-parameterized tests that compare the CETL implementation to the ones in our representative standard libraries like https://github.com/OpenCyphal/CETL/blob/main/cetlvast/suites/unittest/test_pf20_span.cpp does for span.

Copy link
Contributor Author

@serges147 serges147 Oct 18, 2024

Choose a reason for hiding this comment

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

  1. See below my response, namely:

My thinking was that it will add more work while we most probably will use char specialization only.

Could you please elaborate why it is critical to invest into what we most probably (plz correct me if I'm wrong) will not use? Are we making CETL universal for the whole world? Honestly, it's quite exhausting to "fight" against c++14 - I believe libcyphal were long time done already if it was not support of 14 standard. And Nunavut's c++ code generation goals will be much simpler and more clean. I do understand that anyway there will be always a "race" against the latest standard and what we "have to support", so polyfills will probably still live in some form... it just concerns me (a lot!) that a lot of simple things become not so simple, and hardly contribute to the final product we deliver to customers. Sorry, for my frustration and being emotional ;)

  1. BTW, you said

... compare the CETL implementation to the ones in our representative standard libraries ..."

I didn't quite catch what you meant by "compare"... I don't see there any comparison of what cetl::pf20::span and std::span does... if this is what you meant.

Anyway, if you confirm (and hopefully explain why) that basic_string_view is a must then of course I will change my tests to be type parameterized. TBD: all of the below?

Defined in header [<string_view>](https://en.cppreference.com/w/cpp/header/string_view)
Type	Definition
std::string_view (C++17)	std::basic_string_view<char>
std::wstring_view (C++17)	std::basic_string_view<wchar_t>
// std::u8string_view (C++20)	std::basic_string_view<char8_t>   // TBD: should be under our pf20?
std::u16string_view (C++17)	std::basic_string_view<char16_t>
std::u32string_view (C++17)	std::basic_string_view<char32_t>

Copy link
Member

Choose a reason for hiding this comment

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

The simple answer is that CETL's polyfill types are re-implementations from the standard and the standard defines basic_stringview then provides aliases. We can tolerate sparse implementations but must minimize deviant implementations.

As for the reasoning for C++14? It just goes to the state of the world and compatibility. The need for C++14 polyfill types will naturally diminish over time just as all software gets outdated and deprecated as the years roll by.

namespace pf17
{

class string_view
Copy link
Member

Choose a reason for hiding this comment

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

In the standard, string_view is just an alias for basic_string_view so we need to start with this template.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I can do it. My thinking was that it will add more work while we most probably will use char specialization only.

@serges147
Copy link
Contributor Author

serges147 commented Oct 18, 2024

Are the docs omitted on purpose?

You are right, I for some reason thought that we don't duplicate docs (cppreference) for our polyfills, but now I see that span, variant and etc do contain certain level of documentation - I'll fix it.

Copy link

Copy link
Member

@thirtytwobits thirtytwobits left a comment

Choose a reason for hiding this comment

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

This is fine but please add the A/B comparison test between STL and CETL. See test_variable_length_array_compat.cpp:159 "Any Type" for how to swap between the two in parameterized tests.

@thirtytwobits thirtytwobits merged commit 040182a into issue/string_view_2 Oct 22, 2024
32 checks passed
@thirtytwobits thirtytwobits deleted the sshirokov/string_view branch October 22, 2024 00:44
@thirtytwobits thirtytwobits restored the sshirokov/string_view branch October 22, 2024 00:46
@thirtytwobits
Copy link
Member

Well, that didn't go as I had planned. I pushed an example of how to write these A/B tests but it ended up "merging" your PR into this repo's new string_view_2 branch. Can you take a look and finish your work up on that branch or pull it over and reopen this one? Sorry.

@serges147 serges147 deleted the sshirokov/string_view branch October 22, 2024 12:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants