[algs] Implement implicit casting between compatible pair types
This commit is contained in:
parent
69d9114b53
commit
790315e0db
|
@ -217,6 +217,11 @@ struct hb_pair_t
|
|||
hb_pair_t (T1 a, T2 b) : first (a), second (b) {}
|
||||
hb_pair_t (const pair_t& o) : first (o.first), second (o.second) {}
|
||||
|
||||
template <typename Q1, typename Q2,
|
||||
hb_enable_if (hb_is_convertible (T1, Q1) &&
|
||||
hb_is_convertible (T2, T2))>
|
||||
operator hb_pair_t<Q1, Q2> () { return hb_pair_t<Q1, Q2> (first, second); }
|
||||
|
||||
hb_pair_t<T1, T2> reverse () const
|
||||
{ return hb_pair_t<T1, T2> (second, first); }
|
||||
|
||||
|
|
|
@ -73,5 +73,8 @@ main (int argc, char **argv)
|
|||
z = 3;
|
||||
assert (x == 3);
|
||||
|
||||
hb_pair_t<const int*, int> xp = hb_pair_t<int *, long> (nullptr, 0);
|
||||
xp = hb_pair_t<int *, double> (nullptr, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue