Phase 4
Now that IntList
supports iteration, you get to actually use it in your own implementation code. In this development phase, you will implement the following member function(s) of the IntList
class:
operator==(…)
(the equal-to operator)
and as a result, this operator will also work:
operator!=(…)
(the not equal-to operator, already written)
These operations are described in the
which you should keep open in a window or tab for reference.
Work Through the Steps
As always, don't forget to check out the Helpful Hints!
1. Plan
- Plan how the
==
operator should work. - Add an image
Phase_4.jpg
to theintlist/Planning
folder in your assignment repository. - Make sure the file was added successfully by viewing it on the GitHub website.
2. Write Tests
- Write tests for
==
and!=
onIntList
s and add them tointlist-test.cpp
.
3. Implement
- Use your plan to write your implementation of
operator==
inintlist.cpp
.
4. Test & Fix
- See if you can find any bugs in your implementation, and if you do, sort them out.
- Think about how someone else might have accidentally fundamentally misunderstood what equality on lists means and make sure your test would catch those kinds of mistakes.
Helpful Hints
Use Your Iter
You should use your iterator to implement ==
. Specificially, since both lists are const
, when you call begin()
on them, it'll return a const_iterator
.
Note that you'll need to use two iterators, one for each list.
I know how to call
begin
on the RHS list, that'srhs.begin()
, but how do I call it on the LHS list. I know that it's basicallylhs.operator==(rhs)
, so is itthis.begin()
orthis->begin()
?You should just say
begin()
rather thanthis->begin()
. (Andthis.begin()
wouldn't compile, becausethis
is a pointer.)
Obey the Complexity Guarantees
The specification lists specific complexity guarantees about the performance of ==
that limits your options on how you can implement this operation.
Yes, without those constraints, you'd have just been able to call
std::equal
passing in thebegin()
andend()
iterators for both lists.We'll let you code
==
usingstd::equal
in future assignments. But more practice is good right now.
(When logged in, completion status appears here.)