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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:35:35+00:00 2026-05-28T07:35:35+00:00

I absolutely love the way Xcode offers insight into possible available member functions of

  • 0

I absolutely love the way Xcode offers insight into possible available member functions of the language and would prefer to use it relative to, say, text mate, if not for an oddity i noticed today.

When string s = "Test string"; the only available substr signature is as shown

enter image description here

From what i understand however, and what i see online the signature should be

string substr ( size_t pos = 0, size_t n = npos ) const;

Indeed s.substr(1,2); is both understood and works in Xcode.

Why does it not show when i try to method complete? (Ctrl-Space)

  • 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-28T07:35:36+00:00Added an answer on May 28, 2026 at 7:35 am

    Xcode is performing the completion correctly, but it’s not what you expect. You’ve actually answered the question yourself unknowingly. The function signature for string‘s substr() method, just as you said, is:

    string substr ( size_t pos = 0, size_t n = npos ) const;
    

    All arguments to substr() have default assignments, therefore to Xcode, s.substr() (with no arguments) is the valid code completion to insert because it’s really s.substr(0, s.npos). You can confirm this with any number of standard C++ functions with default arguments. The easiest place to see this is with any STL container constructor.

    Take for instance a vector. We all know that vectors can take an Allocator, but the default argument assigned Allocator is “good enough” for most casual uses. Sure enough, two of the signatures for vector constructors are:

    explicit vector ( const Allocator& = Allocator() );
    explicit vector ( size_type n, const T& value= T(), const Allocator& = Allocator() );
    

    In both cases, the Allocator argument has a default assignment, and in the second, the T default value has a default assignment. Now, take a look at what Xcode suggests when constructing a vector:

    Xcode 4.2.1 Code Completions for vector constructor

    The suggestion with no argument list is actually the constructor that takes just an Allocator. The suggestion that takes just a size_type is actually the constructor that takes a size_type, T, and Allocator.

    Depending on how you think about this, it may or may not be an Xcode bug. Ideally, you want to see completions with default arguments for simpler functions like substr(), but for STL container constructors, you probably almost never want to see them. Perhaps it could be an option, but I wouldn’t expect to see this corrected. I’d happily dup a radar with you though.

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

Sidebar

Related Questions

I'm absolutely in love with the way GWT does RPC. Is there anything similar
I absolutely love maths (or 'math' as most of you would say!) but I
I absolutely love StackOverflow's usage of OpenID for registration. How would I go about
I absolutely love the Source Code Ouliner power toy that I use in VS2005
How practical would it be to use Cython as the primary programming language for
I absolutely love good defender games (e.g. Gemcraft, Protector: reclaiming the throne) as they
I absolutely loved Dive Into Python when I picked up Python. In fact, tutorials
How to make absolutely original salt for every user? Is it better to use
I am getting started on the Moq framework and absolutely love it. I am
I absolutely love the Code Folding feature inside Delphi 2010. However, each time start

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.