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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:08:25+00:00 2026-05-26T23:08:25+00:00

First: my apologies if I am getting the nomenclature wrong! Basically, I have a

  • 0

First: my apologies if I am getting the nomenclature wrong!

Basically, I have a not-too-uncommon desire to declare a stack based container, such as:

std::map<CString, size_t> ecounts;

Then I want to iterate over the contents of ecounts a little further down in the function body, but I really don’t want to have to typedef a bunch of things, nor retype the above types in order to get the compiler to work with what I have…

std::foreach(ecounts.begin(), ecounts.end(), [&] (>>>here is the problem<<< e)
{
  ... whatever I want to do with e ...
}

Of course, I can either use typedefs, or my knowledge of the declaration of ecounts manually:

std::foreach(ecounts.begin(), ecounts.end(), [&] (std::pair<CString,size_t> e)
...

But, yuck! I’d much rather have a single declaration of what ecounts is, and just use it’s value_type somehow. But this seems not to work:

std::foreach(ecounts.begin(), ecounts.end(), [&] (decltype(ecounts)::value_type e)
...

Is this just a limitation of my compiler (vs2010), or is this a limitation of C++?

How might I go about making a sort of One Definition Rule to such code, preferably without having to use typedefs to achieve it (i.e., I can do the following):

typedef std::map<CString, size_t> maptype;
typedef maptype::value_type valuetype;
maptype ecounts;
...
std::foreach(ecounts.begin(), ecounts.end(), [&] (valuetype e)
...

This is not the end of the world, obviously, but if I can use decltype, I’d be happier with the resulting reduction in thinking & backtracking to achieve the above…

  • 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-26T23:08:26+00:00Added an answer on May 26, 2026 at 11:08 pm

    Limitation of VS2010, as the addition you want came into the standard too late for it. It should compile with a conformant compiler. As a workaroung, just use decltype(*ecounts.begin()) e. Or an identity template:

    template<class T>
    struct identity{ typedef T type; };
    // usage: identity<decltype(ecounts)>::type::value_type
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

First off - apologies for the poor title, I have no idea how to
First, apologies,this should be simple but I've had too much coffee and cannot wrap
My apologies if this question is too general, as this is my first time
My apologies if it is quite confusing. I have this two main interfaces. First
Apologies, I am completely new to Django and Python. I have 2 questions. First,
First - apologies for the fuzzy title, I could not find a better one.
First of all my apologies to those of you who would have followed my
First of all, my apologies for the title of this question, I don't have
First off, apologies for the length... I have a Host/Plugin application akin to MAF.
I searched first, so apologies if it's already been asked. I have a couple

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.