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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:19:50+00:00 2026-06-15T20:19:50+00:00

Is decltype(*it) the value type of the iterator, or an lvalue reference to that,

  • 0

Is decltype(*it) the value type of the iterator, or an lvalue reference to that, or something else?

I think it is an lvalue reference, because *it is an lvalue, but I’m not sure.

Note: In my case, it is a BidirectionalIterator, but feel free to answer the general case.

  • 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-15T20:19:51+00:00Added an answer on June 15, 2026 at 8:19 pm

    *it is not necessarily an lvalue. Only forward iterators have that requirement.

    Iterators (§24.2.2) are required to have *it be a valid expression that returns iterator_traits<Iterator>::reference (and other irrelevant things). Nothing else is said about this and reference does not have to be a reference type†.

    Input iterators (§24.2.3) are required to have *it be a valid expression that returns something convertible to the value type.

    Forward iterators, however, have the following requirement (§24.2.5 paragraph 1):

    — if X is a mutable iterator, reference is a reference to T; if X is a const iterator, reference is a reference to const T,

    (here T is the iterator’s value type)

    This requires *it to be a reference, which means it has to be a glvalue (i.e. cannot be a prvalue but can be an xvalue like it is the case with move iterators).

    The higher iterator categories do not add any relevant requirements.


    † reference is defined to be the type of *it which makes it a bit of a circular definition, but poses no restrictions.

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

Sidebar

Related Questions

I needed to use the std::is_assignable type traits, which happens not to be available
It appears that to test for const-ness, one must test the template-parameter, but to
Possible Duplicate: trailing return type using decltype with a variadic template function I want
Possible Duplicate: trailing return type using decltype with a variadic template function I'm getting
Take an C++ integral variable i , and suppose that you're multiplying its value
I know about value_type, key_type... but they operate on types, not on instances. I
auto lambda = [](){ return 7; }; std::result_of<decltype(lambda)()>::type val = lambda(); // 'val' :
Consider the following code: int&& x = 42; static_assert(std::is_same<decltype( x ), int&&>::value, &&); static_assert(std::is_same<decltype((x)),
I'm attempting to solve a problem in which decltype will greatly simplify things, but
struct C { int Foo(int i) { return i; } typedef decltype(C::Foo) type; };

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.