Taming constructors?
"Rob Meijer" <rmeijer-qWit8jRvyhVmR6Xm/[email protected]>
| Newsgroups | gmane.comp.capabilities.general |
|---|---|
| Message-ID | <[email protected]> |
A while ago I came up with a simple C++ template:
template <typename T>
class raiicap {
public:
friend int main(int,char **);
private:
raiicap(){}
};
This now allows main (as a root of authority) to create a raiicap<T> and
pass it as a token of authority.
Using this template in a constructor definition like this:
class raiiclass;
class raiiclass {
private:
..
public:
raiiclass(raiicap<raiiclass> const &);
..
};
basically allows the receiver of a raiicap<raiiclass> to instantiate a
raiiclass object. Given that only root can create a raiicap<T>, and given
that a raiicap<T> can be delegated, we end up with the authority to invoke
a constructor effectively becoming somewhat of a capability.
While the above is pretty much C++ specific code, both friends and
templates are unavailable in any other language that I know of, I think
the problem it solves is certainly not C++ specific. In fact, solving this
problem in memory secure languages may be even more important.
Is anyone aware of similar solutions for any memory safe languages?