2

Why C++17 structured binding do not like the this-> operator in is a syntax like this one :

std::tuple<int, std:string> external_function()
{
    return { 0, "" };
}

class Foo
{
public:
    void internal_method()
    {
        auto [this->x, unused] = external_function();
    }

private:
    int x;
};

How to add a class member specifier to the returned variable names?

Barry
  • 286,269
  • 29
  • 621
  • 977
MaxC2
  • 343
  • 3
  • 10
  • 5
    From what I understand structured bindings are supposed to introduce new local variables, not assign multiple returned values to multiple existing variables. – user7860670 Jan 07 '18 at 15:01
  • So that's why the compiler (vs2017 in my case) do not like the `this->` operator. It's bad to add a simplification enhancement and do not allow to do this type of operation. Thank you for your answer – MaxC2 Jan 07 '18 at 15:06
  • 3
    @MaximeCoorevits: For existing variables, `std::tie` is still an option, but yes, there is a gap between "all existing" and "all non-existent" that isn't covered. – ShadowRanger Jan 07 '18 at 15:20
  • 1
    @MaximeCoorevits: "*Structured binding only create local variable and do not allow a direct access to class member.*" No, Structured binding only creates local variables, and therefore cannot assign to *any* existing variable, whether a class member, global, local, etc. That's why your question is a duplicate; class members are a subset of "any existing variable". – Nicol Bolas Jan 07 '18 at 16:10
  • @Nicol Bolas. Thank you. Do I need delete my question? – MaxC2 Jan 07 '18 at 16:12
  • 1
    @MaximeCoorevits: There's nothing wrong with a duplicate. Some are even quite useful, since searching can lead to the original question. – Nicol Bolas Jan 07 '18 at 16:15
  • @Nicol Bolas. Thank you. Have a good day. – MaxC2 Jan 07 '18 at 16:21

0 Answers0