一 偏特化實現hash function
型如:
template<>
struct hash <string>
二 tuple 使用
tuple<XX,XX,XX> t;? ? XX: 為類型
tuple <XX,XX,XX> t (YY,YY,YY);? XX:為類型? ?YY:為具體值
make_tuple(XX,YY,ZZ);?
獲取get<XX>(t)? ?XX為序號
課程中講到的GNU C4.8 版本, tuple具體實現使用了遞歸的思路
最新版本gcc7.2 中的tuple由?
tuple 繼承 _Tuple_impl? ,,?_Tuple_impl??Basis case of inheritance recursion.
三 type traits
http://en.cppreference.com/w/cpp/header/type_traits
通過模板泛化,特化實現
四 cout
重載operator<<
五 movable
通過修改指針方式完成, 效率比較copy高,但是具有破化性。?
六 作業報錯
重載operator<< , 輸出參數使用版本參數, 報錯如下
meter me
cout << me << endl;
^test.h:142:52: error: ‘std::ostream& weida1001::operator<<(std::ostream&)’ must take exactly two arguments std::ostream & operator << (ostream& os const T &m) { ^test.cpp: In function ‘void weida1001::test()’:test.cpp:21:8: error: no match for ‘operator<<’ (operand types are ‘std::ostream {aka std::basic_ostream}’ and ‘weida1001::meter’)
//@{ /** * @brief Character inserters * @param __out An output stream. * @param __c A character. * @return out * * Behaves like one of the formatted arithmetic inserters described in * std::basic_ostream. After constructing a sentry object with good * status, this function inserts a single character and any required * padding (as determined by [22.2.2.2.2]). @c __out.width(0) is then * called. * * If @p __c is of type @c char and the character type of the stream is not * @c char, the character is widened before insertion. */ templateinline basic_ostream<_CharT, _Traits>&
參考 C++ include ostream 文件, 進行修改, 輸出char 和string 不同, 我這里只是用char
template? < typename? _CharT, typename _Traits, typename T>
basic_ostream<_CharT,_Traits>&?
operator<<(basic_ostream<_CharT, _Traits>&os, const T &m)
?{
? ? ? ? ? ? ? ?unit_traits<T>u;
? ? ? ? ? ? ? ?os << m.getvalue() << u.get_unit(m);
}