range-v3: strange BehaviorUndefined, unspecified and implementation-defined behaviorUndefined behavior and sequence pointsclang “hello, world!” link errors in windowsCan code that is valid in both C and C++ produce different behavior when compiled in each language?Strange definitions of TRUE and FALSE macrosHow do I write a range pipeline that uses temporary containers?Function works when not in namespace else it breaksranges of ranges to vector of vectorsWhen is a class member visible?Problem with stateful lambda - Microsoft Compiler Version 19.16.27024.1

What are the differences between credential stuffing and password spraying?

Purpose of のは in this sentence?

Using field size much larger than necessary

I need a disease

Verb "geeitet" in an old scientific text

Lie super algebra presentation of the Kähler identities

Can my company stop me from working overtime?

Do Maps have an Reliable Relationship between keySet() order and values() order?

What is the most remote airport from the center of the city it supposedly serves?

If your medical expenses exceed your income does the IRS pay you?

Can you complete the sequence?

Can there be a single technologically advanced nation, in a continent full of non-technologically advanced nations?

How should I tell my manager I'm not paying for an optional after work event I'm not going to?

Point of the the Dothraki's attack in GoT S8E3?

A mathematically illogical argument in the derivation of Hamilton's equation in Goldstein

What does a spell range of "25 ft. + 5 ft./2 levels" mean?

String won't reverse using reverse_copy

how to ban all connection to .se and .ru in the hosts.deny-file

If I readied a spell with the trigger "When I take damage", do I have to make a constitution saving throw to avoid losing Concentration?

Is this homebrew life-stealing melee cantrip unbalanced?

Hyperlink on red background

How do I tell my manager that his code review comment is wrong?

How can I get a job without pushing my family's income into a higher tax bracket?

In Avengers 1, why does Thanos need Loki?



range-v3: strange Behavior


Undefined, unspecified and implementation-defined behaviorUndefined behavior and sequence pointsclang “hello, world!” link errors in windowsCan code that is valid in both C and C++ produce different behavior when compiled in each language?Strange definitions of TRUE and FALSE macrosHow do I write a range pipeline that uses temporary containers?Function works when not in namespace else it breaksranges of ranges to vector of vectorsWhen is a class member visible?Problem with stateful lambda - Microsoft Compiler Version 19.16.27024.1






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








1















I am trying to play with range-v3 and I encountered a problems : it does not extract values from a vector as I would have wanted.



See the code below:



  1. When running, it outputs (0, 0), instead of what I would have thought, i.e (1, 0)


  2. If I uncomment the line auto pairs = ..., then the result is changed, and the output becomes (33144464,0), although the variable pairs is unused (and the assert will fail)


#include <iostream>
#include <vector>
#include <range/v3/all.hpp>

auto foo()

auto values = std::vector<int> 1, 0 ;
// auto pairs = std::vector< std::pair<int, int> > 1, 0 , 0, 1 , 0, 0 ;

return ranges::view::for_each(values, [=](int nb)
);



int main()

ranges::for_each(foo(), [](auto v)
std::cout << v << "n";
);



This code was compiled with g++ (g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0) and clang++ (clang version 8.0.0 (tags/RELEASE_800/final)) with the following commands:



g++ foo.cpp -std=c++14 -Irange-v3/include -Wall -Wpedantic
clang++ foo.cpp -std=c++14 -Irange-v3/include -Wall -Wpedantic


I am using a fresh clone for ranges-v3, and I can reproduce this on ubuntu and OSX (with AppleClang).










share|improve this question



















  • 4





    I suspect it’s because values has ceased to exist by the time you try to access it through the view.

    – molbdnilo
    Mar 22 at 22:25

















1















I am trying to play with range-v3 and I encountered a problems : it does not extract values from a vector as I would have wanted.



See the code below:



  1. When running, it outputs (0, 0), instead of what I would have thought, i.e (1, 0)


  2. If I uncomment the line auto pairs = ..., then the result is changed, and the output becomes (33144464,0), although the variable pairs is unused (and the assert will fail)


#include <iostream>
#include <vector>
#include <range/v3/all.hpp>

auto foo()

auto values = std::vector<int> 1, 0 ;
// auto pairs = std::vector< std::pair<int, int> > 1, 0 , 0, 1 , 0, 0 ;

return ranges::view::for_each(values, [=](int nb)
);



int main()

ranges::for_each(foo(), [](auto v)
std::cout << v << "n";
);



This code was compiled with g++ (g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0) and clang++ (clang version 8.0.0 (tags/RELEASE_800/final)) with the following commands:



g++ foo.cpp -std=c++14 -Irange-v3/include -Wall -Wpedantic
clang++ foo.cpp -std=c++14 -Irange-v3/include -Wall -Wpedantic


I am using a fresh clone for ranges-v3, and I can reproduce this on ubuntu and OSX (with AppleClang).










share|improve this question



















  • 4





    I suspect it’s because values has ceased to exist by the time you try to access it through the view.

    – molbdnilo
    Mar 22 at 22:25













1












1








1


1






I am trying to play with range-v3 and I encountered a problems : it does not extract values from a vector as I would have wanted.



