[patch] [C++14] Implement N3657: heterogeneous lookup in associative containers.

François Dumont frs.dumont@gmail.com
Mon Jan 26 21:27:00 GMT 2015


Hi

     Thanks a lot for those explanations, very educative. I was indeed 
wondering what was the additional template parameter for.

     So here is a new attempt. While moving __is_transparent to std 
namespace I renamed to __has_is_transparent to not conflict with 
existing __is_transparent. I agree that it is another non-standard type 
in the std namespace but at the same time should'nt the whole content of 
stl_tree.h be in __gnu_cxx rather ? This is perhaps not a reason to make 
situation worst so tell me if you want me to move it to std::__detail 
namespace ?

     At the beginning I wanted to make something like in bits/map.h to 
not have to replicate the __is_transparent stuff. But I didn't found any 
way to do such a thing.

2015-01-22  François Dumont  <fdumont@gcc.gnu.org>

     * include/bits/stl_tree.h (_Rb_tree<>::__is_transparent<>): Move to 
outer
     scope and rename in ...
     (std::__hash_is_transparent<>): ... this.
     * include/debug/stl_map.h (map::find<>,
     map::lower_bound<>, map::upper_bound<>, map::equal_range<>): New
     member function templates to perform heterogeneous lookup.
     * include/debug/stl_multimap.h (multimap::find<>,
     multimap::lower_bound<>, multimap::upper_bound<>,
     multimap::equal_range<>): Likewise.
     * include/debug/stl_multiset.h (multiset::find<>,
     multiset::lower_bound<>, multiset::upper_bound<>,
     multiset::equal_range<>): Likewise.
     * include/debug/stl_set.h (set::find<>,
     set::lower_bound<>, set::upper_bound<>, set::equal_range<>): Likewise.
     * include/profile/stl_map.h (map::find<>, map::count<>,
     map::lower_bound<>, map::upper_bound<>, map::equal_range<>): Likewise.
     * include/profile/stl_multimap.h (multimap::find<>, multimap::cout<>,
     multimap::lower_bound<>, multimap::upper_bound<>,
     multimap::equal_range<>): Likewise.
     * include/profile/stl_multiset.h (multiset::find<>, multiset::count<>,
     multiset::lower_bound<>, multiset::upper_bound<>,
     multiset::equal_range<>): Likewise.
     * include/profile/stl_set.h (set::find<>, set::count<>,
     set::lower_bound<>, set::upper_bound<>, set::equal_range<>): Likewise.

Tested under Linux x86_64 normal, debug and profile modes.

François


On 26/01/2015 12:19, Jonathan Wakely wrote:
> On 24/01/15 22:46 +0000, Jonathan Wakely wrote:
>> On 24/01/15 23:03 +0100, François Dumont wrote:
>>> types. I am also surprised that it is not using enable_if, IMHO it 
>>> makes the code clearer.
>>
>> It doesn't work though.
>>
>>> @@ -1155,9 +1150,8 @@
>>>       return _S_iter(__y);
>>>     }
>>>
>>> -      template<typename _Kt,
>>> -           typename _Req = typename __is_transparent<_Compare, 
>>> _Kt>::type>
>>> -    iterator
>>> +      template<typename _Kt>
>>> + enable_if_t<__has_is_transparent<_Compare>::value, iterator>
>>>     _M_find_tr(const _Kt& __k)
>>
>> This doesn't work.
>>
>> Consider:
>>
>> #include <set>
>>
>> struct I
>> {
>>   int i;
>>   operator int() const { return i; }
>> };
>>
>> int main()
>> {
>>   std::set<int> s;
>>   I i = { };
>>   s.find(i);
>> }
>>
>> (I will add something like this to the testsuite.)
>
> Done with this patch, tested x86_64-linux and committed to trunk.
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: heterogeneous_lookup.patch
Type: text/x-patch
Size: 34379 bytes
Desc: not available
URL: <http://gcc.gnu.org/pipermail/libstdc++/attachments/20150126/b7be3d79/attachment.bin>


More information about the Libstdc++ mailing list