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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:02:06+00:00 2026-06-06T14:02:06+00:00

When iterating over a standard container, do you think it’s a good idea to

  • 0

When iterating over a standard container, do you think it’s a good idea to omit the std:: prefix and rely on ADL to find the definition? Example:

std::vector<int> vec = get_vec();
// range-based for loop would be preferred here, but just for the sake of example
for (auto it = begin(vec), end = end(vec); it != end; ++it) { /*...*/ }

Are there any reasons to do or not do 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-06-06T14:02:08+00:00Added an answer on June 6, 2026 at 2:02 pm

    If you’re going to use ADL to be able to change the container type without changing the loops, then add using std::begin; using std::end;. That makes sure it finds the std functions for containers from other namespaces that have begin and end members, but no free functions in their namespace.

    namespace my {
        template <typename T>
        struct container {
            // ... stuff
            iterator begin();
            iterator end();
        };
        // no begin/end free functions
    }
    
    
    my::container<int> vec = get_vec();
    using std::begin;
    using std::end;
    for (auto it = begin(vec), end = end(vec); it != end; ++it) { /*...*/ }
    // defaults to std::begin which defaults to .begin() member function
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Iterating over a vector works: std::vector<int> collection = {2, 3, 4, 5435345, 2}; std::for_each(collection.begin(),
When iterating over std::map<X,std::vector<Y> > , may I sort the vectors, or might that
I'm iterating over a JRE Collection which enforces the fail-fast iterator concept, and thus
I want avoid iterating over a nil array. My bad solution: if nil!=myArr myArr.each
I have the following issue related to iterating over an associative array of strings
Is there a better shorter way than iterating over the array? int[] arr =
Starting from Visual Studio 2010, iterating over a set seems to return an iterator
I need a function, which is capable of iterating over the collection, calling a
To access the values id1 & id2 im iterating over every value in the
I have a class (foo) that contains a vector. If i try iterating over

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.