is_lexical_convertible
Is there something like `boost::is_lexical_convertible` (like `boost::is_convertible`)?
On Sunday 23 November 2014 23:54:26 endight . wrote:
Is there something like `boost::is_lexical_convertible` (like `boost::is_convertible`)?
You mean a trait that tells if lexical_cast will work for your type? I don't think so. Your best bet is has_left_shift and has_right_shift, with the left operand type being the stream and the right one your type. But that doesn't tell that lexical_cast will actually succeed because the stream operators can be not reversible. In general there is no way to tell that the operators are reversible, so without some help from the user such a trait cannot be implemented.
2014-11-23 23:54 GMT+04:00 endight .
Is there something like `boost::is_lexical_convertible` (like `boost::is_convertible`)?
There is a runtime function boost::conversion::try_lexical_convert, that
does not throw and returns true if conversion succeeded.
If compile time trait is required, then something like the following would
work in most cases (not tested):
template
{};
-- Best regards, Antony Polukhin
participants (3)
-
Andrey Semashev
-
Antony Polukhin
-
endight .