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

  • Home
  • SEARCH
  • 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 8570183
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:30:04+00:00 2026-06-11T18:30:04+00:00

Possible Duplicate: Why does the C++ standard algorithm “count” return a ptrdiff_t instead of

  • 0

Possible Duplicate:
Why does the C++ standard algorithm “count” return a ptrdiff_t instead of size_t?

There is algorithm std::count/std::count_if in standard C++.

template<class InputIterator, class T>
typename iterator_traits<InputIterator>::difference_type
count(InputIterator first, InputIterator last, const T& value);

template<class InputIterator, class Predicate>
typename iterator_traits<InputIterator>::difference_type
count_if(InputIterator first, InputIterator last, Predicate pred);

Effects: Returns the number of iterators i in the range [first,last) for which the following corresponding
conditions hold: *i == value, pred(*i) != false.

difference_type is iterator's difference_type, which can be negative, but count can return only value >= 0. Why difference_type and not size_t for example?

  • 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-06-11T18:30:05+00:00Added an answer on June 11, 2026 at 6:30 pm

    In theory you may have a tremendous sequence whose number of elements can only be represented with 128 bits. Assuming the implementation supports a corresponding integer type, it is quite likely that size_t use a 64 bit type. However, the iterator for this huge sequence could use a 128 bit integer. Note, that the sequence isn’t necessary represented in the memory of any individual computer. It may be split across multiple huge databases.

    You might also have a relatively small computer supporting only a 32 bit type with reasonable performance. For full standard conformance it might have to support a 64 bit type but it can be desirable to rather support faster computations using a representation natively supported by the platform. That is, size_t may not be the optimal choice. When creating iterators you generally know what size needs to be supported.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What does “(void) new” mean in C++? I'm not familiar with C++
Possible Duplicate: JavaScript === vs == : Does it matter which “equal” operator I
Possible Duplicate: ImproperlyConfigured: Middleware module “django.middleware.csrf” does not define a “CsrfResponseMiddleware” class I am
Possible Duplicate: Why does (“foo” === new String(“foo”)) evaluate to false in JavaScript? Over
Possible Duplicate: Does it make sense to use the <table> tag on a “modern”
Possible Duplicate: “Web interface” to PHPUnit tests? Are there any PHP unit testing systems
Possible Duplicate: CSS @font-face - what does “src: local('☺')” mean? Hi, I came across
Possible Duplicate: Does there exist a static_warning? I often use #warning scattered through my
Possible Duplicate: Does std::list::remove method call destructor of each removed element? I have a
Possible Duplicate: “No newline at end of file” compiler warning i am a Linux

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.