Opened 6 years ago
Closed 5 years ago
#12897 closed Bugs (fixed)
[Utility] string_view's comparison operators are not marked "constexpr"
Reported by: | Owned by: | Marshall Clow | |
---|---|---|---|
Milestone: | To Be Determined | Component: | utility |
Version: | Boost 1.63.0 | Severity: | Problem |
Keywords: | string_view, constexpr | Cc: |
Description
During the implementation of my GSoC static_map competency project, I found that in Boost 1.63, string_view's comparison operator was not marked as constexpr(http://www.boost.org/doc/libs/1_63_0/boost/utility/string_view.hpp). According to cppreference, string_view in C++17's standard library includes constexpr comparison operators, and actually the implementation of Boost's comparison operators calls constexpr compare() method. However, constexpr compare() in Boost never works in C++14, since it uses std::char_traits in standard library, of which char_traits::compare is not marked constexpr until C++17. It seems possible to backport C++17's constexpr char_traits into Boost's library.
Change History (2)
comment:1 by , 6 years ago
Owner: | changed from | to
---|
comment:2 by , 5 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
I have added constexpr to the string_view
comparison calls (and operators), so that if you use a traits class that has a constexpr compare
method, you'll get constexpr comparisons.
Boost doesn't have a char_traits implementation, constexpr or otherwise.
As I mentioned on the mailing list, unless we can select an optimized runtime versions of the algorithms provided by
char_traits
based onconstexpr
-ness of their arguments (or better yet untilchar_traits
does that),constexpr
versions ofstring_view
operations or constructors are not feasible. I don't think sacrificing runtime performance is an acceptable solution.Assigning the ticket to Marshall Clow.