Skip to content

Commit 25d3402

Browse files
committed
First half of support for N3657; heterogenous lookups for set/multiset
llvm-svn: 188241
1 parent f09a3db commit 25d3402

File tree

12 files changed

+902
-0
lines changed

12 files changed

+902
-0
lines changed

libcxx/include/__functional_base

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ struct _LIBCPP_TYPE_VIS_ONLY less<void>
6868
template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
6969
auto operator()(_T1&& __t, _T2&& __u) const
7070
{ return _VSTD::forward<_T1>(__t) < _VSTD::forward<_T2>(__u); }
71+
typedef void is_transparent;
7172
};
7273
#endif
7374

@@ -501,6 +502,20 @@ template <class _Tp> void cref(const _Tp&&);// = delete;
501502

502503
#endif // _LIBCPP_HAS_NO_VARIADICS
503504

505+
#if _LIBCPP_STD_VER > 11
506+
template <class _Tp1, class _Tp2 = void>
507+
struct __is_transparent
508+
{
509+
private:
510+
struct __two {char __lx; char __lxx;};
511+
template <class _Up> static __two __test(...);
512+
template <class _Up> static char __test(typename _Up::is_transparent* = 0);
513+
public:
514+
static const bool value = sizeof(__test<_Tp1>(0)) == 1;
515+
};
516+
#endif
517+
518+
504519
_LIBCPP_END_NAMESPACE_STD
505520

506521
#endif // _LIBCPP_FUNCTIONAL_BASE

libcxx/include/functional

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,7 @@ struct _LIBCPP_TYPE_VIS_ONLY plus<void>
515515
template <class _T1, class _T2>
516516
_LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
517517
{ return _VSTD::forward<_T1>(__t) + _VSTD::forward<_T2>(__u); }
518+
typedef void is_transparent;
518519
};
519520
#endif
520521

@@ -537,6 +538,7 @@ struct _LIBCPP_TYPE_VIS_ONLY minus<void>
537538
template <class _T1, class _T2>
538539
_LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
539540
{ return _VSTD::forward<_T1>(__t) - _VSTD::forward<_T2>(__u); }
541+
typedef void is_transparent;
540542
};
541543
#endif
542544

@@ -559,6 +561,7 @@ struct _LIBCPP_TYPE_VIS_ONLY multiplies<void>
559561
template <class _T1, class _T2>
560562
_LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
561563
{ return _VSTD::forward<_T1>(__t) * _VSTD::forward<_T2>(__u); }
564+
typedef void is_transparent;
562565
};
563566
#endif
564567

@@ -581,6 +584,7 @@ struct _LIBCPP_TYPE_VIS_ONLY divides<void>
581584
template <class _T1, class _T2>
582585
_LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
583586
{ return _VSTD::forward<_T1>(__t) / _VSTD::forward<_T2>(__u); }
587+
typedef void is_transparent;
584588
};
585589
#endif
586590

@@ -603,6 +607,7 @@ struct _LIBCPP_TYPE_VIS_ONLY modulus<void>
603607
template <class _T1, class _T2>
604608
_LIBCPP_INLINE_VISIBILITY auto operator()(_T1&& __t, _T2&& __u) const
605609
{ return _VSTD::forward<_T1>(__t) % _VSTD::forward<_T2>(__u); }
610+
typedef void is_transparent;
606611
};
607612
#endif
608613

@@ -625,6 +630,7 @@ struct _LIBCPP_TYPE_VIS_ONLY negate<void>
625630
template <class _Tp>
626631
_LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const
627632
{ return -_VSTD::forward<_Tp>(__x); }
633+
typedef void is_transparent;
628634
};
629635
#endif
630636

@@ -647,6 +653,7 @@ struct _LIBCPP_TYPE_VIS_ONLY equal_to<void>
647653
template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
648654
auto operator()(_T1&& __t, _T2&& __u) const
649655
{ return _VSTD::forward<_T1>(__t) == _VSTD::forward<_T2>(__u); }
656+
typedef void is_transparent;
650657
};
651658
#endif
652659

@@ -669,6 +676,7 @@ struct _LIBCPP_TYPE_VIS_ONLY not_equal_to<void>
669676
template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
670677
auto operator()(_T1&& __t, _T2&& __u) const
671678
{ return _VSTD::forward<_T1>(__t) != _VSTD::forward<_T2>(__u); }
679+
typedef void is_transparent;
672680
};
673681
#endif
674682

