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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:59:18+00:00 2026-06-09T00:59:18+00:00

Should it be possible to write the following code? What I’d like to do

  • 0

Should it be possible to write the following code? What I’d like to do is that the do_vector_action could automatically deduce the correct return type of the function (the code I actually have has the function defined in a cpp file, not in the header as here).

class some_class
{
    public:
        std::vector<int> int_vector;
        auto do_vector_action() -> decltype(int_vector_.size())
        {
            decltype(int_vector.size()) something + 1;
            return something;
        }
}

Moreover, I’d like also know, would it be possible to replace typedefs such as

class some_class
{
    public:
        typedef std::vector<int> int_vector_type;
        int_vector_type int_vector;
        int_vector_type::size_type size;
}

with using decltype or some other construct such as

  class some_class
  {
       public:
           std::vector<int> int_vector;
           decltype(int_vector)::size_type size;
  }

as the last snippet with decltype doesn’t compile with Visual Studio 2012 RC.

  • 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-09T00:59:20+00:00Added an answer on June 9, 2026 at 12:59 am
    decltype(int_vector.size()) something + 1;
    

    This is equivalent to:

    std::vector<int>::size_type something + 1;
    

    which is ill-formed (you are declaring a variable named something then… adding one to it?

    Your second example, using decltype(int_vector)::size_type is valid. Visual C++ 2010 and 2012 reject it due to a compiler bug(*). As a workaround, you should be able to declare size as:

    identity<decltype(int_vector)>::type::size_type size;
    

    assuming the presence of a standard identity template declared as:

    template <typename T>
    struct identity { typedef T type; };
    

    (*) The ability to use decltype in a nested name specifier was added very near the end of the C++11 standardization process (see N3031 [PDF]). This was after Visual C++ 2010 was completed, and support for this addition was not added in Visual C++ 2012.

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

Sidebar

Related Questions

Is it possible to write code like the following. I'm trying to using Moq
Is it possible to write union select queries like the following more succintly? select
Having read around it appears this should be possible. I have the following content
Can this be done? It seems like this should be possible. In general, I
hi i have write following code which prints elements in sorted order only one
I'm trying to write some replacement regex that will insert a locale code into
Possible Duplicate: Submission of form should be done when on user login Following is
I think it should be possible to add additional namespaces to the generated classes
I have read about gstreamer support for rtp and it should be possible to
I need a control having these features: It should be possible use it in

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.