Can I mix compile time string comparison with MPL templates?

Posted by Negative Zero on Stack Overflow See other posts from Stack Overflow or by Negative Zero
Published on 2012-06-09T22:36:03Z Indexed on 2012/06/09 22:40 UTC
Read the original article Hit count: 262

Filed under:
|
|

I got this compile time string comparison from another thread using constexpr and C++11 (http://stackoverflow.com/questions/5721813/compile-time-assert-for-string-equality). It works with constant strings like "OK"

    constexpr bool isequal(char const *one, char const *two) {
        return (*one && *two) ? (*one == *two && isequal(one + 1, two + 1))
        : (!*one && !*two);
    }

I am trying to use it in the following context:

 static_assert(isequal(boost::mpl::c_str<boost::mpl::string<'ak'>>::value, "ak"), "should not fail");

But it gives me an compilation error of static_assert expression is not an constant integral expression.

Can I do this?

© Stack Overflow or respective owner

Related posts about c++

Related posts about boost