boost_no_mem_templ_frnds.ipp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. // (C) Copyright John Maddock 2001.
  2. // Use, modification and distribution are subject to the
  3. // Boost Software License, Version 1.0. (See accompanying file
  4. // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  5. // See http://www.boost.org/libs/config for most recent version.
  6. // MACRO: BOOST_NO_MEMBER_TEMPLATE_FRIENDS
  7. // TITLE: member template friends
  8. // DESCRIPTION: Member template friend syntax
  9. // ("template<class P> friend class frd;")
  10. // described in the C++ Standard,
  11. // 14.5.3, not supported.
  12. namespace boost_no_member_template_friends{
  13. template <class T>
  14. class foobar;
  15. template <class T>
  16. class foo;
  17. template <class T>
  18. bool must_be_friend_proc(const foo<T>& f);
  19. template <class T>
  20. class foo
  21. {
  22. private:
  23. template<typename Y> friend class foobar;
  24. template<typename Y> friend class foo;
  25. template<typename Y> friend bool must_be_friend_proc(const foo<Y>& f);
  26. int i;
  27. public:
  28. foo(){ i = 0; }
  29. template <class U>
  30. foo(const foo<U>& f){ i = f.i; }
  31. };
  32. template <class T>
  33. bool must_be_friend_proc(const foo<T>& f)
  34. { return f.i != 0; }
  35. template <class T>
  36. class foobar
  37. {
  38. int i;
  39. public:
  40. template <class U>
  41. foobar(const foo<U>& f)
  42. { i = f.i; }
  43. };
  44. int test()
  45. {
  46. foo<int> fi;
  47. foo<double> fd(fi);
  48. must_be_friend_proc(fd);
  49. foobar<long> fb(fi);
  50. (void) &fb; // avoid "unused variable" warning
  51. return 0;
  52. }
  53. }