Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve auto&& #6

Closed
andreasfertig opened this issue May 18, 2018 · 0 comments
Closed

Improve auto&& #6

andreasfertig opened this issue May 18, 2018 · 0 comments

Comments

@andreasfertig
Copy link
Owner

The example for range-based for-loops on the about page transforms this piece of code:

#include <cstdio>

int main()
{
    const char arr[]{2,4,6,8,10};

    for(const char& c : arr)
    {
      printf("c=%c\n", c);
    }
}

into this:

#include <cstdio>

int main()
{
    const char arr[]{2,4,6,8,10};

    {
       auto&& __range1 = arr;
       const char * __begin1 = __range1;
       const char * __end1 = __range1 + 5l;
       
       for( ; __begin1 != __end1; ++__begin1 )
       {
         const char & c = *__begin1;
         printf("c=%c\n", static_cast<int>(c));
       }
     }
}

Leaving the auto&& __range1 = arr; is wrong as it was pointed out here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant