11. (STL Compatibility and Emulation, Project) Using the design philosophy underlying the STL algorithms will improve the...
Question:
11. (STL Compatibility and Emulation, Project)
Using the design philosophy underlying the STL algorithms will improve the quality of the code for lattice ADTs and make the code less redundant.
Answer the following questions:
a) Modify the lattice ADTs to make them STL compatible.
b) Test the new functionality by writing a function (similar to std::transform()) that applies a real-valued function of one variable to each node of a source lattice to either modify that lattice or initialise a destination lattice.We use iterators in the style of STL by modifying the following code:
template
void transform(Lattice
{ // Apply a function to each node of lattice, modifying it for (std::size_t n = lattice.MinIndex(); n <= lattice.
MaxIndex(); ++n)
{
for (std::size_t i = 0; i < lattice[n].size(); ++i)
{
lattice[n][i] = f(lattice[n][i]);
}
}
}
c) What are the advantages of having STL-compatible containers?
Step by Step Answer: