Just Posted: Stephan T. Lavavej’s Advanced STL, 4 of n

Just Posted: Stephan T. Lavavej’s Advanced STL, 4 of n

  • Comments 3

The 4th part digs into rvalue references, perfect forwarding and associative containers.The 4th part of this series digs into rvalue references, perfect forwarding and associative containers.

Advanced STL covers the gory details of the STL's implementation -> you will therefore need to be versed in the basics of STL, competent in C++ (of course), and be able to pay attention! Stephan is a great teacher and we are so happy to have him on Channel 9—the only place you'll find this level of technical detail regarding the internals of the STL. There are no books. There are no websites. This is Stephan taking us into what is uncharted territory for most, even those with a more advanced STL skill set.

[Watch Part 4 in Channel 9]

 

See the previous chapters on this Advanced STL series:

Part 1 -> shared_ptr and friends
Part 2 -> Algorithm optimization
Part 3 -> STL's comprehensive correctness checks

 

New to STL? Watch the STL Introductory Series.

  • The error of rvalue references v2.0 looks like my bug report at connect.microsoft.com/.../vc10-results-of-by-value-conversion-operators-are-not-treated-as-rvalue-correctly. I suspect that bug is the same thing, and it is funny to see that this is actually a problem in the standard draft VC10 is based on. The bug is still not closed - do you have a development version that fixes rvalues v2.1 (and my bug as well)? If you do, can you please show what the sample code does using that compiler?

  • > I suspect that bug is the same thing

    It is.

    > do you have a development version that fixes rvalues v2.1 (and my bug as well)?

    Yes. (After filming Part 4, I learned that our implementation of v2.1 is incomplete - there are other cases that we still need to fix. There's an active bug tracking that.)

    > If you do, can you please show what the sample code does using that compiler?

    Here's my current build of VC11:

    C:\Temp>type kitty.cpp

    #include <stdio.h>

    #include <utility>

    using namespace std;

    struct Foo {

       Foo() { puts("Foo()"); }

       Foo(const Foo&) { puts("Foo(const Foo&)"); }

       Foo(Foo&&) { puts("Foo(Foo&&)"); }

       Foo& operator=(const Foo&) { puts("operator=(const Foo&)"); return *this; }

       Foo& operator=(Foo&&) { puts("operator=(Foo&&)"); return *this; }

       ~Foo() { puts("~Foo()"); }

    };

    struct Bar {

       operator Foo() { return Foo(); }

       Foo convert() { return Foo(); }

    };

    int main() {

       Foo foo;

       Bar bar;

       puts("----Case 1: foo = bar.convert();");

       foo = bar.convert();

       puts("----Case 2: foo = Bar();");

       foo = Bar();

       puts("----Case 3: foo = bar;");

       foo = bar;

       puts("----Case 4: foo = (Foo) bar;");

       foo = (Foo) bar;

       puts("----Case 5: foo = move(bar);");

       foo = move(bar);

       puts("----Done.");

    }

    C:\Temp>cl /EHsc /nologo /W4 /MT /O2 /GL kitty.cpp

    kitty.cpp

    Generating code

    Finished generating code

    C:\Temp>kitty

    Foo()

    ----Case 1: foo = bar.convert();

    Foo()

    operator=(Foo&&)

    ~Foo()

    ----Case 2: foo = Bar();

    Foo()

    operator=(Foo&&)

    ~Foo()

    ----Case 3: foo = bar;

    Foo()

    operator=(Foo&&)

    ~Foo()

    ----Case 4: foo = (Foo) bar;

    Foo()

    Foo(Foo&&)

    operator=(Foo&&)

    ~Foo()

    ~Foo()

    ----Case 5: foo = move(bar);

    Foo()

    operator=(Foo&&)

    ~Foo()

    ----Done.

    ~Foo()

    In Case 4, there's a temporary that VC11's not eliding, but I believe that our behavior is conformant (I'd have to look up the Standardese to prove it).

    WARNING: Don't implement operator Foo&() or operator Foo&&() returning a temporary Foo. That leads to dangling references.

  • Nice. Another feature I want VC11 asap :) ( First is the deleted constructor/assignment op support. )

Page 1 of 1 (3 items)