[algs] Add hb_swap() ala, and using, std::swap()
Use it in vector. Use ADL idiom.
This commit is contained in:
parent
bbaccf23d9
commit
8c05569930
|
@ -34,6 +34,7 @@
|
|||
#include "hb-null.hh"
|
||||
#include "hb-number.hh"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
/*
|
||||
* Flags
|
||||
|
@ -533,6 +534,16 @@ struct
|
|||
}
|
||||
HB_FUNCOBJ (hb_clamp);
|
||||
|
||||
struct
|
||||
{
|
||||
template <typename T> void
|
||||
operator () (T& a, T& b) const
|
||||
{
|
||||
using std::swap; // allow ADL
|
||||
swap (a, b);
|
||||
}
|
||||
}
|
||||
HB_FUNCOBJ (hb_swap);
|
||||
|
||||
/*
|
||||
* Bithacks.
|
||||
|
|
|
@ -274,7 +274,7 @@ struct graph_t
|
|||
|
||||
remap_all_obj_indices (id_map, &sorted_graph);
|
||||
|
||||
vertices_.swap (sorted_graph);
|
||||
hb_swap (vertices_, sorted_graph);
|
||||
sorted_graph.fini_deep ();
|
||||
}
|
||||
|
||||
|
@ -334,7 +334,7 @@ struct graph_t
|
|||
|
||||
remap_all_obj_indices (id_map, &sorted_graph);
|
||||
|
||||
vertices_.swap (sorted_graph);
|
||||
hb_swap (vertices_, sorted_graph);
|
||||
sorted_graph.fini_deep ();
|
||||
}
|
||||
|
||||
|
|
|
@ -87,19 +87,11 @@ struct hb_vector_t
|
|||
resize (0);
|
||||
}
|
||||
|
||||
void swap (hb_vector_t& other)
|
||||
friend void swap (hb_vector_t& a, hb_vector_t& b)
|
||||
{
|
||||
int allocated_copy = allocated;
|
||||
unsigned int length_copy = length;
|
||||
Type *arrayZ_copy = arrayZ;
|
||||
|
||||
allocated = other.allocated;
|
||||
length = other.length;
|
||||
arrayZ = other.arrayZ;
|
||||
|
||||
other.allocated = allocated_copy;
|
||||
other.length = length_copy;
|
||||
other.arrayZ = arrayZ_copy;
|
||||
hb_swap (a.allocated, b.allocated);
|
||||
hb_swap (a.length, b.length);
|
||||
hb_swap (a.arrayZ, b.arrayZ);
|
||||
}
|
||||
|
||||
hb_vector_t& operator = (const hb_vector_t &o)
|
||||
|
|
Loading…
Reference in New Issue