搜尋此網誌

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