vendredi 30 juin 2017

Is std::is_same

I've inherited some code that looks like this:

///
/// A specializable function for converting a user-defined object to a string value
///
template <typename value_type>
std::string to_string(const value_type &value)
{
    static_assert(!std::is_same<value_type, value_type>::value, "Unspecialized usage of to_string not supported");
    return "";
}

///
/// A specializable function for converting a user-defined object from a string to a value
///
template <typename return_type>
return_type from_string(const std::string &source)
{
    static_assert(!std::is_same<return_type, return_type>::value, "Unspecialized usage of from_string not supported");
}

!std::is_same<value_type, value_type>::value seems overly verbose.

Should I change these statements to static_assert(false,"...")?

I'm not sure if it was expressed this way to handle some kind of edge case, or if false is indeed equivalent.

Is std::is_same<t,t>::value always true?

Aucun commentaire:

Enregistrer un commentaire