搜尋此網誌

2025年11月25日星期二

Template function

A template function in C++ is a way to write a single function that works with multiple data types, avoiding code duplication.

A template allows you to define a function once and use it with different data types (like int, double, char).

It uses the keyword template followed by a type parameter inside angle brackets (<>).

In C++, the placeholder inside a template is the type parameter that represents a generic type.
It’s declared inside angle brackets (<>) after the keyword template.

A bit is the smallest unit of data in computing.

It can only have two possible values:

- 0 (off/false)

- 1 (on/true)

1 byte = 8 bits
This means a byte can represent 256 different values (from 0 to 255).

template <typename T>
int size_in_bit(T a) {
    return sizeof(a) * 8;
}

- template <typename T>
Declares a template with a placeholder type T. This allows the function to accept any data type (int, double, char, etc.).
- sizeof(a)
Returns the size of the variable a in bytes.
- * 8
Since 1 byte = 8 bits, multiplying by 8 converts the size into bits.
- Return type int
The function returns the number of bits as an integer.

int: 32 bits
double: 64 bits
char: 8 bits

Microsoft Copilot

Other than computer field

breadth: the distance or measurement from one side to the other; how broad or wide something is

cursive: ​(of handwriting) with the letters joined together

abridged: ​(of a book, play, etc.) made shorter by leaving parts out

stint: a period of time that you spend working somewhere or doing a particular activity

page: (North American English) a student who works as an assistant to a member of the US Congress

boarding house: ​a private house where people can pay for accommodation and meals

scramble: to push, fight or compete with others in order to get or to reach something

thriller: a book, play or film with an exciting story, especially one about crime or spying

capitalize on: ​to gain a further advantage for yourself from a situation

snap up: (informal) to buy or obtain something quickly because it is cheap or you want it very much

explicitly: clearly or directly, so that the meaning is easy to understand

bristle at: to suddenly become very annoyed or offended at what somebody says or does

playwright: ​a person who writes plays for the theatre, television or radio

farce: a funny play for the theatre based on silly and unlikely situations and events; this type of writing or performance

fiancée: the woman that somebody is engaged to

debutante: (especially in the past) a young, rich or upper-class woman who is going to fashionable social events for the first time

colonel: an officer of high rank in the army, the marines, or the US air force

grope: to try and find something that you cannot see, by feeling with your hands

pratfall: an embarrassing mistake

madcap: (of people, plans, etc.) crazy and not caring about danger; not sensible

shoo: to make somebody/something go away or to another place

inopportune: happening at a bad time

costar: ​one of two or more famous actors who appear together in a film or play

nail down: to reach an agreement or a decision, usually after a lot of discussion

split-second: done very quickly or very accurately

antic: very playful, funny, or silly

flirt: to behave towards somebody as if you find them sexually attractive, without seriously wanting to have a relationship with them

venture: a business project or activity, especially one that involves taking risks

prospect: a wide view of an area of land, etc.

blow off: (North American English) to deliberately not do something that you said you would

pinball: a game played on a pinball machine, in which the player sends a small metal ball up a sloping board and scores points as it bounces off objects. The player tries to prevent the ball from reaching the bottom of the machine by pressing two buttons at the side.

leaf through: to quickly turn over the pages of a book, etc. without reading them or looking at them carefully

tantalizing: making you want something that you cannot have or do

persona: ​the aspects of a person’s character that they show to other people, especially when their real character is different

pursuit: the act of looking for or trying to get something

stumble: to hit your foot against something while you are walking or running and almost fall

sprawl: to sit, lie or fall with your arms and legs spread out in a relaxed or careless way

flail around: to move around without control; to move your arms and legs around without control

kudos: the praise and honor that goes with a particular achievement or position

spontaneity: ​the quality of being spontaneous

one-time: former

clown: an entertainer who wears funny clothes and a large red nose and does silly things to make people laugh

realm: an area of activity, interest or knowledge

take aback: to shock or surprise somebody very much

curtain call: the time in the theatre when the actors come to the front of the stage at the end of a play to receive the applause of the audience

applause: the noise made by a group of people clapping their hands and sometimes shouting to show their approval or pleasure


Bill Gates "Source Code"

Online Dictionaries Used:

hk.dictionary.search.yahoo.com

www.oxfordlearnersdictionaries.com

2025年11月23日星期日

Template in C++

instantiate: represent as or by an instance

Compile-time polymorphism in C++ (also called static polymorphism or early binding) is achieved mainly through function overloading and operator overloading. The compiler decides which function or operator to invoke at compile time, based on the arguments provided.

Function Overloading: Multiple functions with the same name but different parameter lists.

Operator Overloading: Redefining operators (like +, ==, etc.) to work with user-defined types.

Difference from Runtime Polymorphism: Runtime polymorphism uses virtual functions and dynamic binding, where the decision is made at execution time. Compile-time polymorphism is faster because it avoids the overhead of dynamic dispatch.

#include <iostream>
using namespace std;

void greet(string name) {   // parameter
    cout << "Hello, " << name << "!" << endl;
}

int main() {
    greet("Alice");  // argument
    greet("Bob");
    return 0;
}

In C++, a template is a feature that allows you to write generic code that works with any data type. Instead of duplicating functions or classes for different types (like int, double, or string), you can define a template once and let the compiler generate the appropriate version when needed.

In C++ templates, the angle brackets (< >) are used to specify the template arguments when instantiating a template. They tell the compiler which data type (or constant value, in case of non-type parameters) should be substituted into the generic template definition.

Microsoft Copilot

Chip

the nitty-gritty: ​the basic or most important details of an issue or a situation

transistor: a small electronic device used in computers, radios, televisions, etc. for controlling an electric current as it passes along a circuit

etch: to cut lines into a piece of glass, metal, etc. in order to make words or a picture

spec: specification: a detailed description of something, especially the design and materials needed to produce something

distributor: a person or company that supplies goods to shops, etc.

heck: used to show that you are slightly annoyed or surprised; used to emphasize something

nerd: ​a person who is boring, stupid and not fashionable

A "hippie techie" can describe someone who blends the countercultural ideals of the 1960s-70s hippie movement with modern technology, often by balancing new and old tools to foster creativity.

pal: a friend

rip: to tear something or to become torn, often suddenly or violently

paranoid: having false beliefs because of a mental illness, especially the belief that people are trying or planning to harm you


Bill Gates "Source Code"

Online Dictionaries Used:

hk.dictionary.search.yahoo.com

www.oxfordlearnersdictionaries.com

Goggle AI overview

2025年11月13日星期四

Partnership

tamp something (down) to press something down hard, especially into a closed space

get on with something: to continue doing something, especially after you have been interrupted

service: a religious ceremony

cot: a light narrow bed that you can fold up and carry easily

soccer: DJ[ˋsɔkə]

punchy: having a strong effect because it expresses something clearly in only a few words

recount: to tell somebody about something, especially something that you have experienced

hysterics: DJ[hisˋteriks]

nemesis: punishment or defeat that is deserved and cannot be avoided

in retrospect: thinking about a past event or situation, often with a different opinion of it from the one you had at the time

haze: a mental state in which your thoughts, feelings, etc. are not clear

affectation: behavior or an action that is not natural or sincere and that is often intended to impress other people

geekiness: the quality of being knowledgeable about and obsessively interested in a particular subject, especially one that is technical or of specialist or niche interest; the quality of being unfashionable and socially inept or boringly studious

obsessive: thinking too much about one particular person or thing, in a way that is not reasonable or normal

inept: acting or done with no skill

contraption: a machine or piece of equipment that looks strange or complicated and possibly does not work well

orb: an object like a ball in shape

electrocute: to injure or kill somebody by passing electricity through their body

soldering iron: a tool that is heated and used for joining metals and wires by soldering them

assorted: ​of various different sorts

scour: to search a place or thing carefully and completely in order to find

genre: DJ[ˋʒɑ:nrə]

deserted: (of a place) with no people in it

well versed in something having a lot of knowledge about something, or skill at something

seminal: very important and having a strong influence on later developments

rhapsodize: to talk or write with great enthusiasm about something

brim: the flat edge around the bottom of a hat that sticks out

mantra: a statement or slogan that is often repeated

shorthand (for something) a shorter way of saying or referring to something, which may not be as accurate as the more complicated way of saying it

goad: something that makes somebody do something, usually by annoying them

Scotch: the type of whisky made in Scotland

throw up: vomit

pass out: to become unconscious

lounge: DJ[laundʒ]

A joint is a rolled cannabis cigarette.

LSD: a powerful illegal drug that affects people’s minds and makes them see and hear things that are not really there

decline: to refuse politely to accept or to do something

tremendous: very great

A congressional page is a high school student, typically 16 or older, who works for a member of the U.S. Senate or House of Representatives.

stint: a period of time that you spend working somewhere or doing a particular activity

sophomore: a student in the second year of a course of study at a college or university

"On my shoulders" can mean the figurative burden of great responsibility

figurative: (of language, words, phrases, etc.) used in a way that is different from the usual meaning, in order to create a particular mental picture.

round-the-clock: ​lasting or happening all day and night

pay off: (of a plan or an action, especially one that involves risk) to be successful and bring good results

adviser: a person who gives advice, especially somebody who knows a lot about a particular subject

legacy: money or property that is given to you by somebody when they die

forge something: to put a lot of effort into making something successful or strong so that it will last

embolden: to make somebody feel braver or more confident

mull over: to spend time thinking carefully about a plan or proposal


Bill Gates "Source Code"

Online Dictionaries Used:

hk.dictionary.search.yahoo.com

www.oxfordlearnersdictionaries.com

2025年10月28日星期二

人不知,而不慍,不亦君子乎?

人家不了解我,我卻不怨恨,不也是君子嗎?

君子務本,本立而道生。

君子專心致力於基礎工作,基礎樹立了,「道」就會產生。

巧言令色,鮮矣仁!

花言巧語,偽善的面貌,這種人,「仁德」是不會多的。

謹而信。

寡言少語,說則誠實可信。

無友不如己者。

不要跟不如自己的人交朋友。

禮之用,和為貴。

禮的作用,以遇事都做得恰當為可貴。

恭近於禮,遠恥辱也。

態度容貌的莊矜合於禮,就不致遭受侮辱。

敏於事而慎於言。

對工作勤勞敏捷,說話卻謹慎。

不患人之不己知,患不知人也。

別人不了解我,我不急;我急的是自己不了解別人。

視其所以,觀其所由,察其所安,人焉廋哉?

考查一個人所結交的朋友;觀察他為達到一定目的所採用的方式方法;了解他的心情,安於什麼,不安於什麼。那麼,這個人怎樣隱藏得住呢?

君子周而不比。

君子是團結,而不是勾結。

知之為知之,不知為不知,是知也。

知道就是知道,不知道就是不知道,這就是聰明智慧。

人而無信,不知其可也。

作為一個人,卻不講信譽,不知那怎麼可以。

見義不為,無勇也。

眼見應該挺身而出的事情,卻袖手旁觀,這是怯懦。

君子無所爭。

君子沒有什麼可爭的事情。

君使臣以禮,臣事君以忠。

君主應該依禮來使用臣子,臣子應該忠心地服事君主。

成事不說,遂事不諫,既往不咎。

已經做了的事不再解釋了,已經完成的事不便再挽救了,已經過去的事不便再追究了。

唯仁者能好人,能惡人。

只有仁人才能夠喜愛某人,厭惡某人。

惡不仁者,其為仁矣,不使不仁者加乎其身。

厭惡不仁德的人,他行仁德只是不使不仁德的東西加在自己身上。

觀過,斯知仁矣。

仔細考察某人所犯的錯誤,就可以知道他是什麼樣式的人了。

放於利而行,多怨。

依據個人利益而行動,會招致很多的怨恨。

不患無位,患所以立。不患莫己知,求為可知也。

不發愁沒有職位,只發愁沒有任職的本領;不怕沒有人知道自己,去追求足以使別人知道自己的本領好了。

夫子之道,忠恕而已矣。

他老人家的學說,只是忠和恕罷了。

見不賢而內自省也。

看見不賢的人,便應該自己反省,有沒有和他類似的毛病。

古者言之不出,恥躬之不逮也。

古時候言語不輕易出口,就是怕自己的行動趕不上。

匿怨而友其人,左丘明恥之,丘亦恥之。

內心藏著怨恨,表面上卻同他要好,這種行為,左丘明認為可恥,我也認為可恥。

顏淵曰︰「願無伐善,無施勞。」

顏淵道︰「願意不誇耀自己的好處,不表白自己的功勞。」

已矣乎,吾未見能見其過而內自訟者也。

算了吧,我沒有看見過能夠看到自己的錯誤便自我責備的呢。

有顏回者好學,不遷怒,不貳過。

有一個叫顏回的人好學,不拿別人出氣;也不再犯同樣的過失。

人之生也直,罔之生也幸而免。

人的生存由於正直,不正直的人也可以生存,那是他僥倖地免於禍害。

仁者先難而後獲,可謂仁矣。

仁德的人付出一定的力量,然後收獲果實,可以說是仁德了。

中庸之為德也,其至矣乎!民鮮久矣。

中庸這種道德,該是最高的了,大家已經是長久地缺乏它了。

己欲立而立人,己欲達而達人。

自己要站得住,同時也使別人站得住;自己要事事行得通,同時也使別人事事行得通。

不義而富且貴,於我如浮雲。

幹不正當的事而得來的富貴,我看來好像浮雲。

多聞,擇其善者而從之;多見而識之;知之次也。

多多地聽,選擇其中好的加以接受;多多地看,全記在心裡。這樣的知,是僅次於「生而知之」的。

直而無禮則絞。

心直口快,卻不知禮,就會尖刻刺人。

人而不仁,疾之已甚,亂也。

對於不仁的人,痛恨太甚,也是一種禍害。

不在其位,不謀其政。

不居於那個職位,便不考慮它的政務。

學如不及,猶恐失之。

做學問好像生怕趕不上,還生怕丟掉了。

毋意,毋必,毋固,毋我。

不懸空揣測,不絕對肯定,不拘泥固執,不唯我獨是。

逝者如斯夫!不舍晝夜。

消逝的時光像河水一樣呀!日夜不停地流去。

知者不惑,仁者不憂,勇者不懼。

聰明人不致疑惑,仁德的人經常樂觀,勇敢的人無所畏懼。

為仁由己,而由人乎哉?

實踐仁德,全憑自己,還憑別人嗎?

內省不疚,夫何憂何懼?

自己問心無愧,那有什麼可以憂愁和恐懼的呢?

浸潤之譖,膚受之愬,不行焉,可謂明也已矣。

點滴而來,日積月累的讒言和肌膚所受、急迫切身的誣告都在你這裡行不通,那你可以說是看得明白的了。

政者,正也。子帥以正,孰敢不正?

政字的意思就是端正。您自己帶頭端正,誰敢不端正呢?

夫達也者,質直而好義,察言而觀色,慮以下人。

怎樣才是達呢?品質正直,遇事講理,善於分析別人的言語,觀察別人的容色,從思想上願意對別人退讓。

先是後得,非崇德與?攻其惡,無攻人之惡,非修慝與?一朝之忿,忘其身,以及其親,非惑與?

首先付出勞動,然後收穫,不是提高品德了嗎?批判自己的壞處,而不去批判別人的壞處,不就消除無形的怨恨了嗎?因為偶然的忿怒,便忘記自己,甚至也忘記了父母,不是糊塗嗎?

如不善而莫之違也,不幾乎一言而喪邦乎?

假若說的話不正確而也沒有人違抗,不近於一句話便喪失國家麼?

人而無恆,不可以作巫醫。

人假若沒有恆心,連巫醫都做不了。

君子和而不同。

君子用自己正確意見來糾正別人的錯誤意見,使一切都做到恰到好處,卻不肯盲從附和。

