锘??xml version="1.0" encoding="utf-8" standalone="yes"?>人妻精品久久无码区,99久久无码一区人妻,性做久久久久久久久浪潮http://www.shnenglu.com/chenchen/C++zh-cnWed, 07 May 2025 15:48:02 GMTWed, 07 May 2025 15:48:02 GMT60涓漢緲昏瘧Beyond the C++ Standard Library -2http://www.shnenglu.com/chenchen/archive/2005/12/31/2323.htmlchenchenchenchenSat, 31 Dec 2005 09:23:00 GMThttp://www.shnenglu.com/chenchen/archive/2005/12/31/2323.htmlhttp://www.shnenglu.com/chenchen/comments/2323.htmlhttp://www.shnenglu.com/chenchen/archive/2005/12/31/2323.html#Feedback3http://www.shnenglu.com/chenchen/comments/commentRss/2323.htmlhttp://www.shnenglu.com/chenchen/services/trackbacks/2323.htmlshared_ptr
Header: "boost/shared_ptr.hpp"

鍑犱箮鍏ㄩ儴鏈夋晥紼嬪簭閮介渶瑕佷竴浜涘紩鐢ㄨ鏁?reference-counted)褰㈠紡鐨勬櫤鑳芥寚閽?榪欎簺鍙兘鎸囬拡浣挎垜浠笉鍐嶉渶瑕佽嚜宸卞啓澶嶆潅鐨勯昏緫鏉ユ帶鍒惰鍏變韓瀵硅薄鐨勭敓鍛芥湡.褰撳紩鐢ㄨ鏁伴檷鍒?,娌℃湁瀵硅薄瀵硅繖涓鍏變韓瀵硅薄鎰熷叴瓚?鎵浠ュ畠鑷姩delete.寮曠敤璁版暟鏅鴻兘鎸囬拡琚垎綾諱負渚靛叆寮忓拰闈炰鏡鍏ュ紡.綾繪牸寮忔彁渚涗竴涓‘瀹氱殑鍔熻兘鍑芥暟鎴栬呮暟鎹垚鍛樻潵綆$悊寮曠敤璁版暟.閭f剰鍛崇潃璁捐綾誨甫鏈夐瑙佹х殑鍙互涓庝鏡鍏ュ紡,寮曠敤璁版暟鏅鴻兘鎸囬拡綾?鎴栬呮敼榪涘瀷鍏卞悓宸ヤ綔.闈炰鏡鍏ュ紡,寮曠敤璁版暟鏅鴻兘鎸囬拡涓嶉渶瑕佺鐞嗕換浣曠被鍨?寮曠敤璁版暟鏅鴻兘鎸囬拡鍋囪鍐呭瓨鐨勬墍鏈夋潈涓庡瓨鍌ㄤ粬浠殑鎸囬拡鐩稿叧鑱?鍦ㄦ病鏈夋櫤鑳芥寚閽堝府鍔╀笅浣跨敤鍏變韓瀵硅薄鐨勯棶棰樻槸蹇呴』鏈変漢鏈緇坉elete鍏變韓鍐呭瓨.璋佸仛,浣曟椂鍋?娌℃湁寮曠敤璁版暟鏅鴻兘鎸囬拡,涓涓閮ㄧ殑鐢熷懡鏈熺鐞嗗繀欏誨己鍔犱簬琚鐞嗙殑鍐呭瓨,瀹冨吀鍨嬬殑琛ㄨ揪浜嗘墍鏈夋潈闆嗗悎涔嬮棿瀛樺湪寰堝己鐨勪簰鐩鎬緷闄勫叧緋?閭f牱濡ㄧ浜嗗彲閲嶇敤鎬у拰澧炲姞浜嗗鏉傚害.

