Re: Examples Heap Sort - problem
From: Chris \( Val \) (chrisval_at_bigpond.com.au)
Date: 12/15/04
- Next message: Chris \( Val \): "Re: Elegant way to do this?"
- Previous message: Chris \( Val \): "Re: help for a novice"
- In reply to: B. v Ingen Schenau: "Re: Examples Heap Sort - problem"
- Next in thread: Alwyn: "Re: Examples Heap Sort - problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 15 Dec 2004 19:40:13 +1100
"B. v Ingen Schenau" <bart@ingen.ddns.info> wrote in message
news:3262v5F3j336gU1@individual.net...
| Chris ( Val ) wrote:
|
| >
| > "B. v Ingen Schenau" <bart@ingen.ddns.info> wrote in message
| > news:322kkiF3hkq59U1@individual.net...
| > | Dumas wrote:
| >
| > [snip]
| >
| > | To get the number of elements in an array, you can use the following
| > | function
| > |
| > | template <typename T, size_t N>
| > | size_t array_size(T (&)[N]){return N;}
| >
| > [snip]
| >
| > True - However, I personally find it more readable to
| > use the following:
| >
| > template<typename DataType>
| > inline std::size_t SizeOf( DataType& Source )
| > {
| > return sizeof Source / sizeof* Source;
| > }
|
| The problem with this version is that it can be called with a pointer
| argument, which can lead to unexpected behaviour.
| When you use my version, the compiler will immediately diagnose the
| error that you ask the array length of a pointer.
Thanks Bart.
I agree that you're version is safer in this
regard, but I do like readability offered by
the more simplistic version :-)
Thanks for the tip.
Chris Val
- Next message: Chris \( Val \): "Re: Elegant way to do this?"
- Previous message: Chris \( Val \): "Re: help for a novice"
- In reply to: B. v Ingen Schenau: "Re: Examples Heap Sort - problem"
- Next in thread: Alwyn: "Re: Examples Heap Sort - problem"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|