@@ -691,6 +699,7 @@ struct _LIBCPP_TYPE_VIS_ONLY greater<void>
691699
template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
692700
auto operator()(_T1&& __t, _T2&& __u) const
693701
{ return _VSTD::forward<_T1>(__t) > _VSTD::forward<_T2>(__u); }
702+
typedef void is_transparent;
694703
};
695704
#endif
696705

@@ -715,6 +724,7 @@ struct _LIBCPP_TYPE_VIS_ONLY greater_equal<void>
715724
template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
716725
auto operator()(_T1&& __t, _T2&& __u) const
717726
{ return _VSTD::forward<_T1>(__t) >= _VSTD::forward<_T2>(__u); }
727+
typedef void is_transparent;
718728
};
719729
#endif
720730

@@ -737,6 +747,7 @@ struct _LIBCPP_TYPE_VIS_ONLY less_equal<void>
737747
template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
738748
auto operator()(_T1&& __t, _T2&& __u) const
739749
{ return _VSTD::forward<_T1>(__t) <= _VSTD::forward<_T2>(__u); }
750+
typedef void is_transparent;
740751
};
741752
#endif
742753

@@ -759,6 +770,7 @@ struct _LIBCPP_TYPE_VIS_ONLY logical_and<void>
759770
template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
760771
auto operator()(_T1&& __t, _T2&& __u) const
761772
{ return _VSTD::forward<_T1>(__t) && _VSTD::forward<_T2>(__u); }
773+
typedef void is_transparent;
762774
};
763775
#endif
764776

@@ -781,6 +793,7 @@ struct _LIBCPP_TYPE_VIS_ONLY logical_or<void>
781793
template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
782794
auto operator()(_T1&& __t, _T2&& __u) const
783795
{ return _VSTD::forward<_T1>(__t) || _VSTD::forward<_T2>(__u); }
796+
typedef void is_transparent;
784797
};
785798
#endif
786799

@@ -803,6 +816,7 @@ struct _LIBCPP_TYPE_VIS_ONLY logical_not<void>
803816
template <class _Tp>
804817
_LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const
805818
{ return !_VSTD::forward<_Tp>(__x); }
819+
typedef void is_transparent;
806820
};
807821
#endif
808822

@@ -825,6 +839,7 @@ struct _LIBCPP_TYPE_VIS_ONLY bit_and<void>
825839
template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
826840
auto operator()(_T1&& __t, _T2&& __u) const
827841
{ return _VSTD::forward<_T1>(__t) & _VSTD::forward<_T2>(__u); }
842+
typedef void is_transparent;
828843
};
829844
#endif
830845

@@ -847,6 +862,7 @@ struct _LIBCPP_TYPE_VIS_ONLY bit_or<void>
847862
template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
848863
auto operator()(_T1&& __t, _T2&& __u) const
849864
{ return _VSTD::forward<_T1>(__t) | _VSTD::forward<_T2>(__u); }
865+
typedef void is_transparent;
850866
};
851867
#endif
852868

@@ -869,6 +885,7 @@ struct _LIBCPP_TYPE_VIS_ONLY bit_xor<void>
869885
template <class _T1, class _T2> _LIBCPP_INLINE_VISIBILITY
870886
auto operator()(_T1&& __t, _T2&& __u) const
871887
{ return _VSTD::forward<_T1>(__t) ^ _VSTD::forward<_T2>(__u); }
888+
typedef void is_transparent;
872889
};
873890
#endif
874891

@@ -887,6 +904,7 @@ struct _LIBCPP_TYPE_VIS_ONLY bit_not<void>
887904
template <class _Tp>
888905
_LIBCPP_INLINE_VISIBILITY auto operator()(_Tp&& __x) const
889906
{ return ~_VSTD::forward<_Tp>(__x); }
907+
typedef void is_transparent;
890908
};
891909
#endif
892910

