if constexpr (ranges::forward_range<_Rg>)
{
+ const auto __ins_idx = __pos - cbegin();
+ // Number of new elements to insert:
+ const auto __n = size_type(ranges::distance(__rg));
+ if (__n == 0)
+ return begin() + __ins_idx;
+
// Start of existing elements:
pointer __old_start = this->_M_impl._M_start;
// End of existing elements:
pointer __old_finish = this->_M_impl._M_finish;
// Insertion point:
- const auto __ins_idx = __pos - cbegin();
pointer __ins = __old_start + __ins_idx;
- // Number of new elements to insert:
- const auto __n = size_type(ranges::distance(__rg));
// Number of elements that can fit in unused capacity:
const auto __cap = this->_M_impl._M_end_of_storage - __old_finish;
if (__cap >= __n)
return true;
}
+struct SelfAssignChecker {
+ static int moveCounter;
+ static int copyCounter;
+
+ SelfAssignChecker() = default;
+ constexpr SelfAssignChecker(int v) : val(v) { }
+ SelfAssignChecker(const SelfAssignChecker&) = default;
+ SelfAssignChecker(SelfAssignChecker&&) = default;
+
+ SelfAssignChecker operator=(const SelfAssignChecker& rhs)
+ {
+ if (this == &rhs)
+ ++copyCounter;
+ this->val = rhs.val;
+ return *this;
+ }
+
+ SelfAssignChecker operator=(SelfAssignChecker&& rhs)
+ {
+ if (this == &rhs)
+ ++moveCounter;
+ this->val = rhs.val;
+ return *this;
+ }
+
+ int val;
+
+ friend bool operator==(SelfAssignChecker, SelfAssignChecker) = default;
+};
+
+int SelfAssignChecker::moveCounter = 0;
+int SelfAssignChecker::copyCounter = 0;
+
+void
+test_pr121313()
+{
+ using namespace __gnu_test;
+
+ SelfAssignChecker::copyCounter = SelfAssignChecker::moveCounter = 0;
+ do_test<test_forward_range<int>, std::allocator<SelfAssignChecker>>();
+ VERIFY( SelfAssignChecker::moveCounter == 0 );
+ VERIFY( SelfAssignChecker::copyCounter == 0 );
+
+ SelfAssignChecker::copyCounter = SelfAssignChecker::moveCounter = 0;
+ do_test<test_input_range<int>, std::allocator<SelfAssignChecker>>();
+ VERIFY( SelfAssignChecker::moveCounter == 0 );
+ VERIFY( SelfAssignChecker::copyCounter == 0 );
+}
+
constexpr bool
test_constexpr()
{
// XXX: this doesn't test the non-forward_range code paths are constexpr.
do_test<std::span<short>, std::allocator<int>>();
return true;
+
}
int main()
{
test_ranges();
+ test_pr121313();
static_assert( test_constexpr() );
}