+ namespace detail // selectors for choosing stream character type
+ {
+ template<typename Type>
+ struct stream_char
+ {
+ typedef char type;
+ };
+
+ #ifndef DISABLE_WIDE_CHAR_SUPPORT
+#if !defined(BOOST_NO_INTRINSIC_WCHAR_T)
+ template<>
+ struct stream_char<wchar_t>
+ {
+ typedef wchar_t type;
+ };
+#endif
+
+ template<>
+ struct stream_char<wchar_t *>
+ {
+ typedef wchar_t type;
+ };
+
+ template<>
+ struct stream_char<const wchar_t *>
+ {
+ typedef wchar_t type;
+ };
+
+ template<>
+ struct stream_char<std::wstring>
+ {
+ typedef wchar_t type;
+ };
+ #endif
+
+ template<typename TargetChar, typename SourceChar>
+ struct widest_char
+ {
+ typedef TargetChar type;
+ };
+
+ template<>
+ struct widest_char<char, wchar_t>
+ {
+ typedef wchar_t type;
+ };
+ }
+
+ namespace detail // stream wrapper for handling lexical conversions
+ {
+ template<typename Target, typename Source>
+ class lexical_stream
+ {
+ private:
+ typedef typename widest_char<
+ typename stream_char<Target>::type,
+ typename stream_char<Source>::type>::type char_type;
+
+ public:
+ lexical_stream()
+ {
+ stream.unsetf(std::ios::skipws);
+
+ if(std::numeric_limits<Target>::is_specialized)
+ stream.precision(std::numeric_limits<Target>::digits10 + 1);
+ else if(std::numeric_limits<Source>::is_specialized)
+ stream.precision(std::numeric_limits<Source>::digits10 + 1);
+ }
+ ~lexical_stream()
+ {
+ #if defined(BOOST_NO_STRINGSTREAM)
+ stream.freeze(false);
+ #endif
+ }
+ bool operator<<(const Source &input)
+ {
+ return !(stream << input).fail();
+ }
+ template<typename InputStreamable>
+ bool operator>>(InputStreamable &output)
+ {
+ return !is_pointer<InputStreamable>::value &&
+ stream >> output &&
+ stream.get() ==
+#if defined(__GNUC__) && (__GNUC__<3) && defined(BOOST_NO_STD_WSTRING)
+// GCC 2.9x lacks std::char_traits<>::eof().
+// We use BOOST_NO_STD_WSTRING to filter out STLport and libstdc++-v3
+// configurations, which do provide std::char_traits<>::eof().
+
+ EOF;
+#else
+ std::char_traits<char_type>::eof();
+#endif
+ }
+ bool operator>>(std::string &output)
+ {
+ #if defined(BOOST_NO_STRINGSTREAM)
+ stream << '\0';
+ #endif
+ output = stream.str();
+ return true;
+ }
+ #ifndef DISABLE_WIDE_CHAR_SUPPORT
+ bool operator>>(std::wstring &output)
+ {
+ output = stream.str();
+ return true;
+ }
+ #endif
+ private:
+ #if defined(BOOST_NO_STRINGSTREAM)
+ std::strstream stream;
+ #elif defined(BOOST_NO_STD_LOCALE)
+ std::stringstream stream;
+ #else
+ std::basic_stringstream<char_type> stream;
+ #endif
+ };
+ }
+
+ #ifndef BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
+
+ // call-by-const reference version
+
+ namespace detail
+ {
+ template<class T>
+ struct array_to_pointer_decay
+ {
+ typedef T type;
+ };
+
+ template<class T, std::size_t N>
+ struct array_to_pointer_decay<T[N]>
+ {
+ typedef const T * type;
+ };
+ }
+