Boost logo

Boost Users :

From: Todd Greer (TGreer_at_[hidden])
Date: 2006-08-08 16:10:56


Johan Råde wrote:

> We aren't actually testing static array initialization, are we? How do we
> know that it works at all? :-)

I can think of two tests that might be useful. I haven't had a chance to try either one yet. After adding in the appropriate #includes and namespace qualification, and following whatever the standard Boost test construction guidelines are, do these look like they would do the job?

1. Test that it is POD:

struct x {};
BOOST_STATIC_ASSERT(!is_pod<x>::value || is_pod<array<int> >::value)

On most compilers, is_pod always yields false for structs, and this test should pass, but is useless. On those compilers for which is_pod works on structs, this test will pass iff array<int> is a POD.

2. Test that it gets statically initialized:

test_static_initialization.h:

extern array<int> a;
extern array<int> b;
extern bool a_is_initialized;
extern bool b_is_initialized;

a.cpp:

#include "test_static_initialization.h"
array<int> a = { 1 };
bool const b_is_initialized = b[0] == 1;

b.cpp:

#include "test_static_initialization.h"
array<int> b = { 1 };
bool const a_is_initialized = a[0] == 1;

test_static_initialization.cpp:

#include "test_static_initialization.h"
int main()
{
  assert(a_is_initialized);
  assert(b_is_initialized);
}

What do you think?

-- 
Todd Greer		<tgreer (at) affinegy {dot} [com]>

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