锘??xml version="1.0" encoding="utf-8" standalone="yes"?>
]]>
using std::string;
using std::vector;
inline string utf8_trans_impl(string const& from, int from_code, int to_code)
{
int len16 = MultiByteToWideChar(from_code, 0, from.begin(), from.size(), 0, 0);
if (len16 > 0)
{
vector<wchar_t> ucs2_buf(len16, 0);
len16 = MultiByteToWideChar(from_code, 0, from.begin(), from.size(), ucs2_buf.begin(), len16);
int len8 = WideCharToMultiByte(to_code, 0, ucs2_buf, len16, 0, 0, 0, 0);
string result(len8, 0);
WideCharToMultiByte(to_code, 0, ucs2_buf.begin(), len16, result.begin(), len8, 0, 0);
return result;
}
return string();
}
inline string from_utf8(string const& from)
{
return utf8_trans_impl( from, CP_UTF8, CP_ACP);
}
inline string to_utf8(string const& from)
{
return utf8_trans_impl(from, CP_ACP, CP_UTF8);
}
杞澆璇瘋〃鏄庡師鏂囧湴鍧: http://www.shnenglu.com/exile/
]]>
銆銆鎻掑叆瀹炵幇錛?
template <typename Container>
inline void ordered_insert(Container& c,銆 typename Container::value_type const& t)
{
c.insert(std::upper_bound(c.begin(), c.end(), t), t);
}
template <typename Container, typename Cmp>
inline void ordered_insert(Container& c,銆typename Container::value_type const& t,銆Cmp cmp)
{
c.insert(std::upper_bound(c.begin(), c.end(), t, cmp), t);
}
銆銆鍒犻櫎瀹炵幇錛?
template <typename Container, typename It>
inline void erase_range(Container& c, std::pair<It, It> const& r)
{
c.erase(r.first, r.second);
}
template <typename Container>
inline void ordered_erase(Container& c, 銆typename Container::value_type const& t)
{
erase_range(c, std::equal_range(c.begin(), c.end(), t));
}
template <typename Container, typename T, typename Cmp>
inline void ordered_erase(Container& c, T const& t, Cmp cmp)
{
erase_range(c, std::equal_range(c.begin(), c.end(), t, cmp));
}
銆銆鏌ユ壘鍙氳繃binary_search, lower_bound, upper_bound, 鎴栬卐qual_range瀹炵幇銆傚鏋滆瀹炵幇綾諱技map鐨勫叧閿瓧鎼滅儲錛屾湁涓涓妧宸э紝灝辨槸鐢ㄦ瘮杈冨嚱鏁拌繘琛岄噸杞斤紝姣斿瀛︾敓瑕佹寜瀛﹀彿鏌ユ壘錛屽垯鐢ㄤ互涓嬪畾涔夛細
struct Student
{
int id;
std::string name;
struct LessThan
{
bool operator() (Student const& x, Student const& y)
{
return x.id < y.id;
}
bool operator() (Student const& x, int id)
{
return x.id < id;
}
bool operator() (int id, Student const& y)
{
return id < y.id;
}
};
};
鏌ユ壘瀛﹀彿涓?鐨勫鐢燂細
bool exist = std::binary_search(students.begin(), students.end(), 5, Student::LessThan());
鍒犻櫎瀛﹀彿涓?鐨勫鐢燂細
ordered_erase(students, 5, Student::LessThan());
]]>
]]>
銆銆涓嬮潰緇欏嚭浜嗙ず渚嬩唬鐮侊細
bool MyDialog::winEvent(MSG* msg, long* result)
{
const int captionHeight = 25;
const int frameWidth = 6;
if (msg->message != WM_NCHITTEST) return false;
QPoint pos = mapFromGlobal(QCursor::pos());
int w = width();
int h = height();
if (QRect(frameWidth, captionHeight, w-frameWidth-frameWidth, h-captionHeight-frameWidth).contains(pos))
{
*result = HTCLIENT;
}
else if (QRect(0, 0, w, captionHeight).contains(pos))
{
*result = HTCAPTION;
}
else if (QRect(0, captionHeight, frameWidth, h-captionHeight-frameWidth).contains(pos))
{
*result = HTLEFT;
}
else if (QRect(w-frameWidth, captionHeight, frameWidth, h-captionHeight-frameWidth).contains(pos))
{
*result = HTRIGHT;
}
else if (QRect(frameWidth, h-frameWidth, w-frameWidth-frameWidth, frameWidth).contains(pos))
{
*result = HTBOTTOM;
} else if (QRect(0, h-frameWidth, frameWidth, frameWidth).contains(pos))
{
*result = HTBOTTOMLEFT;
}
else if (QRect(w-frameWidth, h-frameWidth, frameWidth, frameWidth).contains(pos))
{
*result = HTBOTTOMRIGHT;
}
return true;
}
]]>
銆銆鍋囪涓涓寚閽堝彉閲忥細
銆銆Object * ptr;
銆銆浣跨敤ptr鏃訛紝鎴戜滑闄や簡瑕佸垽鏂璸tr鏄惁涓?浠ュ錛岃繕瑕佹鐤戝畠鎸囧悜鐨勫璞℃槸鍚︽湁鏁堬紝鏄笉鏄凡緇忓湪鍒殑鍦版柟琚攢姣佷簡銆傛垜浠笇鏈涘綋瀹冩寚鍚戠殑瀵硅薄琚攢姣佹椂錛宲tr琚嚜鍔ㄧ疆涓?銆?br>銆銆鏄劇劧錛孋++娌℃湁榪欑鏈哄埗錛屼絾鏄紝鍙互鍊熷姪浜巄oost::weak_ptr鍋氬埌榪欎竴鐐廣?br>