【发布时间】:2017-06-26 16:48:17
【问题描述】:
std::string_view::remove_prefix()和std::string_view::remove_suffix()都是c++17中的constexpr成员函数;但是,它们会修改调用它们的变量。如果该值为constexpr,那么它也将是const,并且无法修改,那么这些函数如何在constexpr值上使用呢?
换一种说法:
constexpr std::string_view a = "asdf";
a.remove_prefix(2); // compile error- a is const
您如何在constexpr std::string_view 上使用这些功能?如果它们不能在constexpr std::string_view 上使用,为什么函数本身标记为constexpr?
【问题讨论】:
标签: c++ c++17 string-view