libstdc++/41975

Daniel Krügler daniel.kruegler@googlemail.com
Tue Nov 22 22:49:00 GMT 2011


2011/11/22 Paolo Carlini <paolo.carlini@oracle.com>:
>> Regarding:
>>
>> +      static_assert(__or_<integral_constant<bool, __cache_hash_code>,
>> +                     integral_constant<bool,
>> +                       noexcept(declval<const _H1&>()(declval<const
>> _Key&>()))>
>> +                       >::value,
>> +           "Cache the hash code or qualify your hash functor with
>> noexcept");
>>
>> I would recommend to wrap the expression test in a wrapper trait combined
>> to ensure lazy evaluation. As written, this test is always performed,
>> regardless
>> of the value of __cache_hash_code.
>
> Right. Daniel, can you help Francois a bit more concretely, just to make
> sure we don't have to iterate on this?

Sure: Just introduce an (internal) trait as suggested in my original
suggestion, e.g.

template<typename _H1, typename _Key>
struct __is_nothrow_hashable : public integral_constant<bool,
         noexcept(declval<const _H1&>()(declval<const _Key&>()))>
{};

and use this wherever the "inline" expression was used, e.g. replace above
by

static_assert(__or_<integral_constant<bool, __cache_hash_code>,
                              __is_nothrow_hashable<_H1, _Key>>>::value,
           "Cache the hash code or qualify your hash functor with
           noexcept");

Doing so prevents that the noexcept expression is evaluated at all, unless
__cache_hash_code is false.

- Daniel



More information about the Libstdc++ mailing list