Hello Christopher,

BCS wrote:

Hello Walter,

Andrei suggests making a library type work for this rather than a
language attribute, but it's still an extra thing that will have to
be specified everywhere where used.

I've considered trying to make a template that compile time enforces
Non-null usage but can, with a version flag, be switched to a simple
alias/typedef of the internal type. Near zero overhead and possibly
just as strong a guard.

It's impossible.

You can create a struct that will throw an exception if you use it
uninitialized, or if you try assigning null to it. But the struct
cannot require that it is initialized.

You can add a contract that requires the struct be initialized, and
put the contract and declaration in a template.


Your right, but if you switch to a class and factory with no public constructor, you can make it work. The problem of perf going down the drain is avoidable if you can (in that mode) enforce compile time checking of most cases and requiter calls to do run time checks for the rest. If the template works right, than flipping back to alias/typedef mode leaves the run time checks and leave the unchecked code as correct while doing away with the perf problems.


Reply via email to