BOOST_STATIC_ASSERT with boost::array.static_size
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...
2013/7/11 Anton Daneyko <self@mezhaka.com>
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; }
You must write BOOST_STATIC_ASSERT(boost::array<int, 3>::static_size == 3); Here is a fixed version: #include <boost/array.hpp> #include <boost/static_assert.hpp> int main(int argc, const char *argv[]) { typedef boost::array<int, 3> array_t; array_t a1 = {{1, 1, 1}}; BOOST_STATIC_ASSERT(array_t::static_size == 3); return 0; } -- Best regards, Antony Polukhin
participants (2)
-
Anton Daneyko
-
Antony Polukhin