Boost logo

Boost :

From: Mark Rodgers (mark.rodgers_at_[hidden])
Date: 2002-02-13 15:33:34


From: "Daniel Frey" <daniel.frey_at_[hidden]>

> template< typename T > class finalize
> {
> friend T;
> finalize() {}
> };

This has been suggested many times in the past but unfortunately
the standard gets in the way. See 7.1.5.3p2:

   "If the identifier resolves to a typedef-name or a template
   type-parameter, the elaborated-type-specifier is ill-formed.
   [Note: this implies that, within a class template with a
   template type-parameter T, the declaration

          friend class T;

   is ill-formed. ]"

Otherwise, yes, your finalize template would be a useful addition
to utility.hpp, although I'd prefer a different name maybe "key"
since it had other uses before it was made illegal. For example,
you could use it to restrict a function so that only a certain class
can call it:

struct Y;
struct X {
    void f( key<Y> );
};
struct Y {
    void g(X x) {
        x.f( key<Y>() );
    }
};

Since only Y can construct a key<Y>, no-one else can call X::f
(unless Y gave them the key).

Mark


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk