Opened 6 years ago

Closed 5 years ago

#12897 closed Bugs (fixed)

[Utility] string_view's comparison operators are not marked "constexpr"

Reported by: vicluo96@… 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 Andrey Semashev, 6 years ago

Owner: changed from No-Maintainer to Marshall Clow

As I mentioned on the mailing list, unless we can select an optimized runtime versions of the algorithms provided by char_traits based on constexpr-ness of their arguments (or better yet until char_traits does that), constexpr versions of string_view operations or constructors are not feasible. I don't think sacrificing runtime performance is an acceptable solution.

Assigning the ticket to Marshall Clow.

comment:2 by Marshall Clow, 5 years ago

Resolution: fixed
Status: newclosed

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.

Note: See TracTickets for help on using tickets.