It's impossible to friend a template parameter because the standard disallows it. How might I get effectively the same thing then?
What I want is basically a type that is unusable outside the object which owns it. Why is rather beside the point but if you really must know, I'm trying to formulate a set of smart pointers that answer the problem of sharing an owned resource. Thus what I'm looking to do is something like so, if it worked:
template < typename T, typename Owner >
struct accessible_member
{
private:
accessible_member() : val(T()) {}
accessible_member(T const& t) : val(t) {}
operator T& () { return val; }
operator T const& () const { return val; }
member_ptr<T> operator & () { return member_ptr<T>(val); }
friend class Owner;
};
Thus a class can't hold this object as a member unless it declares itself the owner, and if it's silly enough to expose it as is, it will be impossible to use outside the class being so stupid.