Questions tagged [std-tie]

6 questions
123
votes
3 answers

std::ignore with structured bindings?

Prelude: std::tuple f(); std::tuple g(); C++1z will introduce syntax for structured bindings which will make it possible to write instead of int a, b, c; std::tie(a, b, c) = f(); something like auto [a, b, c] =…
jotik
  • 17,044
  • 13
  • 58
  • 123
4
votes
1 answer

Adding the : in front of variable gives wrong result

I am comparing the class. For the below code #include #include #include #include enum class e : bool { positive = true, negetive = false }; class A { public: int a; e e1 : 1; friend bool…
Swapnil
  • 1,424
  • 2
  • 19
  • 30
4
votes
1 answer

Why structured binding fails with 'std::tie' d objects?

I was curious to do this asked problem in the following way: #include #include #include #include #include #include int main() { const std::set s{ 0, 1, 2, 3, 4, 5, 6, 7, 8 }; …
JeJo
  • 30,635
  • 6
  • 49
  • 88
1
vote
1 answer

Using std::tie with bit fields seems to fail

I have the following code in C++17 in which I am defining a struct which is a bit mask and has member variables which are bit fields of type bool. I am defining a tie function so that I can convert it to a comparable std::tuple object, which can be…
nyarlathotep108
  • 5,275
  • 2
  • 26
  • 64
1
vote
3 answers

Are there downsides with using std::tie for golang-like error-handling while also returning a result? (C++11)

In go a common way to do error handling and still return a value is to use tuples. I was wondering if doing the same in C++ using std::tie would be a good idea when exceptions are not applicable. like std::tie(errorcode, data) =…
Jimmy R.T.
  • 1,314
  • 1
  • 10
  • 13
0
votes
0 answers

Is there something like `std::tie` for passing values from returned struct into existing variables?

I had a code like: std::tie(info.amount, info.price) = GetAmountAndPrice(); and the GetAmountAndPrice was returning std::pair so it worked. But there was a code review suggesting to change the return type to struct so it's clear what the returned…
Lukas Salich
  • 959
  • 2
  • 12
  • 30