// ----------------------------------------------------------------------
//
// tmplfrnd.cc - Do we support templated friends?
//
// History:
//   21-Sep-1999  WEB  Initial draft, adapted from SGIport
//   25-Apr-2001  WEB  s/<ISOcxxSyntax.hh>/"ISOcxx\/ISOcxxSyntax.hh"/
//
// ----------------------------------------------------------------------


#include "ISOcxx/ISOcxxSyntax.hh"


// ----------------------------------------------------------------------
// forward-declare the friend-to-be:
// ----------------------------------------------------------------------

template< class T >
struct F;


// ----------------------------------------------------------------------
// define C<T>, granting friendship to all F<> specializations:
// ----------------------------------------------------------------------

template< class T >
class C  {

public:
  C() : myT( T() )  { ; }  // constructor using T's default value

#if ! defined DEFECT_NO_FRIEND_TEMPLATES
private:
  template< class U >  friend struct F;
#endif
  T  myT;

};  // C<T>


// ----------------------------------------------------------------------
// define F<T> whose member f() requires friendship of C<T>:
// ----------------------------------------------------------------------

template< class T >
struct F  {

  T  f( C<T> const & c ) const  {  return  c.myT;  }

};  // F<t>


// ----------------------------------------------------------------------
// test driver:
// ----------------------------------------------------------------------

int  main()  {

  C<int>  ci;
  F<int>  fi;

  return  fi.f( ci );

}  // main()
