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.

Change History (2)

comment:1 by Marshall Clow, 5 years ago

Owner: changed from No-Maintainer to Marshall Clow

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.

However, constexpr compare() in Boost never works in C++14, since it uses std::char_traits in standard library.

That's not strictly true; merely a default. You are free to use your own traits class.

I'll fix the operators.

comment:2 by Marshall Clow, 5 years ago

Commit 330b49d602e0f3b1a7697bd0c816d6031b59f80c addresses this.

Note: See TracTickets for help on using tickets.