libcxx/include/set

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,13 +129,33 @@ public:
129129
// set operations:
130130
iterator find(const key_type& k);
131131
const_iterator find(const key_type& k) const;
132+
template<typename K>
133+
iterator find(const K& x);
134+
template<typename K>
135+
const_iterator find(const K& x) const; // C++14
136+
template<typename K>
137+
size_type count(const K& x) const; // C++14
138+
132139
size_type count(const key_type& k) const;
133140
iterator lower_bound(const key_type& k);
134141
const_iterator lower_bound(const key_type& k) const;
142+
template<typename K>
143+
iterator lower_bound(const K& x); // C++14
144+
template<typename K>
145+
const_iterator lower_bound(const K& x) const; // C++14
146+
135147
iterator upper_bound(const key_type& k);
136148
const_iterator upper_bound(const key_type& k) const;
149+
template<typename K>
150+
iterator upper_bound(const K& x); // C++14
151+
template<typename K>
152+
const_iterator upper_bound(const K& x) const; // C++14
137153
pair<iterator,iterator> equal_range(const key_type& k);
138154
pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
155+
template<typename K>
156+
pair<iterator,iterator> equal_range(const K& x); // C++14
157+
template<typename K>
158+
pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
139159
};
140160
141161
template <class Key, class Compare, class Allocator>
@@ -285,13 +305,32 @@ public:
285305
// set operations:
286306
iterator find(const key_type& k);
287307
const_iterator find(const key_type& k) const;
308+
template<typename K>
309+
iterator find(const K& x);
310+
template<typename K>
311+
const_iterator find(const K& x) const; // C++14
312+
288313
size_type count(const key_type& k) const;
289314
iterator lower_bound(const key_type& k);
290315
const_iterator lower_bound(const key_type& k) const;
316+
template<typename K>
317+
iterator lower_bound(const K& x); // C++14
318+
template<typename K>
319+
const_iterator lower_bound(const K& x) const; // C++14
320+
291321
iterator upper_bound(const key_type& k);
292322
const_iterator upper_bound(const key_type& k) const;
323+
template<typename K>
324+
iterator upper_bound(const K& x); // C++14
325+
template<typename K>
326+
const_iterator upper_bound(const K& x) const; // C++14
327+
293328
pair<iterator,iterator> equal_range(const key_type& k);
294329
pair<const_iterator,const_iterator> equal_range(const key_type& k) const;
330+
template<typename K>
331+
pair<iterator,iterator> equal_range(const K& x); // C++14
332+
template<typename K>
333+
pair<const_iterator,const_iterator> equal_range(const K& x) const; // C++14
295334
};
296335
297336
template <class Key, class Compare, class Allocator>
@@ -579,6 +618,17 @@ public:
579618
iterator find(const key_type& __k) {return __tree_.find(__k);}
580619
_LIBCPP_INLINE_VISIBILITY
581620
const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
621+
#if _LIBCPP_STD_VER > 11
622+
template <typename _K2>
623+
_LIBCPP_INLINE_VISIBILITY
624+
typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
625+
find(const _K2& __k) {return __tree_.find(__k);}
626+
template <typename _K2>
627+
_LIBCPP_INLINE_VISIBILITY
628+
typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
629+
find(const _K2& __k) const {return __tree_.find(__k);}
630+
#endif
631+
582632
_LIBCPP_INLINE_VISIBILITY
583633
size_type count(const key_type& __k) const
584634
{return __tree_.__count_unique(__k);}
@@ -588,18 +638,51 @@ public:
588638
_LIBCPP_INLINE_VISIBILITY
589639
const_iterator lower_bound(const key_type& __k) const
590640
{return __tree_.lower_bound(__k);}
641+
#if _LIBCPP_STD_VER > 11
642+
template <typename _K2>
643+
_LIBCPP_INLINE_VISIBILITY
644+
typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
645+
lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
646+
647+
template <typename _K2>
648+
_LIBCPP_INLINE_VISIBILITY
649+
typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
650+
lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
651+
#endif
652+
591653
_LIBCPP_INLINE_VISIBILITY
592654
iterator upper_bound(const key_type& __k)
593655
{return __tree_.upper_bound(__k);}
594656
_LIBCPP_INLINE_VISIBILITY
595657
const_iterator upper_bound(const key_type& __k) const
596658
{return __tree_.upper_bound(__k);}
659+
#if _LIBCPP_STD_VER > 11
660+
template <typename _K2>
661+
_LIBCPP_INLINE_VISIBILITY
662+
typename enable_if<__is_transparent<_Compare, _K2>::value,iterator>::type
663+
upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
664+
template <typename _K2>
665+
_LIBCPP_INLINE_VISIBILITY
666+
typename enable_if<__is_transparent<_Compare, _K2>::value,const_iterator>::type
667+
upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
668+
#endif
669+
597670
_LIBCPP_INLINE_VISIBILITY
598671
pair<iterator,iterator> equal_range(const key_type& __k)
599672
{return __tree_.__equal_range_unique(__k);}
600673
_LIBCPP_INLINE_VISIBILITY
601674
pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
602675
{return __tree_.__equal_range_unique(__k);}
676+
#if _LIBCPP_STD_VER > 11
677+
template <typename _K2>
678+
_LIBCPP_INLINE_VISIBILITY
679+
typename enable_if<__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
680+
equal_range(const _K2& __k) {return __tree_.__equal_range_unique(__k);}
681+
template <typename _K2>
682+
_LIBCPP_INLINE_VISIBILITY
683+
typename enable_if<__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
684+
equal_range(const _K2& __k) const {return __tree_.__equal_range_unique(__k);}
685+
#endif
603686
};
604687

605688
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES
@@ -917,27 +1000,72 @@ public:
9171000
iterator find(const key_type& __k) {return __tree_.find(__k);}
9181001
_LIBCPP_INLINE_VISIBILITY
9191002
const_iterator find(const key_type& __k) const {return __tree_.find(__k);}
1003+
#if _LIBCPP_STD_VER > 11
1004+
template <typename _K2>
1005+
_LIBCPP_INLINE_VISIBILITY
1006+
typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1007+
find(const _K2& __k) {return __tree_.find(__k);}
1008+
template <typename _K2>
1009+
_LIBCPP_INLINE_VISIBILITY
1010+
typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1011+
find(const _K2& __k) const {return __tree_.find(__k);}
1012+
#endif
1013+
9201014
_LIBCPP_INLINE_VISIBILITY
9211015
size_type count(const key_type& __k) const
9221016
{return __tree_.__count_multi(__k);}
1017+
9231018
_LIBCPP_INLINE_VISIBILITY
9241019
iterator lower_bound(const key_type& __k)
9251020
{return __tree_.lower_bound(__k);}
9261021
_LIBCPP_INLINE_VISIBILITY
9271022
const_iterator lower_bound(const key_type& __k) const
9281023
{return __tree_.lower_bound(__k);}
1024+
#if _LIBCPP_STD_VER > 11
1025+
template <typename _K2>
1026+
_LIBCPP_INLINE_VISIBILITY
1027+
typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1028+
lower_bound(const _K2& __k) {return __tree_.lower_bound(__k);}
1029+
1030+
template <typename _K2>
1031+
_LIBCPP_INLINE_VISIBILITY
1032+
typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1033+
lower_bound(const _K2& __k) const {return __tree_.lower_bound(__k);}
1034+
#endif
1035+
9291036
_LIBCPP_INLINE_VISIBILITY
9301037
iterator upper_bound(const key_type& __k)
9311038
{return __tree_.upper_bound(__k);}
9321039
_LIBCPP_INLINE_VISIBILITY
9331040
const_iterator upper_bound(const key_type& __k) const
9341041
{return __tree_.upper_bound(__k);}
1042+
#if _LIBCPP_STD_VER > 11
1043+
template <typename _K2>
1044+
_LIBCPP_INLINE_VISIBILITY
1045+
typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,iterator>::type
1046+
upper_bound(const _K2& __k) {return __tree_.upper_bound(__k);}
1047+
template <typename _K2>
1048+
_LIBCPP_INLINE_VISIBILITY
1049+
typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,const_iterator>::type
1050+
upper_bound(const _K2& __k) const {return __tree_.upper_bound(__k);}
1051+
#endif
1052+
9351053
_LIBCPP_INLINE_VISIBILITY
9361054
pair<iterator,iterator> equal_range(const key_type& __k)
9371055
{return __tree_.__equal_range_multi(__k);}
9381056
_LIBCPP_INLINE_VISIBILITY
9391057
pair<const_iterator,const_iterator> equal_range(const key_type& __k) const
9401058
{return __tree_.__equal_range_multi(__k);}
1059+
#if _LIBCPP_STD_VER > 11
1060+
template <typename _K2>
1061+
_LIBCPP_INLINE_VISIBILITY
1062+
typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<iterator,iterator>>::type
1063+
equal_range(const _K2& __k) {return __tree_.__equal_range_multi(__k);}
1064+
template <typename _K2>
1065+
_LIBCPP_INLINE_VISIBILITY
1066+
typename _VSTD::enable_if<_VSTD::__is_transparent<_Compare, _K2>::value,pair<const_iterator,const_iterator>>::type
1067+
equal_range(const _K2& __k) const {return __tree_.__equal_range_multi(__k);}
1068+
#endif
9411069
};
9421070

9431071
#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES

0 commit comments

Comments
 (0)