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 7447527
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T12:37:49+00:00 2026-05-29T12:37:49+00:00

I have a sorted std::vector<unsigned long long int> myvector (and all values are different).

  • 0

I have a sorted std::vector<unsigned long long int> myvector (and all values are different).

What is the shortest way to find the value of the first index size_t idx (not an iterator) of myvector strictly > to MAX_UI32 = 4294967295U.

For example :

[1, 34, 83495, 4294967295, 4294967296, 104000000000] -> idx = 4
[1, 34, 83495, 923834, 912834823, 4294967295] -> idx = 6 (= size of myvector)

How to achieve this in one line of code ?

Thank you very much.

  • 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-29T12:37:51+00:00Added an answer on May 29, 2026 at 12:37 pm

    A combination of upper_bound and distance should do the trick:

    #include <algorithm>
    #include <iterator>
    #include <vector>
    
    std::vector<unsigned long long int> v;
    
    // ...
    
    return std::distance(v.begin(),
                         std::upper_bound(v.begin(), v.end(), MAX_UI32));
    

    If there is no such element, upper_bound returns v.end(), so your result will equal v.size().

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

Sidebar

Related Questions

Suppose I have the following two data structures: std::vector<int> all_items; std::set<int> bad_items; The all_items
I have sorted CFArray, and I need to find the index of a value.
I have a std::vector<std::pair<int,std::pair<Bone,std::string> > > I'm trying to sort it with std sort,
I have a sorted dictionary where the key is a date and the value
I have a N-Ary non sorted in any way tree and each node can
How large does a collection have to be for std::map to outpace a sorted
I have a std::vector<std::string> which would contain numbers and characters (single char). I would
I have some data that is stored in a sorted vector. This vector is
Greetings, Any input on a way to divide a std::vector into two equal parts
Suppose you have a sorted range (x to y) of values in an array.

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.