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

Why wasn't the Night King naked in S08E03?

Can Infinity Stones be retrieved more than once?

Can an isometry leave entropy invariant?

Shantae Dance Matching

Can a nothic's Weird Insight action discover secrets about a player character that the character doesn't know about themselves?

How to model the curly cable part of the phone

Why are prions in animal diets not destroyed by the digestive system?

As matter approaches a black hole, does it speed up?

Has a commercial or military jet bi-plane ever been manufactured?

Would Hubble Space Telescope improve black hole image observed by EHT if it joined array of telesopes?

String won't reverse using reverse_copy

Out of scope work duties and resignation

How does this change to the opportunity attack rule impact combat?

Why is Arya visibly scared in the library in S8E3?

What was the design of the Macintosh II's MMU replacement?

Getting a W on your transcript for grad school applications

Why do people keep telling me that I am a bad photographer?

What are the differences between credential stuffing and password spraying?

What does this colon mean? It is not labeling, it is not ternary operator

Pressure inside an infinite ocean?

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

How do I overfit?

Fitch Proof Question

Does a card have a keyword if it has the same effect as said keyword?



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)
(nb == 1) );
return ranges::yield(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)
(nb == 1) );
return ranges::yield(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)
(nb == 1) );
return ranges::yield(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)
(nb == 1) );
return ranges::yield(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

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript