亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? sutter.htm

?? 教你如何編寫有效簡潔的出C++程序
?? HTM
?? 第 1 頁 / 共 4 頁
字號:
    ++first;  }}The tricky part is the "what goes here?". There are really only three choices: either the catch body rethrows the exception, or it converts the exception by throwing something else, or it throws nothing and continues the loop. If the catch body rethrows the exception, then the destroy function nicely meets the requirement of being exception-neutral, because it does indeed allow any T exceptions to propagate out normally. However, it still doesn't meet the safety requirement that no resources be leaked if exceptions occur. Because destroy has no way of signaling how many objects were not successfully destroyed, those objects can never be properly destroyed and so any resources associated with them will be unavoidably leaked. Definitely not good. If the catch body converts the exception by throwing something else, we've clearly failed to meet both the neutrality and the safety requirements. Enough said. If the catch body does not throw or rethrow anything, then the destroy function nicely meets the safety requirement that no resources be leaked if an exception is thrown. (True, if a T destructor could throw in a way that its resources might not be completely released, then there could still be a leak. However, this isn't destroy's problem... this just means that T itself is not exception-safe, but destroy is still properly leak-free in that it doesn't fail to release any resources that it should (namely the T objects themselves).) However, obviously it fails to meet the neutrality requirement that T exceptions be allowed to pass through because exceptions are absorbed and ignored (as far as the caller is concerned, even if the catch body does attempt to do some sort of logging).I've seen people suggest that the function should catch the exception and "save" it while continuing to destroy everything else, then rethrow it at the end. That too isn't a solution; for example, it can't correctly deal with multiple exceptions should multiple T destructors throw (even if you save them all until the end, you can only end by throwing one of them and the others are silently absorbed). You might be thinking of other alternatives, but trust me, they all boil down to writing code like this somewhere because you have a set of objects and they all need to be destroyed. Someone, somewhere, is going to end up writing non-exception-neutral code (at best) if T destructors are ever allowed to throw......Which brings us to the innocent-looking new[] and delete[].The issue with both of these is that they have fundamentally the same problem we just described for destroy! For example, consider the following code: T* p = new T[10];delete[] p;Looks like normal harmless C++, doesn't it? But have you ever wondered what new[] and delete[] do if a T destructor throws? Even if you have wondered, you can't know the answer for the simple reason that there is none: The standard says you get undefined behavior if a T destructor throws anywhere in this code, which means that any code that allocates or deallocates an array of objects whose destructors could throw can result in undefined behavior. This may raise some eyebrows, so let's see why this is so:First, consider what happens if the constructions all succeed, and then during the delete[] operation the fifth T destructor throws. Then delete[] has the same catch-22 problem (pun intended) outlined above for destroy: It can't allow the exception to propagate because then the remaining T objects would be irretrievably undestroyable, but it also can't translate or absorb the exception because then it wouldn't be exception-neutral.Second, consider what happens if the fifth constructor throws. Then the fourth object's destructor is invoked, then the third's, and so on until all the T objects that were successfully constructed have again been destroyed, and the memory is safely deallocated. But what if things don't go so smoothly? In particular, what if, after the fifth constructor throws, the fourth object's destructor throws? And, if that's ignored, the third's? You can see where this is going.If destructors may throw, then neither new[] nor delete[] can be made exception-safe and exception-neutral.The bottom line is simply this: Don't ever write destructors that can allow an exception to escape. (The C++ standard makes the blanket statement: "No destructor operation defined in the C++ Standard Library will throw an exception." Not only do all of the standard classes have this property, but in particular it is illegal to instantiate a standard container with a type whose destructor does throw.) If you do write a class with such a destructor, you will not be able to safely even new[] or delete[] an array of those objects. All destructors should always be implemented as though they had an exception specification of throw()... that is, no exceptions must ever be allowed to propagate.Granted, some may feel that this state of affairs is a little unfortunate, because one of the original reasons for having exceptions was to allow both constructors and destructors to report failures (because they have no return values). This isn't quite true, because the intent was mainly for constructor failures (after all, destructors are supposed to destroy, so the scope for failure is definitely less). The good news is that exceptions are still perfectly useful for reporting construction failures, including array and array-new[] construction failures, because there they can work predictably even if a construction does throw.Safe ExceptionsThe advice "be aware, drive with care" certainly applies to writing exception-safe code for containers and other objects. To do it successfully, you do have to meet a sometimes significant extra duty of care, but don't get unduly frightened by exceptions. Apply the guidelines outlined above that is, isolate your resource management, use the "update a temporary and swap" idiom, and never write classes whose destructors can allow exceptions to escape and you'll be well on your way to safe and happy production code that is both exception-safe and exception- neutral. The advantages can be both concrete and well worth the trouble for your library and your library's users.AcknowledgmentsThanks to Dave Abrahams and Greg Colvin for their comments. Dave and Greg are, with Matt Austern, the authors of the two complete committee proposals for adding these exception safety guarantees into the standard library (see Sidebar 2). Sidebar 1: Some Standard Helper Functions The Stack and StackImpl presented in this article use three helper functions from the standard library (see Item E49): construct, destroy, and swap. In simplified form, here's what these functions look like:   // construct() constructs a new object in  // a given location using an initial value  //  template <class T1, class T2>  void construct( T1* p, const T2value ) {    new (p) T1(value);  }This is called "placement new," and instead of allocating memory for the new object it just puts it into the memory pointed at by p (see Item M8). Any object new'd in this way should generally be destroyed by calling its destructor explicitly (as in the following two functions), rather than using delete (again, see Item M8).   // destroy() destroys an object or a range  // of objects  //  template <class T>  void destroy( T* p ) {    p-~T();  }  template <class FwdIter>  void destroy( FwdIter first, FwdIter last ) {    while( first != last ) {      destroy( first );      ++first;    }  }  // swap() just exchanges two values  //  template <class T>  void swap( Ta, Tb ) {    T temp(a); a = b; b = temp;  }Of these, destroy(iter,iter) is the most interesting. We'll return to it a little later in the main article; it illustrates more than you might think!To find out more about these standard functions, take a few minutes to examine how they're written in the standard library implementation you're using. It's a very worthwhile and enlightening exercise. Sidebar 2: Exception Safety and the Standard Library Are the standard library containers exception-safe and exception-neutral? The short answer is: Yes. ( Here I'm focusing my attention on the containers and iterators portion of the standard library. Other parts of the library, such as iostreams and facets, are specified to be strongly exception-safe.)All iterators returned from standard containers are exception-safe and can be copied without throwing an exception.All standard containers must implement the basic guarantee for all operations: They are always destructible, and they are always in a consistent (if not predictable) state even in the presence of exceptions. To make this possible, certain important functions are required not to throw including swap (the importance of which was illustrated by my second example), allocator::deallocate (the importance of which was illustrated by the discussion of ::operator delete in the first example) and certain operations of the template parameter types themselves (especially the destructor, the importance of which is illustrated under the subhead "Destructors That Throw and Why They're Evil").All standard containers must also implement the strong guarantee for all operations (with two exceptions; see next paragraph): They always have commit-or-rollback semantics, so that an operation such as an insert either succeeds completely or else does not change the program state at all. "No change" also means that failed operations do not affect the validity of any iterators that happened to be already pointing into the container.There are only two exceptions: First, for all containers, multi-element inserts ("iterator range" inserts) are never strongly exception-safe. Second, for vector<T> and deque<T> only, inserts and erases (whether single- or multi-element) are strongly exception-safe only if T's copy constructor or assignment operator do not throw. ( Unfortunately, this means that inserting into and erasing from a vector<string> or a vector<vector<int> >, for example, are not strongly exception-safe.) Why these particular limitations? Because to roll back either kind of operation isn't possible without extra space/time overhead, and the standard did not want to require that overhead in the name of exception safety. All other container operations can be made strongly exception-safe without overhead. So if you ever insert a range of elements into a container, or if T's copy constructor or assignment operator can throw and you insert into or erase from a vector<T> or a deque<T>, the container will not necessarily have predictable contents afterwards and iterators into it may have been invalidated.What does this mean for you? Well, if you write a class that has a container member and you perform range insertions, or that has a member of type vector<T> or deque<T> and T's copy constructor or assignment operator can throw, then you are responsible for doing the extra work to ensure that your own class' state is predictable if exceptions do occur. Fortunately, this "extra work" is pretty simple: Whenever you want to insert into or erase from the container, first take a copy of the container, then perform the change on the copy, and finally use swap to switch over to using that new version after you know that the copy-and-change steps have succeeded. Listing 1   template <class T>  class Stack {  public:    Stack(size_t size=0) : impl_(size) { }    Stack(const Stackother)      : impl_(other.impl_.vused_)    {      while( impl_.vused_ < other.impl_.vused_ ) {	construct( impl_.v_+impl_.vused_,	       other.impl_.v_[impl_.vused_] );	++impl_.vused_;      }    }    Stackoperator=(const Stackother) {      Stack temp(other);      impl_.Swap(temp.impl_);                  // this can't throw      return *this;    }    size_t Count() const {      return impl_.vused_;    }    void Push( const Tt ) {      if( impl_.vused_ == impl_.vsize_ ) {	Stack temp( impl_.vsize_*2+1 );	while( temp.Count() < impl_.vused_ ) {	  temp.Push( impl_.v_[temp.Count()] );	}	temp.Push( t );	impl_.Swap( temp.impl_ );      } else {	construct( impl_.v_+impl_.vused_, t );	++impl_.vused_;      }    }    TTop() {      if( impl_.vused_ == 0) {	throw "empty stack";      }      return impl_.v_[impl_.vused_-1];    }    void Pop() {      if( impl_.vused_ == 0) {	throw "pop from empty stack";      } else {	--impl_.vused_;	destroy( impl_.v_+impl_.vused_ );      }    }  private:    StackImpl<T> impl_;                    // private implementation  }

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
日本道色综合久久| 91久久精品网| 亚洲成人动漫一区| 亚洲国产毛片aaaaa无费看| 国产精品久久久久久久久免费丝袜 | 视频在线观看一区| 亚洲午夜在线电影| 性欧美大战久久久久久久久| 亚洲成av人片在线| 秋霞影院一区二区| 久久99国产精品久久99| 国内精品国产成人国产三级粉色| 精品在线你懂的| 国产资源在线一区| av电影在线观看不卡| 91亚洲大成网污www| 日本道色综合久久| 91精品国产综合久久香蕉的特点| 欧美一区欧美二区| 久久精品欧美一区二区三区不卡| 中文字幕第一页久久| 亚洲欧洲精品一区二区三区 | 91九色02白丝porn| 欧美日韩一区二区在线观看视频| 欧美人与禽zozo性伦| 日韩三级高清在线| 国产精品萝li| 亚洲一区二区美女| 国产麻豆精品视频| 91在线国内视频| 欧美一区二区网站| 国产精品视频看| 亚洲一区二区欧美激情| 狠狠色综合播放一区二区| 北条麻妃一区二区三区| 欧美日韩久久一区| 欧美激情资源网| 亚洲午夜电影在线| 粉嫩久久99精品久久久久久夜| 欧美视频一区二区在线观看| 国产调教视频一区| 亚洲成人先锋电影| av一区二区久久| 欧美一区二区不卡视频| 国产精品久久久99| 久久精品国产色蜜蜜麻豆| jizzjizzjizz欧美| 久久综合资源网| 亚洲国产色一区| 不卡欧美aaaaa| 久久只精品国产| 丝袜美腿成人在线| 91麻豆高清视频| 中文字幕精品在线不卡| 日韩影院精彩在线| 日本电影欧美片| 中文字幕成人网| 极品少妇一区二区| 在线不卡a资源高清| 亚洲精品视频免费观看| 风间由美一区二区三区在线观看| 91麻豆精品国产无毒不卡在线观看| 国产精品视频看| 国产精品一二三区在线| 日韩视频一区二区三区| 婷婷综合另类小说色区| 日本久久精品电影| 中文字幕佐山爱一区二区免费| 国产精品一区二区三区网站| 日韩你懂的在线播放| 日本网站在线观看一区二区三区 | 欧美高清视频不卡网| 亚洲人成网站精品片在线观看 | 亚洲黄色免费电影| 不卡视频在线观看| 国产精品欧美综合在线| 粉嫩高潮美女一区二区三区 | 亚洲一区中文日韩| 一本大道久久a久久综合婷婷| 国产精品福利一区二区三区| 国产一区在线视频| 精品国产不卡一区二区三区| 国产一区二区三区黄视频 | 一本到不卡精品视频在线观看| 中文字幕二三区不卡| 成人性生交大片| 中文字幕精品综合| 91欧美一区二区| 亚洲国产另类av| 911精品国产一区二区在线| 欧美aⅴ一区二区三区视频| 欧美一级二级三级蜜桃| 极品美女销魂一区二区三区| 精品国产髙清在线看国产毛片 | 国产精品久久久久影院色老大| 成人午夜免费视频| 亚洲欧美日韩国产综合在线| 日本二三区不卡| 日本不卡视频在线| 久久精品视频一区二区| 99久久精品情趣| 一区二区三区欧美视频| 91麻豆精品国产| 国产一区二区三区高清播放| 久久精品亚洲精品国产欧美kt∨| 99久久久无码国产精品| 亚洲成人免费在线| 久久久久久97三级| 色综合久久综合中文综合网| 丝袜亚洲另类欧美| 中文字幕av在线一区二区三区| 日本精品一区二区三区四区的功能| 日精品一区二区三区| 国产三级精品三级| 欧美日韩中文一区| 国产精品一二三四| 亚洲国产精品麻豆| 国产色综合久久| 欧美裸体bbwbbwbbw| 风间由美一区二区av101| 亚洲成a人在线观看| 国产精品美女久久久久久2018| 欧美电影一区二区| 91视频在线看| 国产一区二区三区综合| 亚州成人在线电影| 亚洲男女一区二区三区| 久久天天做天天爱综合色| 欧美日韩一区二区欧美激情| 国产91在线观看丝袜| 麻豆国产精品一区二区三区| 一区二区三区日韩| 亚洲视频一区在线| 国产色产综合产在线视频| 69久久夜色精品国产69蝌蚪网| 色一区在线观看| 国产不卡视频一区| 国产精品中文欧美| 久久精品二区亚洲w码| 香蕉久久夜色精品国产使用方法| 日韩伦理av电影| 亚洲国产精品黑人久久久| 精品国产乱子伦一区| 欧美一区二区三区人| 欧美色图一区二区三区| 色一情一伦一子一伦一区| 成人激情开心网| 丰满放荡岳乱妇91ww| 国产精品一区二区不卡| 精品在线一区二区三区| 久久国产欧美日韩精品| 欧美a级理论片| 日本不卡123| 久久99热99| 精品一二三四在线| 国内精品久久久久影院一蜜桃| 麻豆91精品视频| 乱一区二区av| 国内外成人在线视频| 极品销魂美女一区二区三区| 美洲天堂一区二卡三卡四卡视频| 日韩电影在线看| 免费日韩伦理电影| 国产自产2019最新不卡| 国产福利电影一区二区三区| 国产91精品久久久久久久网曝门| 国产高清久久久| 欧美三级蜜桃2在线观看| 欧洲亚洲精品在线| 欧美男人的天堂一二区| 91精品久久久久久久91蜜桃| 精品福利视频一区二区三区| 欧美国产乱子伦| 一区二区三区电影在线播| 午夜精品在线看| 狠狠狠色丁香婷婷综合激情| 国产.欧美.日韩| 色婷婷亚洲精品| 日韩你懂的电影在线观看| 国产精品日产欧美久久久久| 一区二区三区视频在线观看| 日韩激情在线观看| 高清不卡一二三区| 欧美日韩五月天| 久久久影院官网| 亚洲小说春色综合另类电影| 美女视频黄频大全不卡视频在线播放| 国产美女主播视频一区| 91视视频在线观看入口直接观看www | 日本va欧美va精品发布| 国产成人免费视频网站 | 国产91在线观看丝袜| 91成人免费网站| 337p粉嫩大胆噜噜噜噜噜91av| 国产精品久久久久久户外露出 | 久久综合色一综合色88| 亚洲猫色日本管| 国内一区二区视频| 色爱区综合激月婷婷| 精品国产免费人成在线观看|