[llvm] r210100 - Add operator== and operator!= to compare with nullptr.

David Blaikie dblaikie at gmail.com
Tue Jun 3 08:03:36 PDT 2014


Unit tests? (I say this in part because I recall giving Chris Lattner some
grief over a similar change (that turned out to be buggy...))

And if you're going to define some operators in terms of others you could
do that for all and implement A == nullptr as nullptr == A

On Jun 3, 2014 6:39 AM, "Rafael Espindola" <rafael.espindola at gmail.com>
wrote:
>
> Author: rafael
> Date: Tue Jun  3 08:26:18 2014
> New Revision: 210100
>
> URL: http://llvm.org/viewvc/llvm-project?rev=210100&view=rev
> Log:
> Add operator== and operator!= to compare with nullptr.
>
> Modified:
>     llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h
>
> Modified: llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h
> URL:
http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h?rev=210100&r1=210099&r2=210100&view=diff
>
==============================================================================
> --- llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h (original)
> +++ llvm/trunk/include/llvm/ADT/IntrusiveRefCntPtr.h Tue Jun  3 08:26:18
2014
> @@ -241,6 +241,26 @@ public:
>      return A != B.getPtr();
>    }
>
> +  template <class T>
> +  bool operator==(std::nullptr_t A, const IntrusiveRefCntPtr<T> &B) {
> +    return !B;
> +  }
> +
> +  template <class T>
> +  bool operator==(const IntrusiveRefCntPtr<T> &A, std::nullptr_t B) {
> +    return !A;
> +  }
> +
> +  template <class T>
> +  bool operator!=(std::nullptr_t A, const IntrusiveRefCntPtr<T> &B) {
> +    return !(A == B);
> +  }
> +
> +  template <class T>
> +  bool operator!=(const IntrusiveRefCntPtr<T> &A, std::nullptr_t B) {
> +    return !(A == B);
> +  }
> +
>
 //===----------------------------------------------------------------------===//
>  // LLVM-style downcasting support for IntrusiveRefCntPtr objects
>
 //===----------------------------------------------------------------------===//
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20140603/51635dff/attachment.html>


More information about the llvm-commits mailing list