小人難事而易說也。說之雖不以道,說也;及其使人也,求備焉。

在小人底下工作很難,討他的歡善卻容易。用不正當的方式去討他的歡喜,他會歡喜的;等到他使用人的時候,便會百般挑剔,求全責備。

君子恥其言而過其行。

說得多,做得少,君子以為恥。

不患人之不己知,患其不能也。

不著急別人不知道我,只著急自己沒有能力。

以直報怨,以德報德。

拿公平正直來回報怨恨,拿恩惠來酬答恩惠。

躬自厚而薄責於人,則遠怨矣。

多責備自己,而少責備別人,怨恨自然不會來了。

小不忍,則亂大謀。

小事情不忍耐,便會敗壞大事情。

吾嘗終日不食,終夜不寢,以思,無益,不如學也。

我曾經整天不吃,整夜不睡,去想,沒有益處,不如去學習。

道不同,不相為謀。

主張不同,不互相商議。

辭達而已矣。

言辭,足以達意便罷了。

益者三友,損者三友。友直,友諒,友多聞,益矣。友便辟,友善柔,友便佞,損矣。

有益的朋友三種,有害的朋友三種。同正直的人交友,同信實的人交友,同見聞廣博的人交友,便有益了。同諂媚奉承的人交友,同當面恭維背面譭謗的人交友,同誇誇其談的人交友,便有害了。

不學禮,無以立。

不學禮,便沒有立足社會的依據。

性相近也,習相遠也。

人性情本相近,因為習染不同,便相距懸遠。

敏則有功。

勤敏就會工作效率高、貢獻大。

道聽而塗說,德之棄也。

聽到道路傳言就四處傳播,這是應該革除的作風。

子日︰「有惡︰惡稱人之惡者,惡居下流而訕上者,惡勇而無禮者,惡果敢而窒者。」

孔子憎恨一味傳播別人壞處的人,憎恨在下位而譭謗上級的人,憎恨勇敢卻不懂禮節的人,憎恨勇於貫徹自己的主張,卻頑固不通,執拗到底的人。

小人之過也必文。

小人對於錯誤一定加以掩飾。


楊伯峻《論語譯注》

2025年10月27日星期一

職場生存學

勢者,因利而制權也。

所謂勢,就是根據於己有利的原則而採取臨機應變的作戰行動。

不戰而屈人之兵,善之善者也。

不經過交戰而能使敵人屈服,才算是高明中的最高明。

不若則能避之。

實力不如敵人,就要避免決戰。

善守者,藏於九地之下。

善於防守的人,隱藏自己的兵力就像藏在地下,深不可見。

奇正之變,不可勝窮也。

奇正的錯綜變化,卻是無窮無盡。

故善戰者,求之於勢,不責於人,故能擇人而任勢。

所以,善於指揮作戰的將帥,總是設法尋求有利的態勢,不強求自己的部屬,這樣他們的注意力就能不放在強求人上,而放在充分利用有利的態勢上。

兵之勝,避實而擊虛。

作戰取得勝利,是由於避開敵人實處而攻擊敵人的虛處。

無邀正正之旗,勿擊堂堂之陳,此治變者也。

不要去攔截那種旗幟整齊、陣形嚴密的敵軍,不要去攻擊那種陣容盛大、實力雄厚的敵軍,這是掌握戰術變化的方法。

故用兵之法,無恃其不來,恃吾有以待也。

所以用兵的法則是,不要指望敵人不來,而要依靠自己作好準備,嚴陣以待。

廉潔,可辱也。

自愛廉潔,就可能受不了敵人污辱而落入圈套。

兵非多益,惟無武進,足以併力、料敵、取人而已。

打勝仗不在於兵力越多越好,只要不是輕敵貿進,能集中兵力、判明敵情、取得人心就足夠了。

主不可以怒而興師,將不可以慍而致戰。

國君不可因一時惱怒而發動戰爭,將帥不可因一時氣憤而進行戰爭。


吳仁傑《新譯孫子讀本》