Opened 6 years ago
Last modified 5 years ago
#12896 new Bugs
[Utility] string_view's comparison operators are not marked "constexpr"
Reported by: | Zheng Luo | 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.
All the variations of
basic_string_view::compare
are marked as constexpr. (well,BOOST_CXX14_CONSTEXPR
). But, as you correctly point out, the operators (< <= == != > > =
are not.That's not strictly true; merely a default. You are free to use your own traits class.
I'll fix the operators.