Thread: Providing my own simple iterators

  1. #31
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by MutantJohn View Post
    Gratned, std::move()'s semantics are entirely over my head. I miss the days when l- and r-value references really were just left and right lol.
    It's not that difficult. Well, the basics anyway. You can think of it as all temporaries are r-values and everything else is l-values. R-value references are also l-values.
    You can make an l-value into an r-value with std::move. This can be used with local variables, for example.
    R-values sort of says "I'm going to be disposed shortly, so you may steal my state." For vectors, this is easy since you can copy over the pointer and size and set the temporary vector's pointer to null.
    But consider a coordinate struct. What state do you need to have in the new struct? Everything. So you must copy over all bytes. Hence, in this case, moving doesn't really help.
    For advances uses, you can refer to perfect forwarding, which utilizes "universal references."
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  2. #32
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    Returning a local variable is an implicit move in C++11, so you don't need to do it.
    O_o

    This is true, but there is even more to the situation.

    Most C++ compilers, even C++98, implement "RVO" which will, somehow, eliminate the copy.

    With C++11, compilers will default to move semantics if available, but may even eliminate the call to the move constructor.

    Code:
    /* semantically */
    void make_point(float x, float y, float z, point * hidden_rvo_this) {
        point::point(hidden_rvo_this, x, y, z);
    }
    [Edit]
    Code:
    /* extending the original example */
    int main()
    {
        point s(make_point(0.0f, 0.0f, 0.0f));
    }
    Code:
    /* may result in something more like this with rvo */
    iint main()
    {
        char s_hidden[sizeof(point)];
        make_point(0.0f, 0.0f, 0.0f, s);
        point & s(s_hidden);
    }
    [/Edit]

    The example, mutated for explanation from post #27, shows the sort of thing a compiler may do instead of an actual "return" value.

    Most compilers will very likely eliminate the copy if you don't specify `std::move' so don't use it for such cases; you may even force a constructor call using `std::move' in such a case depending on the compiler.

    Soma
    Last edited by phantomotap; 04-27-2014 at 12:42 PM.
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  3. #33
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    The Point can have as many coordinates as the user wants. Thanks for the all the answers, but I accomplished what I was asked too.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  4. #34
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by std10093 View Post
    The Point can have as many coordinates as the user wants.
    Then it's not a point anymore. Unless you are talking about being able to specify the dimension the point exists in.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #35
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    Quote Originally Posted by Elysia View Post
    Then it's not a point anymore. Unless you are talking about being able to specify the dimension the point exists in.
    The dimension is an argument of the constructor.

    :O
    I know saw Soma's post. Where did I say I am good in C++? I am learning.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  6. #36
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    I think it's more your attitude than anything. And how you always make these topics that are secretly homework assignments and then never give enough relevant details. And then when people probe for more information or point out a logical fallacy, you act like you know better and that what you want to do is right even though you directly asked for help. It's exactly that, asking for help and then dismissing it.

  7. #37
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    What? Did I act like knowing better? :P Moreover, it's not for homework. Anyway, these kind of discussions destroy the archive concept.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  8. #38
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by MutantJohn View Post
    I think it's more your attitude than anything. And how you always make these topics that are secretly homework assignments and then never give enough relevant details. And then when people probe for more information or point out a logical fallacy, you act like you know better and that what you want to do is right even though you directly asked for help. It's exactly that, asking for help and then dismissing it.
    Eh, I'm siding with std10093 here. I see no harm. I see it as a member, std10093, who is not super proficient in C++ coming seeking help from other members here.
    We all have our flaws. We may not always go about asking for help the right way (hey, it happens, right?), but I haven't seen any attitude that says that std is trying to act superior or ignore advice on purpose.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #39
    Master Apprentice phantomotap's Avatar
    Join Date
    Jan 2008
    Posts
    5,108
    I think it's more your attitude than anything. And how you always make these topics that are secretly homework assignments and then never give enough relevant details. And then when people probe for more information or point out a logical fallacy, you act like you know better and that what you want to do is right even though you directly asked for help. It's exactly that, asking for help and then dismissing it.
    O_o

    Could not agree more with the sentiment; third time I've been a participant in his crap.

    Eh, I'm siding with std10093 here. I see no harm.
    Really? You see no harm?

    Code:
    std10093: I need help with 'x'.
    community: Here is an example of 'x'.
    std10093: That will not work.
    community: Why?
    std10093: Example where 'x' doesn't work.
    community: That isn't 'x'; that is 'y'. What are you really doing?
    std10093: Let me give you some faulty logic why my example is 'x'; I'm going to do this because I want to ignore your questions.
    community: You are wrong. Let me provide many reasons that 'x' is actually 'y'. Now, what are you really doing?
    std10093: Okay. Fine, let's us pretend that is 'y'. How do I 'y'?
    community: Here is how you 'y'. What are you really doing?
    std10093: I can't use 'y'; I didn't tell you that sooner because I didn't think it was relevant.
    You see that last bit?

    Time and time again in these threads he has been told to provide more information yet does not provide the requested information.

    Soma
    “Salem Was Wrong!” -- Pedant Necromancer
    “Four isn't random!” -- Gibbering Mouther

  10. #40
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by phantomotap View Post
    Really? You see no harm?
    I still see no harm. Perhaps because I am lenient that others. Perhaps because I don't often look inter-posts and quickly forget who posted what. No peeking in history, so to speak.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  11. #41
    Lurking whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    9,612
    Quote Originally Posted by Elysia View Post
    I still see no harm. Perhaps because I am lenient that others. Perhaps because I don't often look inter-posts and quickly forget who posted what. No peeking in history, so to speak.
    History doesn't have to matter. I don't have a lot of experience with him asking questions, but I have talked to him a lot. This is some of the poorest communication I've seen std19003 do in a long time. I would certainly appreciate it if he put more effort into explaining his goal next time. It is really silly that he picked this problem to learn about iterators and it was dangerously close to not being appropriate to apply them. What bothers me is that we weren't able to figure that out until page 2. He wastes his own time and potentially risks leaving with a piecemeal answer, the answer of the worst kind, by not being clear. He harms himself as much as anyone else.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. a library or API providing direct access to a running PE address space
    By renzokuken01 in forum Windows Programming
    Replies: 9
    Last Post: 05-24-2009, 01:40 PM
  2. Help with C# iterators
    By dudeomanodude in forum C# Programming
    Replies: 1
    Last Post: 04-28-2008, 03:23 AM
  3. Providing access to member variables between classes
    By Tonto in forum C++ Programming
    Replies: 11
    Last Post: 06-19-2006, 01:06 PM
  4. providing a GUI...novice!
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 05-20-2002, 09:05 AM