Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 927041
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T19:47:15+00:00 2026-05-15T19:47:15+00:00

Is there any reason that the ctype facet functions ( is , scan_is ,

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T19:47:15+00:00Added an answer on May 15, 2026 at 7:47 pm

    The main reason is that the Standard Library wasn’t developed as a single coherent whole, but incorporates several libraries that were popular at the time.

    Iterators were a concept from the “Standard Template Library”, which was the basis for the standard Containers, Iterators and Algorithms libraries. The Strings and Localization libraries came from other sources, which did not use iterators. Because iterators are so useful, it was deemed worth the effort of retrofitting them to these libraries, but not to completely change the libraries’ interfaces to use iterators everywhere.

    By the way, you might find &foo.back()+1 or &foo[0] + foo.size() to be more readable than &foo[foo.size()-1]+1. You also don’t need to copy the string into a vector to use scan_is and scan_not; something like this should do the job:

    const char* str_begin = foo_str.c_str();
    const char* str_end   = str_begin + foo_str.length();
    const char* num_begin = myctype.scan_is(ctype<char>::digit, str_begin, str_end);
    const char* num_end   = myctype.scan_not(ctype<char>::digit, num_begin, str_end);
    std::string number(num_begin, num_end); // or `vector` if you really want
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there any reason for automating tests that focus on GUI (and not to
Is there any specific reason why has support for designated initializers not been added
Is there any particular reason that all data members in a class are private
I like to know is there any specific reason that there is no public
Is there any design reason for that (like the reason they gave up multi
Is there a historic reason that periods are used instead of any other separator
Is there any reason why images are not being displayed if I place it
Is there any reason that will make you use: add2 = lambda n: n+2
Is there any reason that the compiler cannot optimize the following 2 statements out
Is there any reason that data pulled in from a plist will show in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.