Is there any reason that the ctype facet functions (is
,scan_is
,scan_not
only support plain char pointer, and not iterator based containers, like std::string or even a std::vector...
then one could write:
const ctype<char>& myctype = use_facet<std::ctype<char> >(locale(""));
string foo_str = "hi there here is a number: 748574 and text again";
vector<char> foo(foo_str.begin(),foo_str.end());
//then one could write
vector<char>::iterator num_begin_it = myctype.scan_is( ctype<char>::digit, foo.begin(), foo.end() );
vector<char> foo_num_1( foo, num_begin_it, myctype.scan_not(ctype<char>::digit, num_begin_it, foo.end() );
//instead of:
const char* num_begin_pc = myctype.scan_is(ctype<char>::digit, &foo[0], &foo[foo.size()-1]+1); // &foo[foo.size()-1]+1) instead of foo.end() is not quite readable.
vector<char> foo_num_2(num_begin_pc, myctype.scan_not(ctype<char>::digit, num_begin_pc, &foo[foo.size()-1]+1));
//appendix:
//STL/Boost solution, even more verbose:
function<bool(char)> is_digit_func =
bind(
mem_fn(static_cast<bool (ctype<char>::*)(ctype<char>::mask,char) const>(&ctype<char>::is)),
&myctype,
ctype<char>::digit,
_1
);
vector<char>::iterator num_begin_0x = find_if(foo.begin(), foo.end(),is_digit_func);
vector<char> foo_num_3(num_begin_0x,find_if(num_begin_0x, foo.end(),not1(is_digit_func)));
// all 3 foo_num_X will now contain "748574"
Would be cool if anyone has some insight why the standard committee made those design decisions ?
And is there a better (=less verbose) way to make use of the ctype functions with iterator-based containers ?
The STL/Boost solution would be kinda OK, if it wouldnt need that
Additionally i found that there is no copy_if
algorithm in the standard library, but i already the reason for this.