See the code below:



  1. When running, it outputs (0, 0), instead of what I would have thought, i.e (1, 0)


  2. If I uncomment the line auto pairs = ..., then the result is changed, and the output becomes (33144464,0), although the variable pairs is unused (and the assert will fail)


#include <iostream>
#include <vector>
#include <range/v3/all.hpp>

auto foo()

auto values = std::vector<int> 1, 0 ;
// auto pairs = std::vector< std::pair<int, int> > 1, 0 , 0, 1 , 0, 0 ;

return ranges::view::for_each(values, [=](int nb)
);



int main()

ranges::for_each(foo(), [](auto v)
std::cout << v << "n";
);



This code was compiled with g++ (g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0) and clang++ (clang version 8.0.0 (tags/RELEASE_800/final)) with the following commands:



g++ foo.cpp -std=c++14 -Irange-v3/include -Wall -Wpedantic
clang++ foo.cpp -std=c++14 -Irange-v3/include -Wall -Wpedantic


I am using a fresh clone for ranges-v3, and I can reproduce this on ubuntu and OSX (with AppleClang).










share|improve this question
















I am trying to play with range-v3 and I encountered a problems : it does not extract values from a vector as I would have wanted.



See the code below:



  1. When running, it outputs (0, 0), instead of what I would have thought, i.e (1, 0)


  2. If I uncomment the line auto pairs = ..., then the result is changed, and the output becomes (33144464,0), although the variable pairs is unused (and the assert will fail)


#include <iostream>
#include <vector>
#include <range/v3/all.hpp>

auto foo()

auto values = std::vector<int> 1, 0 ;
// auto pairs = std::vector< std::pair<int, int> > 1, 0 , 0, 1 , 0, 0 ;

return ranges::view::for_each(values, [=](int nb)
);



int main()

ranges::for_each(foo(), [](auto v)
std::cout << v << "n";
);



This code was compiled with g++ (g++ (Ubuntu 7.3.0-27ubuntu1~18.04) 7.3.0) and clang++ (clang version 8.0.0 (tags/RELEASE_800/final)) with the following commands:



g++ foo.cpp -std=c++14 -Irange-v3/include -Wall -Wpedantic
clang++ foo.cpp -std=c++14 -Irange-v3/include -Wall -Wpedantic


I am using a fresh clone for ranges-v3, and I can reproduce this on ubuntu and OSX (with AppleClang).







c++ range-v3






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 22 at 22:18







Pascal T.

















asked Mar 22 at 22:13









Pascal T.Pascal T.

2,01332529




2,01332529







  • 4





    I suspect it’s because values has ceased to exist by the time you try to access it through the view.

    – molbdnilo
    Mar 22 at 22:25












  • 4





    I suspect it’s because values has ceased to exist by the time you try to access it through the view.

    – molbdnilo
    Mar 22 at 22:25







4




4





I suspect it’s because values has ceased to exist by the time you try to access it through the view.

– molbdnilo
Mar 22 at 22:25





I suspect it’s because values has ceased to exist by the time you try to access it through the view.

– molbdnilo
Mar 22 at 22:25












1 Answer
1






active

oldest

votes


















0














There is a experimental feature coming in clang called -Wlifetime that can be used on godbolt. It gives the following warnings pointing to the return from foo.



[x86-64 clang (experimental -Wlifetime) #1] warning: returning a dangling Pointer [-Wlifetime]
[x86-64 clang (experimental -Wlifetime) #1] note: pointee 'values' left the scope here





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308446%2frange-v3-strange-behavior%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    There is a experimental feature coming in clang called -Wlifetime that can be used on godbolt. It gives the following warnings pointing to the return from foo.



    [x86-64 clang (experimental -Wlifetime) #1] warning: returning a dangling Pointer [-Wlifetime]
    [x86-64 clang (experimental -Wlifetime) #1] note: pointee 'values' left the scope here





    share|improve this answer



























      0














      There is a experimental feature coming in clang called -Wlifetime that can be used on godbolt. It gives the following warnings pointing to the return from foo.



      [x86-64 clang (experimental -Wlifetime) #1] warning: returning a dangling Pointer [-Wlifetime]
      [x86-64 clang (experimental -Wlifetime) #1] note: pointee 'values' left the scope here





      share|improve this answer

























        0












        0








        0







        There is a experimental feature coming in clang called -Wlifetime that can be used on godbolt. It gives the following warnings pointing to the return from foo.



        [x86-64 clang (experimental -Wlifetime) #1] warning: returning a dangling Pointer [-Wlifetime]
        [x86-64 clang (experimental -Wlifetime) #1] note: pointee 'values' left the scope here





        share|improve this answer













        There is a experimental feature coming in clang called -Wlifetime that can be used on godbolt. It gives the following warnings pointing to the return from foo.



        [x86-64 clang (experimental -Wlifetime) #1] warning: returning a dangling Pointer [-Wlifetime]
        [x86-64 clang (experimental -Wlifetime) #1] note: pointee 'values' left the scope here






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 24 at 15:36









        sv90sv90

        30339




        30339





























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55308446%2frange-v3-strange-behavior%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현