Boost logo

Boost :

Subject: Re: [boost] is_lexical_convertible
From: Antony Polukhin (antoshkka_at_[hidden])
Date: 2014-11-24 03:11:10


2014-11-23 23:54 GMT+04:00 endight . <endight_at_[hidden]>:

> 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 <class From, class To>
struct is_lexical_convertible: boost::mpl::bool_<
  (boost::has_left_shift< std::basic_ostream< char >, From >::value
    && boost::has_right_shift< std::basic_istream< char >, To >::value )
  || (boost::has_left_shift< std::basic_ostream< wchar_t >, From >::value
    && boost::has_right_shift< std::basic_istream< wchar_t >, To >::value )
> {};

-- 
Best regards,
Antony Polukhin

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk