• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1//  (C) Copyright Jeremy Siek 1999.
2//  (C) Copyright David Abrahams 1999.
3//  (C) Copyright John Maddock 2001.
4//  Use, modification and distribution are subject to the
5//  Boost Software License, Version 1.0. (See accompanying file
6//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7
8//  See http://www.boost.org/libs/config for most recent version.
9
10//  MACRO:         BOOST_NO_OPERATORS_IN_NAMESPACE
11//  TITLE:         friend operators in namespace
12//  DESCRIPTION:   Compiler requires inherited operator
13//                 friend functions to be defined at namespace scope,
14//                 then using'ed to boost.
15//                 Probably GCC specific.  See boost/operators.hpp for example.
16
17namespace boost{
18
19//
20// the following is taken right out of <boost/operators.hpp>
21//
22template <class T>
23struct addable1
24{
25     friend T operator+(T x, const T& y) { return x += y; }
26     friend bool operator != (const T& a, const T& b) { return !(a == b); }
27};
28
29struct spoiler1
30{};
31
32spoiler1 operator+(const spoiler1&,const spoiler1&);
33bool operator !=(const spoiler1&, const spoiler1&);
34
35
36}  // namespace boost
37
38namespace boost_no_operators_in_namespace{
39
40struct spoiler2
41{};
42
43spoiler2 operator+(const spoiler2&,const spoiler2&);
44bool operator !=(const spoiler2&, const spoiler2&);
45
46
47class add : public boost::addable1<add>
48{
49   int val;
50public:
51   add(int i) { val = i; }
52   add(const add& a){ val = a.val; }
53   add& operator+=(const add& a) { val += a.val; return *this; }
54   bool operator==(const add& a)const { return val == a.val; }
55};
56
57int test()
58{
59   add a1(2);
60   add a2(3);
61   add a3(0);
62   a3 = a1 + a2;
63   bool b1 = (a1 == a2);
64   b1 = (a1 != a2);
65   (void)b1;
66   return 0;
67}
68
69}
70
71
72
73
74