Boost logo

Boost :

Subject: Re: [boost] Boost.Exception and constexpr
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2013-01-10 13:51:44


Le 10/01/13 19:13, Andrey Semashev a écrit :
> On Thu, Jan 10, 2013 at 9:06 PM, Vicente J. Botet Escriba
> <vicente.botet_at_[hidden]> wrote:
>> Have you tried declaring arr as a constexpr?
> It doesn't make any difference, the error is the same.
>
The constructor for array must be declared constexpr as well.
The following works with clang 3.1, 3.2 and gcc 4.7.1, 4.7.2. I have no
access to other C++11 compilers now. Could you try it?

Best,
Vicente

// Note the comments //********

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

template< int m >
struct check
{
     static int get() { return m; }
};

int main(int, char*[])
{
     constexpr array< int, 5 > arr; // ***************
     check< arr.at(3) > a;
     return a.get(); // ***************
}


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