go to start Ex W11
|home |print view |recent changes |changed November 3, 2017 |
exact
|You are 54.81.139.56 <- set your identity!

Sections: Function Templates | Filling a vector with squares with standard functors | Function template median() | function template rotate3arguments() | Function readln(std::istream&,...) |

Function Templates ^

Filling a vector with squares with standard functors ^

Use standard functors and the transform algorithm to fill a vector consisting of 10 ones with the 10 squares 1..100. Do not use a loop. Do not use iota(). Do not use a lambda. Start with the following vector:

    std::vector<unsigned> v(10,1);

Function template median() ^

Write a template function median(a,b,c) taking three arguments of the same type and returning the one in the middle, i.e., neither min/max.

Provide useful unit tests for your function.

You can implement the function in a header file within your CUTE test project.

function template rotate3arguments() ^

Write a template function rotate3arguments taking three variables of the same type as arguments and exchanging the values, so that a obtains the value of b, b of c, and c of a.

Provide useful unit tests for your function.

You can implement the function in a header file within your CUTE test project.

Function readln(std::istream&,...) ^

Write a variadic function template readln(std::istream&,...) that takes a variable number of reference arguments and uses operator>> to read in successive values from a line read from the std::istream.

Tip: you might need to create a second function that takes an istream and reads all values from it, whereas readln just reads a line and passes that line as an istringstream to the second function.

Create useful unit tests for your function(s).


|home |print view |recent changes |changed November 3, 2017 |
exact
|You are 54.81.139.56 <- set your identity!

Ex W11
go to start