
From: vicente.botet
I would prefer to have two separated hierarchies, one for constrained values that preserv its constraints, error handling, ... staticaly, and one for those tyhe constraint can be changed at runtime.
I wouldn't prefer to have two separate hierarchies with almost identical functionality and differing only in details.
Well we can have a single type that cover with the whole domain, but we will need more metaprogramming.
We already have a single type that covers both static and dynamic constraints, so what is the point? Did I misunderstood something?
I expect that a constrained integer will have the same size as an int, i.e. sizeof(int). Which is the size of an instance of the constrained class?
Here are some examples: GCC 4.3.2: 4 = sizeof (int) 4 = sizeof (bounded_int<int, 0, 128>::type) 12 = sizeof (bounded<int, int, int>::type) 4 = sizeof (constrained<int, is_even>) MSVC 8.0 SP1: 4 = sizeof (int) 8 = sizeof (bounded_int<int, 0, 128>::type) 20 = sizeof (bounded<int, int, int>::type) 8 = sizeof (constrained<int, is_even>) I don't know why MSVC cannot opimise the size as well as GCC, but anyway the library allows for perfect size optimisation with some compilers.
See below one possible implementation of static_constrained. Of course, the implementation is not complete. [snip] typedef static_constrained<even_traits> even_type;
int main() { even_type a(2); std::cout << "sizeof(even_type)=" << sizeof(even_type) << std::endl; even_type b(1); // throws }
So how is this different from: typedef constrained<int, is_even> even_type; ? Best regards, Robert