u/memset_0

644 post karma · 69 comment karma · joined Aug 2016

  1. 31points

    std::jthread and cooperative cancellation with stop token (nextptr.com)

    6 comments · source

  2. 17points

    std::variant as a map key and std::hash (nextptr.com)

    3 comments · source

  3. 101points

    std::any - comparison with void* and motivating examples (nextptr.com)

    41 comments · source

  4. 7points

    C++ | std::list splice for implementing LRU cache (nextptr.com)

    0 comments · source

  5. 10points

    Update keys of map or set with node extract (nextptr.com)

    0 comments · source

  6. 14points

    unique_ptr, shared_ptr, weak_ptr, or reference_wrapper for class relationships (nextptr.com)

    11 comments · source

  7. 92points

    std::ref and std::reference_wrapper: common use cases (nextptr.com)

    25 comments · source

  8. 1points

    Why taking the address of an xvalue (&std::move(...)) is an error? (self.cpp)

    31 comments

  9. 18points

    Scoped (class) enums: fundamentals and examples (nextptr.com)

    1 comments · source

memset_0

Just to elaborate a little that std::any does not have compile-time type-safety. It does have run-time type check.

memset_0

Oh no, they are very different. auto is only a compile-time construct that directs the compiler to deduce a type from the available information. It saves typing and good for maintainability:

 //These 2 statements compile to the same instructions
 auto i = 10;  //i is int
 int i = 10;
 //another example 
 auto foo() { return 10LL; } //foo returns int64_t 

std::any is a standard library class that can contain any type of object. It is not a compiler feature.

memset_0

I see. So std::variant — like a union — requires a member to be an object (region of storage).

I would add this use case in the article. Thank you so much.

memset_0

Thank You!

memset_0

Sounds interesting. Can you please explain that for the benefit of everyone here? thx.

memset_0

I wish for Sockets and IO Event-Loop support at least.

What's the news flash?

memset_0

You can check out folly. It is cross platform now.

Hope C++ standard library has networking support someday.

memset_0

yes, from what i gather.

memset_0

I did not say or imply that the language should make an exception for std::move. I asked why taking the address of an xvalue is an error (std::move is the most common way to create an xvalue expression).

memset_0

This question is about getting deep into the language semantics. There is no need to oversimplify it.

std::move(x) expression is not a temporary. The reason we have std::move is to in fact explicitly tell the compiler that we want to move an lvalue. Temporaries are already movable. And, std::move does not turn an lvalue to a temporary, or move it to a different location or register.

memset_0

Your point about local variable is good.

But ‘x’ is not an xvalue in your example. it has a name. Also, it is a universal or forwarding reference, not even an rvalue reference.

https://isocpp.org/blog/2012/11/universal-references-in-c11-scott-meyers

memset_0

std::move(x) is an xvalue. so its both, an rvalue and a glvalue.

memset_0

thats what i thought. but i was hoping someone would cite a source for this reasoning. thx.

memset_0

yes. but it is a glvalue too. depends on how we look at it.

memset_0

Yeah, but my question is why is it disallowed. Why &std::move(x) is invalid when x is an lvalue.

memset_0

“The most important source of xvalues are temporary objects.”

But temporary objects are already movable (prvalues), why would they be most important source of xvalues?

string foo(); // returns temporary

string s;

s = move(foo()); //not good. why would anyone do that when foo() is already movable.

Shouldn’t the only source of xvalues be lvalues:

string c; //lvalue

string m;

m = move(c); // ok