meta: drop meta op cbegin/cend, use unused param value to pass constness around

This commit is contained in:
skypjack
2023-07-19 10:23:30 +02:00
committed by Michele Caini
parent f775d3be67
commit b1b4c67b75
2 changed files with 33 additions and 26 deletions

View File

@@ -78,16 +78,20 @@ struct basic_meta_sequence_container_traits {
break;
}
case operation::begin:
*it = iterator{ctx, const_cast<Type *>(cont)->begin()};
if(value) {
*it = iterator{ctx, const_cast<Type *>(cont)->begin()};
} else {
*it = iterator{ctx, cont->begin()};
}
return true;
case operation::end:
*it = iterator{ctx, const_cast<Type *>(cont)->end()};
return true;
case operation::cbegin:
*it = iterator{ctx, cont->begin()};
return true;
case operation::cend:
*it = iterator{ctx, cont->end()};
if(value) {
*it = iterator{ctx, const_cast<Type *>(cont)->end()};
} else {
*it = iterator{ctx, cont->end()};
}
return true;
case operation::insert:
case operation::erase:
@@ -107,6 +111,7 @@ struct basic_meta_sequence_container_traits {
return true;
}
}
break;
}
@@ -139,16 +144,20 @@ struct basic_meta_associative_container_traits {
break;
}
case operation::begin:
*it = iterator{ctx, std::bool_constant<key_only>{}, const_cast<Type *>(cont)->begin()};
if(value) {
*it = iterator{ctx, std::bool_constant<key_only>{}, const_cast<Type *>(cont)->begin()};
} else {
*it = iterator{ctx, std::bool_constant<key_only>{}, cont->begin()};
}
return true;
case operation::end:
*it = iterator{ctx, std::bool_constant<key_only>{}, const_cast<Type *>(cont)->end()};
return true;
case operation::cbegin:
*it = iterator{ctx, std::bool_constant<key_only>{}, cont->begin()};
return true;
case operation::cend:
*it = iterator{ctx, std::bool_constant<key_only>{}, cont->end()};
if(value) {
*it = iterator{ctx, std::bool_constant<key_only>{}, const_cast<Type *>(cont)->end()};
} else {
*it = iterator{ctx, std::bool_constant<key_only>{}, cont->end()};
}
return true;
case operation::insert:
if(key->allow_cast<const typename Type::key_type &>()) {
@@ -159,19 +168,21 @@ struct basic_meta_associative_container_traits {
return val->allow_cast<const typename Type::mapped_type &>() && const_cast<Type *>(cont)->emplace(key->cast<const typename Type::key_type &>(), val->cast<const typename Type::mapped_type &>()).second;
}
}
break;
case operation::erase:
if(key->allow_cast<const typename Type::key_type &>()) {
return const_cast<Type *>(cont)->erase(key->cast<const typename Type::key_type &>());
}
break;
case operation::find:
if(key->allow_cast<const typename Type::key_type &>()) {
if(value) {
*it = iterator{ctx, std::bool_constant<key_only>{}, const_cast<Type *>(cont)->find(key->cast<const typename Type::key_type &>())};
*it = iterator{ctx, std::bool_constant<key_only>{}, const_cast<Type *>(cont)->find(key->cast<const typename Type::key_type &>())};
} else {
*it = iterator{ctx, std::bool_constant<key_only>{}, cont->find(key->cast<const typename Type::key_type &>())};
}
}
return true;
}

View File

@@ -40,8 +40,6 @@ enum class meta_sequence_container_operation {
resize,
begin,
end,
cbegin,
cend,
insert,
erase
};
@@ -52,8 +50,6 @@ enum class meta_associative_container_operation {
reserve,
begin,
end,
cbegin,
cend,
insert,
erase,
find
@@ -1905,7 +1901,7 @@ inline bool meta_sequence_container::reserve(const size_type sz) {
*/
[[nodiscard]] inline meta_sequence_container::iterator meta_sequence_container::begin() {
iterator it{};
vtable(storage.policy() == any_policy::cref ? operation::cbegin : operation::begin, *ctx, std::as_const(storage).data(), nullptr, &it);
vtable(operation::begin, *ctx, std::as_const(storage).data(), storage.policy() == any_policy::cref ? nullptr : this, &it);
return it;
}
@@ -1915,7 +1911,7 @@ inline bool meta_sequence_container::reserve(const size_type sz) {
*/
[[nodiscard]] inline meta_sequence_container::iterator meta_sequence_container::end() {
iterator it{};
vtable(storage.policy() == any_policy::cref ? operation::cend : operation::end, *ctx, std::as_const(storage).data(), nullptr, &it);
vtable(operation::end, *ctx, std::as_const(storage).data(), storage.policy() == any_policy::cref ? nullptr : this, &it);
return it;
}
@@ -2005,14 +2001,14 @@ inline bool meta_associative_container::reserve(const size_type sz) {
/*! @copydoc meta_sequence_container::begin */
[[nodiscard]] inline meta_associative_container::iterator meta_associative_container::begin() {
iterator it{};
vtable(storage.policy() == any_policy::cref ? operation::cbegin : operation::begin, *ctx, std::as_const(storage).data(), nullptr, nullptr, &it);
vtable(operation::begin, *ctx, std::as_const(storage).data(), nullptr, storage.policy() == any_policy::cref ? nullptr : this, &it);
return it;
}
/*! @copydoc meta_sequence_container::end */
[[nodiscard]] inline meta_associative_container::iterator meta_associative_container::end() {
iterator it{};
vtable(storage.policy() == any_policy::cref ? operation::cend : operation::end, *ctx, std::as_const(storage).data(), nullptr, nullptr, &it);
vtable(operation::end, *ctx, std::as_const(storage).data(), nullptr, storage.policy() == any_policy::cref ? nullptr : this, &it);
return it;
}