琚鐞嗙殑綾繪垨璁告湁涓涓睘鎬т嬌瀹冭兘鎴愪負涓涓紭縐鐨勫欓夋潵鍜屽紩鐢ㄨ鏁版櫤鑳芥寚閽堜竴璧蜂嬌鐢?姣斿,浜嬪疄涓?瀹冨鍒跺紑閿寰堝ぇ,鎴栬呭畠琛ㄧず闇瑕佽澶氫釜瀹炰緥鍏變韓,鍚堢悊鐨勫叡浜墍鏈夋潈.榪樻湁鐨勬儏鍐典笉瀛樺湪涓涓槑紜殑鍏變韓璧勬簮鎷ユ湁鑰?搴旂敤寮曠敤璁版暟鏅鴻兘鎸囬拡浣塊渶瑕佸湪瀵硅薄闂村垎浜竴涓叡浜祫婧愭垚涓哄彲鑳?鍚屾牱鍦ㄦ爣鍑嗗簱涓嬌娌℃湁鍗遍櫓鍜屾病鏈夋硠闇茬殑鏉′歡涓嬪瓨鍌ㄥ璞℃寚閽堟垚涓哄彲鑳?灝ゅ叾闈㈠寮傚父鏃舵垨鑰呭綋浠庡鍣ㄤ腑縐婚櫎鍏冪礌鏃?褰撲綘鍦ㄥ鍣ㄤ腑瀛樺偍鎸囬拡鏃?浣犺兘寰楀埌澶氭佺殑浼樺娍,鏁堢巼鏀硅壇(濡傛灉澶嶅埗闇瑕佸緢澶ц姳璐圭殑璇?,榪樺叿澶囧瓨鍌ㄥ涓浉鍚屽璞$殑鑳藉姏,鍏寵仈瀹瑰櫒鐨勪笓闂ㄦ鏌?

鍦ㄤ綘鏈夌悊鐢卞茍鍐沖畾浣跨敤寮曠敤璁版暟鏅鴻兘鎸囬拡鍚?鎬庢牱閫夋嫨浣跨敤渚靛叆寮忚繕鏄潪渚靛叆寮忕殑璁捐?闈炰鏡鍏ュ紡
鍑犱箮鎬繪槸杈冨ソ鐨勯夋嫨鍥犱負瀹冪殑涓鑸傜敤鎬?瀵圭幇瀛樹唬鐮佸獎鍝嶅皯,鐏墊椿.浣犲彲浠ヤ嬌鐢ㄩ潪渚靛叆寮?寮曠敤璁版暟鏅鴻兘鎸囬拡瀵歸偅浜涗綘甯屾湜淇濇寔涓嶅彉鐨勭被.閫氬父鐨勬柟娉曟槸鏀圭紪涓涓被鏉ュ拰渚靛叆寮忕殑涓璧峰伐浣?寮曠敤璁版暟鏅鴻兘鎸囬拡鏄粠寮曠敤璁版暟鍩虹被媧劇敓鍑烘潵鐨?涔嶄竴鐪嬪畠鐨勫彉鍖栨垨璁鎬即闅忕潃鏇村鐨勫紑閿.浣嗘槸鑷沖皯,瀹冨鍔犱簡鐩鎬簰渚濆瓨鍏崇郴鍜屽姞寮轟簡鍙噸鐢ㄦ?瀹冨悓鏍峰鍔犱簡瀵硅薄澶у皬,鎴栧湪涓浜涜寖鍥村唴闄愬埗浜嗗彲鐢ㄦ?


涓涓猻hared_ptr鍙互鐢卞師鐢熸寚閽?鍙︿竴涓猻hared_ptr,涓涓猻td::auto_ptr,鎴栬呬竴涓猙oost::weak_ptr鍒涘緩.瀹冨悓鏍峰彲浠ヤ紶閫掔浜屼釜瀹炲弬鍒皊hared_ptr鐨刢onstructor,褰撳仛閲婃斁鑰?
瀹冧細琚渶鍚庤皟鐢ㄦ潵閲婃斁琚叡浜祫婧?榪欐槸闈炲父鏈夌敤鐨勫浜庣鐞嗛偅浜涗笉鏄氳繃new鍒嗛厤鍜宒elete閿姣佺殑璧勬簮(鎴戜滑紼嶅悗灝嗙湅鍒頒竴浜涘垱寤虹敤鎴烽噴鏀捐呯殑渚嬪瓙).shared_ptr琚垱寤哄悗,瀹冧細琚儚鏅氭寚閽堜竴鏍風殑浣跨敤,娌℃湁琚槑紜垹闄ょ殑鎯呭喌涓嬪洖鏄劇ず寮傚父.

榪欐槸shared_ptr鐨勪竴涓儴鍒嗙翰瑕?鏈閲嶈鐨勬垚鍛樺拰鑷敱鍑芥暟琚垪鍑烘潵,闅忓悗灝嗙畝鐭殑璁ㄨ.

namespace boost {

  template<typename T> class shared_ptr {
  public:
    template <class Y> explicit shared_ptr(Y* p);
    template <class Y,class D> shared_ptr(Y* p,D d);

    ~shared_ptr();

    shared_ptr(const shared_ptr & r);
    template <class Y> explicit
      shared_ptr(const weak_ptr<Y>& r);
    template <class Y> explicit shared_ptr(std::auto_ptr<Y>& r);

    shared_ptr& operator=(const shared_ptr& r);

    void reset();
 
    T& operator*() const;
    T* operator->() const;
    T* get() const;

    bool unique() const;
    long use_count() const;

    operator unspecified-bool-type() const;

    void swap(shared_ptr<T>& b);
  };

  template <class T,class U>
    shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r);
}

Members

template <class Y> explicit shared_ptr(Y* p);

榪欎釜constructor鎺ョ鍙傛暟鎸囬拡p鐨勬墍鏈夋潈.澶卞弬p蹇呴』鏄竴涓湁鏁堢殑Y鐨勬寚閽?鍒涘緩鍚庡紩鐢ㄨ鏁拌璁句負1.浠呭綋constructor涓簊td::bad_alloc鏃舵姏鍑哄紓甯?瀹冧粎鍦ㄥ紩鐢ㄨ鏁版病鍒嗛厤鐪熺涓嶅お鍙兘鐨勬儏鍐典笅鍙戠敓).

template <class Y,class D> shared_ptr(Y* p,D d);

姝onstructor鏈変咯涓弬鏁?絎竴涓槸shared_ptr鎺ョ鎵鏈夋潈鐨勮祫婧?絎簩涓槸璐熻矗閲婃斁璧勬簮鐨勫璞″綋shared_ptr琚攢姣?琚瓨鍌ㄧ殑璧勬簮琚紶閫掔粰瀵硅薄浠(p).p鐨勬湁鏁堝煎彇鍐充簬d.濡傛灉reference counter涓嶈兘琚垎閰?shared_ptr鎶涘嚭std::bad_alloc綾誨瀷鐨勫紓甯?

shared_ptr(const shared_ptr& r);

鍦╮涓瀛樺偍璧勬簮閫氳繃鍒涘緩shared_ptr瀵硅薄琚垎浜?reference count鍔?.榪欎釜copy constructor涓嶆姏鍑哄紓甯?

template <class Y> explicit shared_ptr(const weak_ptr<Y>& r);

浠巜eak_ptr(鍦ㄦ湰绔犲悗闈粙緇?鍒涘緩涓涓猻hared_ptr.瀹冧嬌weak_ptr鍏鋒湁thread-safe鐨勭敤澶?鍥犱負琚叡浜祫婧愮殑reference count灝嗛氳繃weak_ptr鐨勫弬鏁拌嚜澧?weak_ptr涓嶄細褰卞搷琚叡浜祫婧愮殑reference count).濡傛灉weak_ptr鏄┖鐨勮瘽(r.use_count()==0),shared_ptr鎶涘嚭bad_weak_ptr綾誨瀷鐨勫紓甯?

template <typename Y> shared_ptr(std::auto_ptr<Y>& r);

榪欎釜construction浠巃uto_ptr鎺ヨ繃r瀛樺偍瀵硅薄鐨勬墍鏈夋潈閫氳繃瀛樺偍涓涓寚閽堝壇鏈茍閲婃斁鍘焌uto_ptr.鍒涘緩鍚巖eference count鏄?.浠h〃r,褰撶劧,鑰楀敖鍐呭瓨鐨勬儏鍐典笅,reference counter鏃犳硶鍒嗛厤灝嗘姏鍑簊td::bad_alloc

~shared_ptr();

shared_ptr鐨刣estructor鍑忓皯reference count 1.濡傛灉count涓?,琚寚璧勬簮delete.delete鎸囬拡灝嗛氳繃璋冪敤operator delete鎴栬呬嬌鐢ㄧ敤鎴鋒彁渚涚殑閲婃斁鑰呭璞℃潵閿姣?姝ゅ璞″皢琚瓨鍌ㄧ殑鎸囬拡浣滀負瀹冪殑鍞竴鍙傛暟璋冪敤.destructor涓嶆姏鍑哄紓甯?

shared_ptr& operator=(const shared_ptr& r); 

copy assignment operator鍏變韓r涓殑璧勬簮騫跺仠姝㈠叡浜綋鍓嶈鍏變韓鐨勮祫婧?姝opy assignment operator涓嶆姏鍑哄紓甯?/P>

void reset();

姝ゅ嚱鏁拌鐢ㄤ簬鍋滄鍏變韓琚瓨鍌ㄦ寚閽堢殑鎵鏈夋潈.琚叡浜祫婧愮殑reference count鍙?.

T& operator*() const;

姝perator榪斿洖涓涓瀛樺偍鎸囬拡鎵鎸囧悜瀵硅薄鐨勫紩鐢?濡傛灉鎸囬拡涓簄ull,operator*瀵艱嚧鏈畾涔夎涓?姝perator涓嶆姏鍑哄紓甯?/P>

T* operator->() const;

姝perator榪斿洖琚瓨鍌ㄧ殑鎸囬拡.鍚宱perator*涓璧蜂嬌smart pointer鐪嬭搗鏉ユ兂鏅氭寚閽?姝perator涓嶆姏鍑哄紓甯?/P>

T* get() const;

get function鏄鏌ヨ瀛樺偍鎸囬拡鏄惁涓簄ull鐨勯閫夋柟娉?鍦╪ull鎯呭艦涓媜perator* and operator->瀵艱嚧涓哄畾涔夎涓?.娉ㄦ剰瀹冨悓鏍峰彲浠ユ祴璇曚竴涓猻hared_ptr鏄惁鍖呭惈涓涓湁鏁堟寚閽堥氳繃浣跨敤鏆楀紡Boolean綾誨瀷杞崲.姝unction涓嶆姏鍑哄紓甯?

bool unique() const;

姝ゅ嚱鏁拌繑鍥瀟rue褰搒hared_ptr鏄瀛樺偍鎸囬拡鐨勫敮涓鎷ユ湁鑰?鍚﹀垯,榪斿洖false.unique涓嶆姏鍑哄紓甯?

long use_count() const;

姝ゅ嚱鏁拌繑鍥炴寚閽堢殑reference count.鍦ㄨ皟璇曠敤閫斾腑灝ゅ叾鏈夌敤,鍥犱負浠栬兘琚敤鏉ヨ幏寰梤eference count鐨勭畝鐭俊鎭湪鎵ц紼嬪簭鐨勫叧閿偣澶?淇濆畧鐨勪嬌鐢ㄥ畠.涓轟簡浣夸竴浜泂hared_ptr鐨勬帴鍙e彲浠ユ墽琛?璁$畻reference count涔熻鏈夊緢澶у紑閿鐢氳嚦鏄笉鍙兘鐨?姝ゅ嚱鏁頒笉鎶涘嚭寮傚父.

operator unspecified-bool-type() const;

瀹冩殫寮忚漿鎹負涓涓被鍨?unspecified-bool-type,浣跨敤Boolean鏉ユ祴璇曚竴涓猻mart pointer鎴愪負鍙兘.濡傛灉褰撳墠瀛樺偍涓涓湁鏁堟寚閽堝垯涓簍rue,鍚﹀垯,鍒欎負false.姝よ漿鎹㈠嚱鏁拌繑鍥炵殑綾誨瀷鏄負瑙勫畾鐨?浣跨敤bool浣滀負榪斿洖綾誨瀷灝嗗厑璁鎬竴浜涙棤鎰忎箟鐨勬搷浣?浠h〃鎬х殑,浣跨敤safe bool idiom鏉ュ疄鐜?鐨勭‘鏄竴涓紓浜殑鍔炴硶鏉ョ‘淇濅粎褰撻傚綋鐨勯昏緫嫻嬭瘯鎵嶈兘琚嬌鐢?姝ゅ嚱鏁頒笉鎶涘嚭寮傚父.

void swap(shared_ptr<T>& b);

瀹冩湁鏃舵柟渚跨殑浜ゆ崲淇╀釜shared_ptrs鐨勫唴瀹?swap鍑芥暟浜ゆ崲琚瓨鍌ㄧ殑鎸囬拡(鍜屽畠浠殑reference counts).姝ゅ嚱鏁頒笉鎶涘嚭寮傚父.

Free Functions

template <typename T,typename U>
 shared_ptr<T> static_pointer_cast(const shared_ptr<U>& r);

鎵ц涓涓猻tatic_cast浠庤瀛樺偍鐨勬寚閽堝埌shared_ptr,鎴戜滑鍙互媯鏌ユ寚閽堢劧鍚庤漿鎹㈠畠,浣嗘槸鎴戜滑涓嶈兘瀛樺偍瀹冨湪鍙﹀涓涓猻hared_ptr涓?鏂扮殑shared_ptr灝嗚涓哄畠鏄寚閽堝叧鑱旂殑璧勬簮鐨勭涓涓鐞嗚?瀹冨彲浠ヨ琛ユ晳閫氳繃static_pointer_cast.浣跨敤榪欎釜鍑芥暟紜繚鎸囬拡鍓╀綑鐨剅eference count涓嶅彉鎬?static_pointer_cast涓嶆姏鍑哄紓甯?

Usage

shared_ptr瑙e喅鐨勪富瑕侀棶棰樻槸鍦ㄦ紜槸鏃墮棿delete琚涓敤鎴峰叡浜殑璧勬簮.榪欓噷鏈変釜鐩磋鐨勪緥瀛?
鏈変咯涓猚lasses, A鍜孊,鍏變韓涓涓猧nt瀹炰緥.浣跨敤boost::shared_ptr,浣犻渶瑕佸寘鍚?boost/shared_ptr.hpp".

#include "boost/shared_ptr.hpp"
#include <cassert>

class A {
  boost::shared_ptr<int> no_;
public:
  A(boost::shared_ptr<int> no) : no_(no) {}
  void value(int i) {
    *no_=i;
  }
};

class B {
  boost::shared_ptr<int> no_;
public:
  B(boost::shared_ptr<int> no) : no_(no) {}
  int value() const {
    return *no_;
  }
};

int main() {
    boost::shared_ptr<int> temp(new int(14));
    A a(temp);
    B b(temp);
    a.value(28);
    assert(b.value()==28);
}

classes A鍜孊閮藉瓨鍌ㄤ竴涓猻hared_ptr<int>.褰撳垱閫燗鍜孊鐨勫疄渚嬫椂,shared_ptr temp琚紶閫掕繘浜嗕粬浠殑constructor.榪欎互涓虹潃榪欎笁涓猻hared_ptr,a,b,鍜宼emp鐜板湪寮曠敤涓涓叡鍚岀殑int瀹炰緥.鎴戜滑鐢ㄦ寚閽堣揪鍒頒簡鍒嗕韓涓涓猧nt鐨勭洰鐨?A鍜孊灝嗚綆楀嚭瀹冨簲璇ュ湪浣曟椂琚玠elete.鍦ㄦ湰渚嬩腑,reference count鏄?鐩村埌main鐨勭粨鏉?鎵鏈夌殑shared_ptr璺沖嚭浣滅敤鍩?鍑忓皯count鐭ラ亾涓?,鍏佽鏈鍚庝竴涓猻mart pointers鏉elete鍏變韓鐨刬nt.

 



chenchen 2005-12-31 17:23 鍙戣〃璇勮
]]>
涓漢緲昏瘧Beyond the C++ Standard Libraryhttp://www.shnenglu.com/chenchen/archive/2005/12/30/2299.htmlchenchenchenchenFri, 30 Dec 2005 12:43:00 GMThttp://www.shnenglu.com/chenchen/archive/2005/12/30/2299.htmlhttp://www.shnenglu.com/chenchen/comments/2299.htmlhttp://www.shnenglu.com/chenchen/archive/2005/12/30/2299.html#Feedback6http://www.shnenglu.com/chenchen/comments/commentRss/2299.htmlhttp://www.shnenglu.com/chenchen/services/trackbacks/2299.htmlscoped_array

Header : "boost/scoped_array.hpp"

瀵逛簬浣跨敤鍔ㄦ佸垎閰嶇殑鏁扮鏉ヨvector緇忓父鏄垜浠渶濂界殑閫夋嫨.浣嗘槸鏈変咯涓儏鍐典嬌鐢ㄦ櫘閫氭暟緇勬洿涓哄Ε鍠?

1:浼樺寲,vector甯︽潵榪囧ぇ鐨勫紑閿鍦ㄤ綋縐拰閫熷害涓?

2:琛ㄨ揪鐨勬剰鍥?浣跨敤闀垮害鍥哄畾鐨勬暟緇?/TT>

鍔ㄦ佹暟緇勬毚闇插嚭鍜屾櫘閫氭寚閽堜竴鏍風殑鍗遍櫓,浼撮殢鐫璋冪敤delete鎿嶄綔絎︽潵浠f浛delete[]鎿嶄綔絎︾殑閿欒,

鎴戝湪寰堝鍦版柟鐪嬪埌榪囪繖涓敊璇?鍙竴涓氨涓嶆暍鎯寵薄,浣曞喌搴旂敤鐨勫姝ゅ箍娉涘湪瀹瑰櫒綾葷殑鎵鏈夋潈涓?

scoped_array鐢ㄤ簬鏁扮粍綾諱技scoped_ptr浣滅敤浜庡崟涓璞$殑鎸囬拡,瀹僤elete鍐呭瓨,涓嶅悓涔嬪鏄痵coped_array

浣跨敤鎿嶄綔絎elete[].

scoped_array鏄竴涓崟鐙被鑰屼笉鏄痵coped_ptr鐨勭壒鍖栨槸鍥犱負浣跨敤metaprogramming鎶鏈潵鍒嗗埆鍗曚釜瀵硅薄

鐨勬寚閽堝拰鏁扮粍鎸囬拡鏄笉鍙兘鐨?

涓嶇濡備綍鍔姏鐨勫幓鍖哄埆,娌℃湁浜哄彂鐜頒竴涓彲闈犵殑鏂規硶鏉ュ疄鐜?鍥犱負鏁扮粍綾誨瀷澶鏄撻鍖栧埌鎸囬拡綾誨瀷騫朵笉甯︽湁

浠諱綍綾誨瀷杞寲淇℃伅鏉ヨ鏄庡畠鍒板簳鎸囧儚鐨勬槸浠涔堢被鍨?緇撴灉浣犳湁璐d換閲囩敤scoped_array鑰屼笉鏄?TT>scoped_ptr,

灝卞儚浣犲繀欏諱嬌鐢╠elete[] operator鑰屼笉鏄痙elete operator.浼樺娍鏄痵coped_array甯綘澶勭悊delete,

騫朵笖鎻愰啋浣犲畠澶勭悊鐨勬槸鏁扮粍,鍘熺敓鎸囬拡鍗村仛涓嶅埌姝ょ偣.

scoped_array鍜宻coped_ptr鍜岀浉浼?涓嶅悓鐨勬槸瀹冩彁渚沷perator[]鏉ユā浠垮師鐢熸暟緇?

scoped_array浼樹簬鍘熷,鍔ㄦ佸垎閰嶆暟緇勪箣涓.瀹冪鐞嗗姩鎬佹暟緇勭殑鐢熷懡鏈?涓巗coped_ptr濡備綍綆$悊鎵鎸囧悜瀵硅薄

鐨勭敓鍛芥湡綾諱技,铏界劧濡傛,浣嗗緢澶氭儏鍐典笅,std::vector鍗存洿鍙彇,鍥犱負瀹冩洿鐏墊椿,鏇村己澶?

褰撲綘闇瑕佸浐瀹氶暱搴︾殑鏁扮粍,浣跨敤scoped_array鑰屼笉鏄?/FONT>std::vector.



chenchen 2005-12-30 20:43 鍙戣〃璇勮
]]>
浼殢鏈烘暟浜х敓鍣?/title><link>http://www.shnenglu.com/chenchen/archive/2005/12/28/2210.html</link><dc:creator>chenchen</dc:creator><author>chenchen</author><pubDate>Wed, 28 Dec 2005 05:35:00 GMT</pubDate><guid>http://www.shnenglu.com/chenchen/archive/2005/12/28/2210.html</guid><wfw:comment>http://www.shnenglu.com/chenchen/comments/2210.html</wfw:comment><comments>http://www.shnenglu.com/chenchen/archive/2005/12/28/2210.html#Feedback</comments><slash:comments>1</slash:comments><wfw:commentRss>http://www.shnenglu.com/chenchen/comments/commentRss/2210.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/chenchen/services/trackbacks/2210.html</trackback:ping><description><![CDATA[class subtractive_rng : public unary_function<unsigned int, unsigned int> {<BR>private:<BR>  unsigned int _M_table[55];<BR>  size_t _M_index1;<BR>  size_t _M_index2;<BR>public:<BR>  unsigned int operator()(unsigned int __limit) {<BR>    _M_index1 = (_M_index1 + 1) % 55;<BR>    _M_index2 = (_M_index2 + 1) % 55;<BR>    _M_table[_M_index1] = _M_table[_M_index1] - _M_table[_M_index2];<BR>    return _M_table[_M_index1] % __limit;<BR>  }<BR><BR>  void _M_initialize(unsigned int __seed)<BR>  {<BR>    unsigned int __k = 1;<BR>    _M_table[54] = __seed;<BR>    size_t __i;<BR>    for (__i = 0; __i < 54; __i++) {<BR>        size_t __ii = (21 * (__i + 1) % 55) - 1;<BR>        _M_table[__ii] = __k;<BR>        __k = __seed - __k;<BR>        __seed = _M_table[__ii];<BR>    }<BR>    for (int __loop = 0; __loop < 4; __loop++) {<BR>        for (__i = 0; __i < 55; __i++)<BR>            _M_table[__i] = _M_table[__i] - _M_table[(1 + __i + 30) % 55];<BR>    }<BR>    _M_index1 = 0;<BR>    _M_index2 = 31;<BR>  }<BR><BR>  subtractive_rng(unsigned int __seed) { _M_initialize(__seed); }<BR>  subtractive_rng() { _M_initialize(161803398u); }<BR>};<img src ="http://www.shnenglu.com/chenchen/aggbug/2210.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/chenchen/" target="_blank">chenchen</a> 2005-12-28 13:35 <a href="http://www.shnenglu.com/chenchen/archive/2005/12/28/2210.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>stl 鍑芥暟瀵硅薄http://www.shnenglu.com/chenchen/archive/2005/12/27/2190.htmlchenchenchenchenTue, 27 Dec 2005 13:14:00 GMThttp://www.shnenglu.com/chenchen/archive/2005/12/27/2190.htmlhttp://www.shnenglu.com/chenchen/comments/2190.htmlhttp://www.shnenglu.com/chenchen/archive/2005/12/27/2190.html#Feedback0http://www.shnenglu.com/chenchen/comments/commentRss/2190.htmlhttp://www.shnenglu.com/chenchen/services/trackbacks/2190.html
template <class _Tp>
struct _Identity : public unary_function<_Tp,_Tp> {
  const _Tp& operator()(const _Tp& __x) const { return __x; }
};

template <class _Tp> struct identity : public _Identity<_Tp> {};

//楠岃瘉妯℃澘鍙傛暟鏄笉鏄竴涓嚱鏁板璞$被鍨?BR>
template <class _Pair>
struct _Select1st : public unary_function<_Pair, typename _Pair::first_type> {
  const typename _Pair::first_type& operator()(const _Pair& __x) const {
    return __x.first;
  }
};

template <class _Pair>
struct _Select2nd : public unary_function<_Pair, typename _Pair::second_type>
{
  const typename _Pair::second_type& operator()(const _Pair& __x) const {
    return __x.second;
  }
};

template <class _Pair> struct select1st : public _Select1st<_Pair> {};
template <class _Pair> struct select2nd : public _Select2nd<_Pair> {};

//蹇界暐妯℃澘鍙傛暟涓簆air綾誨瀷鎵鍖呭惈鐨勭浉搴斿弬鏁?絎竴涓弬鏁板拰絎簩涓弬鏁?

template <class _Arg1, class _Arg2>
struct _Project1st : public binary_function<_Arg1, _Arg2, _Arg1> {
  _Arg1 operator()(const _Arg1& __x, const _Arg2&) const { return __x; }
};

template <class _Arg1, class _Arg2>
struct _Project2nd : public binary_function<_Arg1, _Arg2, _Arg2> {
  _Arg2 operator()(const _Arg1&, const _Arg2& __y) const { return __y; }
};

template <class _Arg1, class _Arg2>
struct project1st : public _Project1st<_Arg1, _Arg2> {};

template <class _Arg1, class _Arg2>
struct project2nd : public _Project2nd<_Arg1, _Arg2> {};

//蹇界暐璋冪敤榪愮畻絎︽椂鐩稿簲鐨勫弬鏁?/P>

template <class _Result>
struct _Constant_void_fun {
  typedef _Result result_type;
  result_type _M_val;

  _Constant_void_fun(const result_type& __v) : _M_val(__v) {}
  const result_type& operator() const { return _M_val; }
}; 

template <class _Result, class _Argument>
struct _Constant_unary_fun {
  typedef _Argument argument_type;
  typedef  _Result  result_type;
  result_type _M_val;

  _Constant_unary_fun(const result_type& __v) : _M_val(__v) {}
  const result_type& operator()(const _Argument&) const { return _M_val; }
};

template <class _Result, class _Arg1, class _Arg2>
struct _Constant_binary_fun {
  typedef  _Arg1   first_argument_type;
  typedef  _Arg2   second_argument_type;
  typedef  _Result result_type;
  _Result _M_val;

  _Constant_binary_fun(const _Result& __v) : _M_val(__v) {}
  const result_type& operator()(const _Arg1&, const _Arg2&) const {
    return _M_val;
  }
};

//榪斿洖涓涓櫘閫氬彉閲忕殑const鍓湰,鏃犺鍙傛暟涓轟綍,鍙繑鍥炲悓涓涓肩殑鍑芥暟瀵硅薄

template <class _Result>
struct constant_void_fun : public _Constant_void_fun<_Result> {
  constant_void_fun(const _Result& __v) : _Constant_void_fun<_Result>(__v) {}
}; 

template <class _Result,
          class _Argument __STL_DEPENDENT_DEFAULT_TMPL(_Result)>
struct constant_unary_fun : public _Constant_unary_fun<_Result, _Argument>
{
  constant_unary_fun(const _Result& __v)
    : _Constant_unary_fun<_Result, _Argument>(__v) {}
};


template <class _Result,
          class _Arg1 __STL_DEPENDENT_DEFAULT_TMPL(_Result),
          class _Arg2 __STL_DEPENDENT_DEFAULT_TMPL(_Arg1)>
struct constant_binary_fun
  : public _Constant_binary_fun<_Result, _Arg1, _Arg2>
{
  constant_binary_fun(const _Result& __v)
    : _Constant_binary_fun<_Result, _Arg1, _Arg2>(__v) {}
};

//__STL_DEPENDENT_DEFAULT_TMPL 鏄竴涓畯錛屾剰鎬濇槸濡傛灉緙栬瘧鍣ㄤ笉鏀寔榛樿妯℃澘鍙傛暟錛屽垯浣跨敤涓婁竴綰фā鏉垮弬鏁?BR>
template <class _Result>
inline constant_void_fun<_Result> constant0(const _Result& __val)
{
  return constant_void_fun<_Result>(__val);
}

template <class _Result>
inline constant_unary_fun<_Result,_Result> constant1(const _Result& __val)
{
  return constant_unary_fun<_Result,_Result>(__val);
}

template <class _Result>
inline constant_binary_fun<_Result,_Result,_Result>
constant2(const _Result& __val)
{
  return constant_binary_fun<_Result,_Result,_Result>(__val);
}

//鍑芥暟榪斿洖涓涓彧榪斿洖甯擱噺鍜岃緭鍏ュ弬鏁版棤鍏崇殑鍑芥暟瀵硅薄



chenchen 2005-12-27 21:14 鍙戣〃璇勮
]]>
中文字幕亚洲综合久久菠萝蜜| 久久99国产精一区二区三区| 久久精品成人欧美大片| 青青草国产97免久久费观看| 亚洲国产成人精品91久久久| av无码久久久久不卡免费网站| 91久久福利国产成人精品| 亚洲精品国产第一综合99久久| 久久综合亚洲欧美成人| 久久99精品久久久久久齐齐| 精品久久久无码21p发布| 久久亚洲高清观看| 久久精品蜜芽亚洲国产AV| 日韩一区二区三区视频久久| 成人免费网站久久久| 久久综合亚洲色一区二区三区| 久久精品国产亚洲综合色| 国产精品久久久久久久久软件| 夜夜亚洲天天久久| 精品国产一区二区三区久久久狼 | 久久综合九色综合网站| 99热都是精品久久久久久| 亚洲va国产va天堂va久久| 欧美一级久久久久久久大片| 久久久九九有精品国产| 国内精品久久人妻互换| 伊人久久综合无码成人网| 三级片免费观看久久| 精品99久久aaa一级毛片| 久久午夜电影网| 久久精品国产一区| a级毛片无码兔费真人久久| 人人狠狠综合久久亚洲88| 日韩亚洲欧美久久久www综合网 | 亚洲欧美一级久久精品| 久久香蕉国产线看观看猫咪?v| 办公室久久精品| 久久精品成人| 久久国产精品无| 天天躁日日躁狠狠久久| 国产精品女同久久久久电影院|