Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8960755
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T15:43:49+00:00 2026-06-15T15:43:49+00:00

std::tie returns a tuple of references, so you can do the following: int foo,

  • 0

std::tie returns a tuple of references, so you can do the following:

int foo, bar, baz;
std::tie(foo, bar, baz) = std::make_tuple(1, 2, 3);

This is similar to foo, bar, baz = (1, 2, 3) in Python.

What is supposed to happen if one of the assignments throws, as in the following example?

int foo = 1337;
struct Bar {
    Bar& operator=(Bar) { throw std::exception{}; }
} bar;
try {
    std::tie(foo, bar) = std::make_tuple(42, Bar{});
} catch (std::exception const&) {
    std::cout << foo << '\n';
}

Will it print 1337 or 42, or is this unspecified?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T15:43:50+00:00Added an answer on June 15, 2026 at 3:43 pm

    The Standard speaks of tuple assignment art §20.4.2.2 [tuple.assign], the only mention of exception is that the assignment should not throw unless one of the elements assigned to throws.

    Since there is no mention of the order in which elements are assigned to, it is thus unspecified.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

std::map<std::string, int> m; // Can I make assumption that m[NoSuchKey] will return 0? std::cout
std::string s(foo); sprintf(buf,%s,s); Why at least under MSVC 2010 this line of code doesn't
std::vector<bool> reprVectors::encode(std::vector<float> input){ std::vector<float> distance; for(size_t i=0;i<this->reprVectorsList.size();i++){ distance.push_back(distBtw(input,this->reprVectorsList[i])); } std::vector<float>::iterator it= min_element(distance.begin(),distance.end()); return this->reprVectorsList[it]->code;
std::vector<Foo> vec; Foo foo(...); assert(vec.size() == 0); vec.reserve(100); // I've reserved 100 elems vec[50]
std::string x(x); This crashes very badly on my compiler. Does this mean I should
std::unique_ptr<int> ptr; ptr = new int[3]; // error error C2679: binary '=' : no
std::atomic is new feature introduced by c++11 but I can't find much tutorial on
std::vector<double> C(4); for(int i = 0; i < 1000;++i) for(int j = 0; j
std::string has over 30 member functions that can be called on a string object.
std::string str; std::stringstream strm(str); I get this error: Error 11 error C2248: 'std::basic_ios<_Elem,_Traits>::basic_ios' :

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.