Boost logo

Boost Users :

Subject: Re: [Boost-users] [Filesystem] String corruption in path in V3 and Boost 1.44
From: Scott McMurray (me22.ca+boost_at_[hidden])
Date: 2010-09-23 17:31:06


On Thu, Sep 23, 2010 at 02:08, Will Watts <willw_at_[hidden]> wrote:
>
> I am surprised the path class can 'know' the length of a C array. I
> guess that's the magic of templates for me.
>

It's actually quite simple:

    template <typename T, size_t N>
    size_t array_length(T (&)[N]) {
        return N;
    }

    int a[3];
    array_length(a) // returns 3
    char *p;
    array_length(p) // doesn't compile

The only trick is the necessity to pass the array by reference, since
they can't be passed by value.

~ Scott


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net