regex_traits::value
Converts an element to a digit value.
int value(Elem ch, int radix) const;
Parameters
ch
The element to convert.radix
The arithmetic base to use.
Remarks
The member function returns the value represented by the character ch in the base radix, or -1 if ch is not a valid digit in the base radix. The function will only be called with a radix argument of 8, 10, or 16.
Example
// std_tr1__regex__regex_traits_value.cpp
// compile with: /EHsc
#include <regex>
#include <iostream>
typedef std::tr1::regex_traits<char> Mytr;
int main()
{
Mytr tr;
Mytr::char_type ch = tr.translate('a');
std::cout << "translate('a') == 'a' == " << std::boolalpha
<< (ch == 'a') << std::endl;
std::cout << "nocase 'a' == 'A' == " << std::boolalpha
<< (tr.translate_nocase('a') == tr.translate_nocase('A'))
<< std::endl;
const char *lbegin = "abc";
const char *lend = lbegin + strlen(lbegin);
Mytr::size_type size = tr.length(lbegin);
std::cout << "length(\"abc\") == " << size <<std::endl;
Mytr::string_type str = tr.transform(lbegin, lend);
std::cout << "transform(\"abc\") < \"abc\" == " << std::boolalpha
<< (str < "abc") << std::endl;
const char *ubegin = "ABC";
const char *uend = ubegin + strlen(ubegin);
std::cout << "primary \"ABC\" < \"abc\" == " << std::boolalpha
<< (tr.transform_primary(ubegin, uend) <
tr.transform_primary(lbegin, lend))
<< std::endl;
const char *dig = "digit";
Mytr::char_class_type cl = tr.lookup_classname(dig, dig + 5);
std::cout << "class digit == d == " << std::boolalpha
<< (cl == tr.lookup_classname(dig, dig + 1))
<< std::endl;
std::cout << "'3' is digit == " <<std::boolalpha
<< tr.isctype('3', tr.lookup_classname(dig, dig + 5))
<< std::endl;
std::cout << "hex C == " << tr.value('C', 16) << std::endl;
// other members
str = tr.lookup_collatename(dig, dig + 5);
Mytr::locale_type loc = tr.getloc();
tr.imbue(loc);
return (0);
}
translate('a') == 'a' == true nocase 'a' == 'A' == true length("abc") == 3 transform("abc") < "abc" == false primary "ABC" < "abc" == false class digit == d == true '3' is digit == true hex C == 12
Requirements
Header: <regex>
Namespace: std::tr1