Thanks to the help of @ Jarod42 on a separate issue, I have a solution that works with C ++ 98, C ++ 03 and C ++ 11; g ++ and VS2015. Also for the child task std::vector<bool>.
#define DEFINE_HAS_SIGNATURE(traitsName, funcName, signature) \
template <typename U> \
class traitsName \
{ \
private: \
typedef boost::uint8_t yes; typedef boost::uint16_t no; \
template<typename T, T> struct helper; \
template<typename T> static yes check(helper<signature, &funcName>*);\
template<typename T> static no check(...); \
public: \
static const bool value = sizeof check<U>(0) == sizeof(yes); \
}
DEFINE_HAS_SIGNATURE(has_resize_1, T::resize, void (T::*)(typename T::size_type));
DEFINE_HAS_SIGNATURE(has_resize_2, T::resize, void (T::*)(typename T::size_type, \
typename T::value_type));
. , has_resize_1, has_resize_2 resize(). , ++ 11 resize() , ; ++ 11, : , . , VS2015, -, - . , .
, , has_resize<C>::value. , .
template <typename T>
typename boost::enable_if_c<
!boost::spirit::traits::is_container<T>::value,
xstream &>::type
operator>>(xstream &ibs, T &b)
{
return ibs;
}
template <typename C>
typename boost::enable_if_c<
boost::spirit::traits::is_container<C>::value &&
(has_resize_1<C>::value || has_resize_2<C>::value),
xstream &
>::type
operator>>(xstream &ibs, C &c)
{
typename C::value_type v;
ibs >> v;
return ibs;
}
template <typename C>
typename boost::enable_if_c<
boost::spirit::traits::is_container<C>::value &&
!(has_resize_1<C>::value || has_resize_2<C>::value),
xstream &
>::type
operator>>(xstream &ibs, C &c)
{
typename C::value_type v;
ibs >> v;
return ibs;
}