stl: std::pair/std::make_pair

This commit is contained in:
skypjack
2026-04-01 16:50:07 +02:00
parent 80fdab4f21
commit bfe84b59d0
14 changed files with 64 additions and 62 deletions

View File

@@ -31,7 +31,7 @@ static constexpr std::size_t dense_map_placeholder_position = (std::numeric_limi
template<typename Key, typename Type>
struct dense_map_node final {
using value_type = std::pair<Key, Type>;
using value_type = stl::pair<Key, Type>;
template<typename... Args>
dense_map_node(const std::size_t pos, Args &&...args)
@@ -65,7 +65,7 @@ class dense_map_iterator final {
using second_type = decltype((stl::declval<It>()->element.second));
public:
using value_type = std::pair<first_type, second_type>;
using value_type = stl::pair<first_type, second_type>;
using pointer = input_iterator_pointer<value_type>;
using reference = value_type;
using difference_type = std::ptrdiff_t;
@@ -160,7 +160,7 @@ class dense_map_local_iterator final {
using second_type = decltype((stl::declval<It>()->element.second));
public:
using value_type = std::pair<first_type, second_type>;
using value_type = stl::pair<first_type, second_type>;
using pointer = input_iterator_pointer<value_type>;
using reference = value_type;
using difference_type = std::ptrdiff_t;
@@ -235,7 +235,7 @@ class dense_map {
using node_type = internal::dense_map_node<Key, Type>;
using alloc_traits = std::allocator_traits<Allocator>;
static_assert(stl::is_same_v<typename alloc_traits::value_type, std::pair<const Key, Type>>, "Invalid value type");
static_assert(stl::is_same_v<typename alloc_traits::value_type, stl::pair<const Key, Type>>, "Invalid value type");
using sparse_container_type = stl::vector<std::size_t, typename alloc_traits::template rebind_alloc<std::size_t>>;
using packed_container_type = stl::vector<node_type, typename alloc_traits::template rebind_alloc<node_type>>;
@@ -269,14 +269,14 @@ class dense_map {
const auto index = key_to_bucket(key);
if(auto it = constrained_find(key, index); it != end()) {
return std::make_pair(it, false);
return stl::make_pair(it, false);
}
packed.first().emplace_back(sparse.first()[index], std::piecewise_construct, stl::forward_as_tuple(stl::forward<Other>(key)), stl::forward_as_tuple(stl::forward<Args>(args)...));
sparse.first()[index] = packed.first().size() - 1u;
rehash_if_required();
return std::make_pair(--end(), true);
return stl::make_pair(--end(), true);
}
template<typename Other, typename Arg>
@@ -285,14 +285,14 @@ class dense_map {
if(auto it = constrained_find(key, index); it != end()) {
it->second = stl::forward<Arg>(value);
return std::make_pair(it, false);
return stl::make_pair(it, false);
}
packed.first().emplace_back(sparse.first()[index], stl::forward<Other>(key), stl::forward<Arg>(value));
sparse.first()[index] = packed.first().size() - 1u;
rehash_if_required();
return std::make_pair(--end(), true);
return stl::make_pair(--end(), true);
}
void move_and_pop(const std::size_t pos) {
@@ -320,7 +320,7 @@ public:
/*! @brief Mapped type of the container. */
using mapped_type = Type;
/*! @brief Key-value type of the container. */
using value_type = std::pair<const Key, Type>;
using value_type = stl::pair<const Key, Type>;
/*! @brief Unsigned integer type. */
using size_type = std::size_t;
/*! @brief Signed integer type. */
@@ -520,12 +520,12 @@ public:
* the element that prevented the insertion) and a bool denoting whether the
* insertion took place.
*/
std::pair<iterator, bool> insert(const value_type &value) {
stl::pair<iterator, bool> insert(const value_type &value) {
return insert_or_do_nothing(value.first, value.second);
}
/*! @copydoc insert */
std::pair<iterator, bool> insert(value_type &&value) {
stl::pair<iterator, bool> insert(value_type &&value) {
return insert_or_do_nothing(stl::move(value.first), stl::move(value.second));
}
@@ -535,7 +535,7 @@ public:
*/
template<typename Arg>
requires std::constructible_from<value_type, Arg &&>
std::pair<iterator, bool> insert(Arg &&value) {
stl::pair<iterator, bool> insert(Arg &&value) {
return insert_or_do_nothing(stl::forward<Arg>(value).first, stl::forward<Arg>(value).second);
}
@@ -560,13 +560,13 @@ public:
* denoting whether the insertion took place.
*/
template<typename Arg>
std::pair<iterator, bool> insert_or_assign(const key_type &key, Arg &&value) {
stl::pair<iterator, bool> insert_or_assign(const key_type &key, Arg &&value) {
return insert_or_overwrite(key, stl::forward<Arg>(value));
}
/*! @copydoc insert_or_assign */
template<typename Arg>
std::pair<iterator, bool> insert_or_assign(key_type &&key, Arg &&value) {
stl::pair<iterator, bool> insert_or_assign(key_type &&key, Arg &&value) {
return insert_or_overwrite(stl::move(key), stl::forward<Arg>(value));
}
@@ -584,7 +584,7 @@ public:
* insertion took place.
*/
template<typename... Args>
std::pair<iterator, bool> emplace([[maybe_unused]] Args &&...args) {
stl::pair<iterator, bool> emplace([[maybe_unused]] Args &&...args) {
if constexpr(sizeof...(Args) == 0u) {
return insert_or_do_nothing(key_type{});
} else if constexpr(sizeof...(Args) == 1u) {
@@ -597,13 +597,13 @@ public:
if(auto it = constrained_find(node.element.first, index); it != end()) {
packed.first().pop_back();
return std::make_pair(it, false);
return stl::make_pair(it, false);
}
std::swap(node.next, sparse.first()[index]);
rehash_if_required();
return std::make_pair(--end(), true);
return stl::make_pair(--end(), true);
}
}
@@ -619,13 +619,13 @@ public:
* insertion took place.
*/
template<typename... Args>
std::pair<iterator, bool> try_emplace(const key_type &key, Args &&...args) {
stl::pair<iterator, bool> try_emplace(const key_type &key, Args &&...args) {
return insert_or_do_nothing(key, stl::forward<Args>(args)...);
}
/*! @copydoc try_emplace */
template<typename... Args>
std::pair<iterator, bool> try_emplace(key_type &&key, Args &&...args) {
stl::pair<iterator, bool> try_emplace(key_type &&key, Args &&...args) {
return insert_or_do_nothing(stl::move(key), stl::forward<Args>(args)...);
}
@@ -788,13 +788,13 @@ public:
* @return A pair of iterators pointing to the first element and past the
* last element of the range.
*/
[[nodiscard]] std::pair<iterator, iterator> equal_range(const key_type &key) {
[[nodiscard]] stl::pair<iterator, iterator> equal_range(const key_type &key) {
const auto it = find(key);
return {it, it + !(it == end())};
}
/*! @copydoc equal_range */
[[nodiscard]] std::pair<const_iterator, const_iterator> equal_range(const key_type &key) const {
[[nodiscard]] stl::pair<const_iterator, const_iterator> equal_range(const key_type &key) const {
const auto it = find(key);
return {it, it + !(it == cend())};
}
@@ -806,14 +806,14 @@ public:
* @return A pair of iterators pointing to the first element and past the
* last element of the range.
*/
[[nodiscard]] std::pair<iterator, iterator> equal_range(const auto &key)
[[nodiscard]] stl::pair<iterator, iterator> equal_range(const auto &key)
requires is_transparent_v<hasher> && is_transparent_v<key_equal> {
const auto it = find(key);
return {it, it + !(it == end())};
}
/*! @copydoc equal_range */
[[nodiscard]] std::pair<const_iterator, const_iterator> equal_range(const auto &key) const
[[nodiscard]] stl::pair<const_iterator, const_iterator> equal_range(const auto &key) const
requires is_transparent_v<hasher> && is_transparent_v<key_equal> {
const auto it = find(key);
return {it, it + !(it == cend())};

View File

@@ -197,7 +197,7 @@ class dense_set {
static constexpr std::size_t minimum_capacity = 8u;
static constexpr std::size_t placeholder_position = internal::dense_set_placeholder_position;
using node_type = std::pair<std::size_t, Type>;
using node_type = stl::pair<std::size_t, Type>;
using alloc_traits = std::allocator_traits<Allocator>;
static_assert(stl::is_same_v<typename alloc_traits::value_type, Type>, "Invalid value type");
using sparse_container_type = stl::vector<std::size_t, typename alloc_traits::template rebind_alloc<std::size_t>>;
@@ -232,14 +232,14 @@ class dense_set {
const auto index = value_to_bucket(value);
if(auto it = constrained_find(value, index); it != end()) {
return std::make_pair(it, false);
return stl::make_pair(it, false);
}
packed.first().emplace_back(sparse.first()[index], stl::forward<Other>(value));
sparse.first()[index] = packed.first().size() - 1u;
rehash_if_required();
return std::make_pair(--end(), true);
return stl::make_pair(--end(), true);
}
void move_and_pop(const std::size_t pos) {
@@ -509,12 +509,12 @@ public:
* the element that prevented the insertion) and a bool denoting whether the
* insertion took place.
*/
std::pair<iterator, bool> insert(const value_type &value) {
stl::pair<iterator, bool> insert(const value_type &value) {
return insert_or_do_nothing(value);
}
/*! @copydoc insert */
std::pair<iterator, bool> insert(value_type &&value) {
stl::pair<iterator, bool> insert(value_type &&value) {
return insert_or_do_nothing(stl::move(value));
}
@@ -543,7 +543,7 @@ public:
* insertion took place.
*/
template<typename... Args>
std::pair<iterator, bool> emplace(Args &&...args) {
stl::pair<iterator, bool> emplace(Args &&...args) {
if constexpr(((sizeof...(Args) == 1u) && ... && stl::is_same_v<std::decay_t<Args>, value_type>)) {
return insert_or_do_nothing(stl::forward<Args>(args)...);
} else {
@@ -552,13 +552,13 @@ public:
if(auto it = constrained_find(node.second, index); it != end()) {
packed.first().pop_back();
return std::make_pair(it, false);
return stl::make_pair(it, false);
}
std::swap(node.first, sparse.first()[index]);
rehash_if_required();
return std::make_pair(--end(), true);
return stl::make_pair(--end(), true);
}
}
@@ -664,13 +664,13 @@ public:
* @return A pair of iterators pointing to the first element and past the
* last element of the range.
*/
[[nodiscard]] std::pair<iterator, iterator> equal_range(const value_type &value) {
[[nodiscard]] stl::pair<iterator, iterator> equal_range(const value_type &value) {
const auto it = find(value);
return {it, it + !(it == end())};
}
/*! @copydoc equal_range */
[[nodiscard]] std::pair<const_iterator, const_iterator> equal_range(const value_type &value) const {
[[nodiscard]] stl::pair<const_iterator, const_iterator> equal_range(const value_type &value) const {
const auto it = find(value);
return {it, it + !(it == cend())};
}
@@ -682,14 +682,14 @@ public:
* @return A pair of iterators pointing to the first element and past the
* last element of the range.
*/
[[nodiscard]] std::pair<iterator, iterator> equal_range(const auto &value)
[[nodiscard]] stl::pair<iterator, iterator> equal_range(const auto &value)
requires is_transparent_v<hasher> && is_transparent_v<key_equal> {
const auto it = find(value);
return {it, it + !(it == end())};
}
/*! @copydoc equal_range */
[[nodiscard]] std::pair<const_iterator, const_iterator> equal_range(const auto &value) const
[[nodiscard]] stl::pair<const_iterator, const_iterator> equal_range(const auto &value) const
requires is_transparent_v<hasher> && is_transparent_v<key_equal> {
const auto it = find(value);
return {it, it + !(it == cend())};

View File

@@ -13,7 +13,7 @@ template<
typename Type,
typename = std::hash<Key>,
typename = std::equal_to<>,
typename = std::allocator<std::pair<const Key, Type>>>
typename = std::allocator<stl::pair<const Key, Type>>>
class dense_map;
template<

View File

@@ -135,8 +135,8 @@ struct uses_allocator_construction {
};
template<typename Type, typename Other>
struct uses_allocator_construction<std::pair<Type, Other>> {
using type = std::pair<Type, Other>;
struct uses_allocator_construction<stl::pair<Type, Other>> {
using type = stl::pair<Type, Other>;
template<typename First, typename Second>
static constexpr auto args(const auto &allocator, std::piecewise_construct_t, First &&first, Second &&second) noexcept {
@@ -156,12 +156,12 @@ struct uses_allocator_construction<std::pair<Type, Other>> {
}
template<typename First, typename Second>
static constexpr auto args(const auto &allocator, const std::pair<First, Second> &value) noexcept {
static constexpr auto args(const auto &allocator, const stl::pair<First, Second> &value) noexcept {
return uses_allocator_construction<type>::args(allocator, std::piecewise_construct, stl::forward_as_tuple(value.first), stl::forward_as_tuple(value.second));
}
template<typename First, typename Second>
static constexpr auto args(const auto &allocator, std::pair<First, Second> &&value) noexcept {
static constexpr auto args(const auto &allocator, stl::pair<First, Second> &&value) noexcept {
return uses_allocator_construction<type>::args(allocator, std::piecewise_construct, stl::forward_as_tuple(stl::move(value.first)), stl::forward_as_tuple(stl::move(value.second)));
}
};

View File

@@ -44,7 +44,7 @@ class registry_storage_iterator final {
using mapped_type = std::remove_reference_t<decltype(stl::declval<It>()->second)>;
public:
using value_type = std::pair<id_type, constness_as_t<typename mapped_type::element_type, mapped_type> &>;
using value_type = stl::pair<id_type, constness_as_t<typename mapped_type::element_type, mapped_type> &>;
using pointer = input_iterator_pointer<value_type>;
using reference = value_type;
using difference_type = std::ptrdiff_t;
@@ -132,7 +132,7 @@ private:
template<typename Allocator>
class registry_context {
using alloc_traits = std::allocator_traits<Allocator>;
using allocator_type = alloc_traits::template rebind_alloc<std::pair<const id_type, basic_any<0u>>>;
using allocator_type = alloc_traits::template rebind_alloc<stl::pair<const id_type, basic_any<0u>>>;
public:
explicit registry_context(const allocator_type &allocator)
@@ -214,8 +214,8 @@ class basic_registry {
using alloc_traits = std::allocator_traits<Allocator>;
static_assert(stl::is_same_v<typename alloc_traits::value_type, Entity>, "Invalid value type");
// std::shared_ptr because of its type erased allocator which is useful here
using pool_container_type = dense_map<id_type, std::shared_ptr<base_type>, stl::identity, std::equal_to<>, typename alloc_traits::template rebind_alloc<std::pair<const id_type, std::shared_ptr<base_type>>>>;
using group_container_type = dense_map<id_type, std::shared_ptr<internal::group_descriptor>, stl::identity, std::equal_to<>, typename alloc_traits::template rebind_alloc<std::pair<const id_type, std::shared_ptr<internal::group_descriptor>>>>;
using pool_container_type = dense_map<id_type, std::shared_ptr<base_type>, stl::identity, std::equal_to<>, typename alloc_traits::template rebind_alloc<stl::pair<const id_type, std::shared_ptr<base_type>>>>;
using group_container_type = dense_map<id_type, std::shared_ptr<internal::group_descriptor>, stl::identity, std::equal_to<>, typename alloc_traits::template rebind_alloc<stl::pair<const id_type, std::shared_ptr<internal::group_descriptor>>>>;
using traits_type = entt_traits<Entity>;
template<cvref_unqualified Type>

View File

@@ -310,7 +310,7 @@ class basic_continuous_loader {
remloc[entity].second = reg->create();
}
} else {
remloc.insert_or_assign(entity, std::make_pair(entt, reg->create()));
remloc.insert_or_assign(entity, stl::make_pair(entt, reg->create()));
}
}
@@ -500,7 +500,7 @@ public:
}
private:
dense_map<typename traits_type::entity_type, std::pair<entity_type, entity_type>> remloc;
dense_map<typename traits_type::entity_type, stl::pair<entity_type, entity_type>> remloc;
registry_type *reg;
};

View File

@@ -26,7 +26,7 @@ class edge_iterator {
}
public:
using value_type = std::pair<size_type, size_type>;
using value_type = stl::pair<size_type, size_type>;
using pointer = input_iterator_pointer<value_type>;
using reference = value_type;
using difference_type = std::ptrdiff_t;
@@ -61,7 +61,7 @@ public:
}
[[nodiscard]] constexpr pointer operator->() const noexcept {
return std::make_pair<size_type>(pos / vert, pos % vert);
return stl::make_pair<size_type>(pos / vert, pos % vert);
}
[[nodiscard]] constexpr bool operator==(const edge_iterator &other) const noexcept {
@@ -98,7 +98,7 @@ public:
/*! @brief Vertex type. */
using vertex_type = size_type;
/*! @brief Edge type. */
using edge_type = std::pair<vertex_type, vertex_type>;
using edge_type = stl::pair<vertex_type, vertex_type>;
/*! @brief Vertex iterator type. */
using vertex_iterator = iota_iterator<vertex_type>;
/*! @brief Edge iterator type. */
@@ -280,7 +280,7 @@ public:
* the element that prevented the insertion) and a bool denoting whether the
* insertion took place.
*/
std::pair<edge_iterator, bool> insert(const vertex_type lhs, const vertex_type rhs) {
stl::pair<edge_iterator, bool> insert(const vertex_type lhs, const vertex_type rhs) {
const auto pos = lhs * vert + rhs;
if constexpr(stl::is_same_v<graph_category, undirected_tag>) {

View File

@@ -31,8 +31,8 @@ class basic_flow {
using alloc_traits = std::allocator_traits<Allocator>;
static_assert(stl::is_same_v<typename alloc_traits::value_type, id_type>, "Invalid value type");
using task_container_type = dense_set<id_type, stl::identity, std::equal_to<>, typename alloc_traits::template rebind_alloc<id_type>>;
using ro_rw_container_type = stl::vector<std::pair<std::size_t, bool>, typename alloc_traits::template rebind_alloc<std::pair<std::size_t, bool>>>;
using deps_container_type = dense_map<id_type, ro_rw_container_type, stl::identity, std::equal_to<>, typename alloc_traits::template rebind_alloc<std::pair<const id_type, ro_rw_container_type>>>;
using ro_rw_container_type = stl::vector<stl::pair<std::size_t, bool>, typename alloc_traits::template rebind_alloc<stl::pair<std::size_t, bool>>>;
using deps_container_type = dense_map<id_type, ro_rw_container_type, stl::identity, std::equal_to<>, typename alloc_traits::template rebind_alloc<stl::pair<const id_type, ro_rw_container_type>>>;
using adjacency_matrix_type = adjacency_matrix<directed_tag, typename alloc_traits::template rebind_alloc<std::size_t>>;
void emplace(const id_type res, const bool is_rw) {

View File

@@ -1688,10 +1688,10 @@ private:
};
class meta_associative_container::meta_iterator final {
using vtable_type = void(const void *, std::pair<meta_any, meta_any> *);
using vtable_type = void(const void *, stl::pair<meta_any, meta_any> *);
template<bool KeyOnly, typename It>
static void basic_vtable(const void *value, std::pair<meta_any, meta_any> *other) {
static void basic_vtable(const void *value, stl::pair<meta_any, meta_any> *other) {
if(const auto &it = *static_cast<const It *>(value); other) {
if constexpr(KeyOnly) {
other->first.emplace<decltype(*it)>(*it);
@@ -1705,7 +1705,7 @@ class meta_associative_container::meta_iterator final {
}
public:
using value_type = std::pair<meta_any, meta_any>;
using value_type = stl::pair<meta_any, meta_any>;
using pointer = input_iterator_pointer<value_type>;
using reference = value_type;
using difference_type = std::ptrdiff_t;

View File

@@ -19,7 +19,7 @@ struct meta_base_node;
template<typename Type, typename It>
struct meta_range_iterator final {
using value_type = std::pair<id_type, Type>;
using value_type = stl::pair<id_type, Type>;
using pointer = input_iterator_pointer<value_type>;
using reference = value_type;
using difference_type = std::ptrdiff_t;

View File

@@ -30,7 +30,7 @@ class resource_cache_iterator final {
friend class resource_cache_iterator;
public:
using value_type = std::pair<id_type, resource<Type>>;
using value_type = stl::pair<id_type, resource<Type>>;
using pointer = input_iterator_pointer<value_type>;
using reference = value_type;
using difference_type = std::ptrdiff_t;
@@ -127,7 +127,7 @@ template<typename Type, typename Loader, typename Allocator>
class resource_cache {
using alloc_traits = std::allocator_traits<Allocator>;
static_assert(stl::is_same_v<typename alloc_traits::value_type, Type>, "Invalid value type");
using container_allocator = alloc_traits::template rebind_alloc<std::pair<const id_type, typename Loader::result_type>>;
using container_allocator = alloc_traits::template rebind_alloc<stl::pair<const id_type, typename Loader::result_type>>;
using container_type = dense_map<id_type, typename Loader::result_type, stl::identity, std::equal_to<>, container_allocator>;
public:
@@ -287,7 +287,7 @@ public:
* insertion took place.
*/
template<typename... Args>
std::pair<iterator, bool> load(const id_type id, Args &&...args) {
stl::pair<iterator, bool> load(const id_type id, Args &&...args) {
if(auto it = pool.first().find(id); it != pool.first().end()) {
return {it, false};
}
@@ -300,7 +300,7 @@ public:
* @copydetails load
*/
template<typename... Args>
std::pair<iterator, bool> force_load(const id_type id, Args &&...args) {
stl::pair<iterator, bool> force_load(const id_type id, Args &&...args) {
return {pool.first().insert_or_assign(id, pool.second()(stl::forward<Args>(args)...)).first, true};
}

View File

@@ -112,7 +112,7 @@ class basic_dispatcher {
using mapped_type = std::shared_ptr<internal::basic_dispatcher_handler>;
using alloc_traits = std::allocator_traits<Allocator>;
using container_allocator = alloc_traits::template rebind_alloc<std::pair<const key_type, mapped_type>>;
using container_allocator = alloc_traits::template rebind_alloc<stl::pair<const key_type, mapped_type>>;
using container_type = dense_map<key_type, mapped_type, stl::identity, std::equal_to<>, container_allocator>;
template<cvref_unqualified Type>

View File

@@ -38,7 +38,7 @@ class emitter {
using mapped_type = std::function<void(void *)>;
using alloc_traits = std::allocator_traits<Allocator>;
using container_allocator = alloc_traits::template rebind_alloc<std::pair<const key_type, mapped_type>>;
using container_allocator = alloc_traits::template rebind_alloc<stl::pair<const key_type, mapped_type>>;
using container_type = dense_map<key_type, mapped_type, stl::identity, std::equal_to<>, container_allocator>;
public:

View File

@@ -10,7 +10,9 @@ using std::as_const;
using std::declval;
using std::exchange;
using std::forward;
using std::make_pair;
using std::move;
using std::pair;
} // namespace entt::stl
/*! @endcond */