[問題] 請問關於 function object 的一段話
小弟我目前在念 C++ Standard Library: a Tutorial and Reference 這本書
書裡提到使用 function object 有三個優點 (比起原始的函數來說)
三個優點中有兩個我看懂了
1. function object 可以維護內部的狀態。
2. function object 速度比較快。
但是最後一點我看不懂為什麼 囧"
原文抄錄如下
Each function object has its own type.
Ordinary functions have different types only when their signatures differ.
However, function objects can have different types even when their signatures
are the same. In fact, each functional behavior defined by a function object
has its own type. This is a significant improvement for generic programming
using templates because you can pass functional behavior as a template
parameter. It enables containers of different types to use the same kind of
function object as a sorting criterion. This ensures that you don't assign,
combine, or compare collections that have different sorting criteria. You can
even design hierarchies of function objects so that you can, for example,
have different, special kinds of one general criterion.
上來請各位大大指點一下,謝謝。
--
UVa Problems I Solved
http://chchwy.blogspot.com/p/my-solved-acm-problems-list.html
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.115.158.103
→
08/21 20:58, , 1F
08/21 20:58, 1F
推
08/21 22:21, , 2F
08/21 22:21, 2F
→
08/21 22:23, , 3F
08/21 22:23, 3F
→
08/21 23:19, , 4F
08/21 23:19, 4F
→
08/21 23:20, , 5F
08/21 23:20, 5F
→
08/21 23:22, , 6F
08/21 23:22, 6F
→
08/21 23:22, , 7F
08/21 23:22, 7F
→
08/21 23:23, , 8F
08/21 23:23, 8F
→
08/21 23:24, , 9F
08/21 23:24, 9F
→
08/21 23:24, , 10F
08/21 23:24, 10F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章