Boost logo

Boost :

Subject: Re: [boost] Boost.Exception and constexpr
From: Andrey Semashev (andrey.semashev_at_[hidden])
Date: 2013-01-10 14:36:35


On Thu, Jan 10, 2013 at 11:16 PM, Marshall Clow <mclow.lists_at_[hidden]> wrote:
> On Jan 10, 2013, at 9:06 AM, Vicente J. Botet Escriba <vicente.botet_at_[hidden]> wrote:
>
> Here's my test case (using a locally modified Boost::Array):
> constexpr boost::array<int, 10> arr_std {{ 0,1,2,3,4,5,6,7,8,9 }};
> int whatever [ arr.at(4) ];

FWIW, with gcc array size doesn't seem to have to be a constant
expression. The following terminates because of throwing an exception:

template< typename T, unsigned int n >
struct array
{
    constexpr array() {}
    constexpr T at(unsigned int i) const
    {
        return i < n ? T() : throw 0;
    }
};

int main(int, char*[])
{
    constexpr array< int, 5 > arr;
    int whatever[arr.at(10)];
    return whatever[0];
}


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk