Could the compiler figure out if a static item is not used and then elide it
altogether. Or does it do this already?
I can use the following idiom in C++ (can't do it in Rust though) to have the
compiler elide static data (large lookup tables in library code for example) if
the end-user doesn't use it:
template <int n>
class Data
{
static_assert(n == 42, "");
template <int>
friend int get_value(int);
static const int values[3];
};
template <int n>
const int Data<n>::values[3] = { 1, 2, 3 };
template <int n = 42>
int get_value(int idx)
{
return Data<n>::values[idx];
}
If the end-user never calls get_value(...), then Data never gets instantiated
and the (potentially large) array never exists.
-Tommi
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev