我「寫」了一個低效的STL子集

tinySTL

本人蔘考《STL源碼剖析》「寫」了一個低效的STL 子集。代碼中有比較詳細的註釋,可做爲閱讀《STL源碼剖析》的輔助材料。git

本項目爲本人的練習項目,因此暫時未提供測試,不能保證徹底正確。請多多包涵。github

至於怎麼「低效」了,我後面會整理一些我已經能預見到會低效的實現。敬請期待。算法

源碼

Githubless

已完成

  • 空間配置器
  • 普通迭代器
  • 反向迭代器
  • vector
  • list
  • deque
  • stack
  • queue
  • heap
  • priority_queue
  • rb_tree(實現來自GitHub
  • set
  • multiset
  • map
  • multimap
  • hashtable(其餘 hash 函數參考here
  • unordered_set
  • unordered_map
  • unordered_multiset
  • unordered_multimap
  • type traitside

    • integral_constant
    • true_type
    • false_type
    • is_same
    • is_integral
    • remove_reference
    • remove_reference_t
    • add_lvalue_reference
    • add_lvalue_reference_t
    • add_rvalue_reference
    • add_rvalue_reference_t
    • __type_traits
  • 算法函數

    • all_of
    • any_of
    • none_of
    • for_each
    • count
    • count_if
    • mismatch
    • find
    • find_if
    • find_if_not
    • find_end
    • find_first_of
    • adjacent_find
    • search
    • search_n
    • copy
    • copy_if
    • copy_n
    • copy_backward
    • move
    • move_backward
    • remove
    • remove_if
    • remove_copy
    • remove_copy_if
    • replace
    • replace_if
    • replace_copy
    • replace_copy_if
    • swap
    • swap_ranges
    • iter_swap
    • reverse
    • reverse_copy
    • rotate
    • rotate_copy
    • unique
    • unique_copy
    • is_partitioned
    • partition
    • partition_copy
    • max
    • max_element
    • min
    • min_element
    • equal
    • lexicographical_compare
    • move
  • functional測試

    • hash
    • plus
    • minus
    • multiplies
    • divides
    • modulus
    • negate
    • equal_to
    • not_equal_to
    • greater
    • less
    • greater_equal
    • less_equal
    • logical_and
    • logical_or
    • logical_not
    • bit_and
    • bit_or
    • bit_xor
    • identity
    • select1st
    • select2nd
  • utilitycode

    • initializer_list
    • forward
    • move
    • pair
    • make_pair
  • numericip

    • iota
    • accumulate
    • inner_product
    • adjacent_difference
    • partial_sum
  • memory(簡單實現)element

    • shared_ptr
    • weak_ptr
    • unique_ptr
    • addressof
    • uninitialized_copy
    • uninitialized_copy_n
    • uninitialized_fill
    • uninitialized_fill_n
  • cstring

    • strcpy
    • strncpy
    • memcpy

TODO

感悟

  • 侯捷老師說過:「源碼以前,了無祕密」。在本身」抄「了一遍容器代碼以後,進一步熟悉了STL。對於選擇不一樣的容器解決不一樣的問題,在知其因此然的狀況下,本身更有信心能選出一個合適的容器了。
  • 開始明白拷貝(移動)構造函數、複製函數的意義和使用場景。
相關文章
相關標籤/搜索