Extract bool from istream in a templated function

I convert my field class reader functions to a single template function. I have field classes for int, unsigned int, long,and unsigned long. They all use the same method to extract values ​​from istringstream(only types change):

template <typename Value_Type>
Value_Type Extract_Value(const std::string& input_string)
{
    std::istringstream    m_string_stream;
    m_string_stream.str(input_string);
    m_string_stream.clear();
    m_string_stream >> value;
    return;
}

The hard part is with type bool(Boolean). There are many textual representations for booleans:,
0, 1, T, F, TRUE, FALSEand all case-insensitive combinations

Here are the questions:

  • What does the C ++ standard say valid data to retrieve boolusing the stream retrieval operator?
  • Since boolean can represent text, does this include locales?
  • Is this platform dependent?

, bool.

MS Visual Studio 2008 ( 9), ++, Windows XP Vista.

+3
1

true false std::numpunct::truename() std::numpunct::falsename(). numpunct use_facet <numpunct <char> >(stream.getloc()), .

EDIT: "1"/"0" "true"/"false std::noboolalpha std::boolalpha.

+2

Source: https://habr.com/ru/post/1746637/


All Articles