Reputation: 147
constexpr bool isShorter(const string &s1, const string &s2)
{
return s1.size() < s2.size();
}
When compiled it says: "error call to non-constexpr function"
Upvotes: 1
Views: 212
Reputation: 217930
std::string::size()
is not constexpr
With literal c-string you may do:
template <std::size_t N1, std::size_t N2>
constexpr bool isShorter(const char (&)[N1], const char (&)[N2])
{
return N1 < Ns;
}
Upvotes: 1