Now you have a function that can swap any type of variable, without having to overload the function for every data type. However, for classes and structures you'll still have to through function template specialization, or by overloading the operators for that class or structure. (overloading the equal operator is preferable)

I'll go directly onto an example. In August 1981, IBM and World Bank conducted the first known currency swap ever. At this point, the World Bank (which is Swizz) wanted to borrowmoney in Swiss Francs, and IBM (which is a US company) wanted to borrow the same amount in US dollars. They both wanted to do this by issuing bonds. Due to rarity value, IBM could issue bonds in the Swiss Francs at the same rate as the Swiss Treasury - the best possible rate for SFr (Swiss Francs), while it had a fairly "bad" rate at home - US Treasury plus 45 basis points (0.45%). The situation was similar for World Bank. It could issue dollar-denominated bonds at a rate of US Treasury plus 40 basis points (0.40%), while it had to pay Swiss Treasury plus 20 basis points (0.20%) for SFr. As you can see, IBM could borrow what World Bank needed (SFr) cheaper than World Bank could, and World Bank could borrow what IBM wanted - USD (US dollars) at a cheaper rate than IBM. The stage was ripe for a swap - IBM had the loan World Bank wanted, and the reverse was also true.

If the World Bank borrowed USD and lent them to IBM at US Treasury + 40 bp (basis points) it would lose no money, and IBM would get a better rate. If IBM borrowed SFr and lent them to the World Bank at Swiss Treasury + 10 bp, IBM would make ten bp, and so would the World Bank. If both of these loans were done, it would result in a profit to IBM of 15 bp, and a profit to the World Bank of 10 bp. Thus, World Bank and IBM implemented something like this.

Since IBM and World Bank both borrowed the same amount of money (the principal), there is no need to do all the money exchange the above implies. A number of the terms cancel against each other. If the money was actually moved around, IBM would intially get (principal) from World Bank, and World Bank would intially get (principal) from IBM. These cancel each other out, so no money is transferred initially. Each due date, IBM would be paying (interest on USD + 40 bp) to World Bank and recieving (interest on SFr + 10 bp) from World Bank. World Bank would be paying (interest on SFr + 10 bp) and recieving (interest on USD + 40 bp). These terms can be expressed as a difference: IBM would be receiving or paying (depending on the sign) ((interest on USD + 40 bp) - (interest on SFr + 10 bp)), which simplifies to (interest on USD - interest on SFR + 30 bp). World Bank would be on the opposite end of the transaction. This is all the exchange of money there is. In a "normal" transaction, IBM and World Bank would be paying the principals to each other at the end of the terms; however, as the principals were not exchanged in the first place, this is not necessary.

Note that as principals are never exchanged, the risk involved is much smaller than in a loan of similar size. (In the transaction above, the risk of default was close to zero, as both IBM and World Bank had an AAAcredit rating.)

Financial institutions quicly took an interest in this technique. They tried to facilitate it by (for a fee) finding partners for companies that wanted to partake in a swap. This proved fairly difficult - there was a lot of companies interested in swaps, but the swaps were often too different to be reconciled. This was handled by introducing a new party: The swap dealer. A swap dealer will function as a market maker by being willing to take either side in a swap, and adjusting rates depending on how much inventory it has on each side. Any risk not offset by selling opposing swaps is offset in the currency market.
This provided the liquidity that allowed the swap market to really take off.

1. [techspeak] To move information from a
fast-access memory to a slow-access memory (`swap out'), or vice
versa (`swap in'). Often refers specifically to the use of disks
as `virtual memory'. As pieces of data or program are needed,
they are swapped into core for processing; when they are no
longer needed they may be swapped out again. 2. The jargon use of
these terms analogizes people's short-term memories with core.
Cramming for an exam might be spoken of as swapping in. If you
temporarily forget someone's name, but then remember it, your
excuse is that it was swapped out. To `keep something swapped
in' means to keep it fresh in your memory: "I reread the TECO
manual every few months to keep it swapped in." If someone
interrupts you just as you got a good idea, you might say "Wait a
moment while I swap this out", implying that a piece of paper is
your extra-somatic memory and that if you don't swap the idea out
by writing it down it will get overwritten and lost as you talk.
Compare page in, page out.