Boost logo

Boost Users :

Subject: [Boost-users] BOOST_STATIC_ASSERT with boost::array.static_size
From: Anton Daneyko (self_at_[hidden])
Date: 2013-07-11 14:27:11


Dear boost users, could someone tell me why this short program does not
compile?

#include <boost/array.hpp>
#include <boost/static_assert.hpp>

int main(int argc, const char *argv[])
{
  boost::array<int, 3> a1 = {{1, 1, 1}};
  BOOST_STATIC_ASSERT(a1.static_size == 3);
  return 0;
}

With g++ (4.3.4) I get the following error:
tmp.cpp: In function ‘int main(int, const char**)’:
tmp.cpp:7: error: ‘a1’ cannot appear in a constant-expression
tmp.cpp:7: error: `.' cannot appear in a constant-expression
tmp.cpp:7: error: template argument 1 is invalid

With icc (12.1.6) I get the following error:
tmp.cpp(7): error: this operator is not allowed in a template argument
expression
    BOOST_STATIC_ASSERT(a1.static_size == 3);
    ^

tmp.cpp(7): error: incomplete type is not allowed
    BOOST_STATIC_ASSERT(a1.static_size == 3);
    ^

compilation aborted for tmp.cpp (code 2)

However I can compile using IBM xlC compiler.

I thought that static_size is a compile time constant and can be used in
this context...



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