[patch] libstdc++/69240 generic operator!= for random number distributions

Jonathan Wakely jwakely@redhat.com
Thu Jan 14 20:52:00 GMT 2016


On 14/01/16 20:46 +0000, Jonathan Wakely wrote:
>On 14/01/16 20:43 +0000, Jonathan Wakely wrote:
>>On 14/01/16 21:22 +0100, Daniel Krügler wrote:
>>>If there were an __is_direct_base_of intrinsic (or is there?), it
>>>seems to me that there would be no need for all these specializations
>>>(each one nearly taking as much space as the explicit inline
>>>definition of operator!) and there could be a single constrained
>>>operator!= that would only trigger for types that are direct base
>>>classes of __tag.
>>
>>Yes. In fact we do have a __direct_bases intrinsic, see
>><tr2/type_traits>. We'd need a bit of metaprogramming to see if
>>the__tag is one of __direct_bases(_Tp)... but that's doable.
>
>Bah, this causes an ICE:
>
>   template<typename _Tp,
>            typename = __or_<is_same<__tag, __direct_bases(_Tp)>...>>
>     inline bool
>     operator!=(const _Tp& __lhs, const _Tp& __rhs) noexcept
>     { return !(__lhs == __rhs); }
>

But this doesn't ICE:

    template<typename _Tp, typename... _Types>
      struct __is_one_of : __or_<is_same<_Tp, _Types>...>
      { };

    // Derive from this tag to define l != r as !(l == r).
    struct __tag { };

    /// Compare the parameters of two random number distributions.
    template<typename _Tp,
             typename = __is_one_of<__tag, __direct_bases(_Tp)...>>
      inline bool
      operator!=(const _Tp& __lhs, const _Tp& __rhs) noexcept
      { return !(__lhs == __rhs); }



More information about the Libstdc++ mailing list