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

Make find() constexpr in C++11 #48

Open
eyalroz opened this issue Feb 12, 2022 · 7 comments
Open

Make find() constexpr in C++11 #48

eyalroz opened this issue Feb 12, 2022 · 7 comments

Comments

@eyalroz
Copy link

eyalroz commented Feb 12, 2022

Currently, the find() method of basic_string_view is nssv_constexpr14. It seems to me it should be possible to make it constexpr since C++11 with tail-recursion iteration.

@martinmoene
Copy link
Owner

I'd like to do so, can you hint on an implementation?

@eyalroz
Copy link
Author

eyalroz commented Feb 12, 2022

@martinmoene : Is the naive implementation not ok for the constexpr case?

@eyalroz
Copy link
Author

eyalroz commented Feb 12, 2022

@martinmoene : See #49 .

@martinmoene
Copy link
Owner

@eyalroz thanks for your input! It helps to get me going :)

martinmoene added a commit that referenced this issue Feb 13, 2022
commit d934b1ac5b8c4ad30222d5fa89d610f74e1b005a
Author: Eyal Rozenberg <[email protected]>
Date:   Sat Feb 12 21:10:58 2022 +0200

Naive implementation of a `constexpr` alternative to `std::search()` for pairs of `basic_string_view`s, using the `basic_string_view::starts_with()` method.
@eyalroz
Copy link
Author

eyalroz commented Feb 13, 2022

@martinmoene : Do you think we could possibly use an immediately-invoked lambda instead of the function call?

@martinmoene
Copy link
Owner

Not immediately ;)

Can you explain what the driving idea behind that is?

In C++14, one can create a recursive lambda, but not immediately invoke it.

@eyalroz
Copy link
Author

eyalroz commented Feb 13, 2022

Right, we wouldn't be able to recurse. I just wanted to avoid the separate function outside the class, if it's only used in one place.

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

No branches or pull requests

2 participants