Skip to content

Commit 94c9a7b

Browse files
committed
Simplify move exercise.
For many students, it took too long to read the NVector implementation. In this version, we use a class with one pointer to internal storage to compare copy and move. The solution follows the copy and swap idiom discussed in the lecture. Fix #340.
1 parent 83d5883 commit 94c9a7b

File tree

7 files changed

+174
-351
lines changed

7 files changed

+174
-351
lines changed

code/move/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ include( "${CMAKE_CURRENT_SOURCE_DIR}/../CompilerSettings.cmake" )
88
include( "${CMAKE_CURRENT_SOURCE_DIR}/../SolutionTarget.cmake" )
99

1010
# Create the user's executable.
11-
add_executable( trymove "NVector.hpp" "trymove.cpp" )
11+
add_executable( trymove "trymove.cpp" )
1212

1313
# Create the "solution executable".
14-
add_executable( trymove.sol EXCLUDE_FROM_ALL "solution/NVector.sol.hpp" "solution/trymove.sol.cpp" )
14+
add_executable( trymove.sol EXCLUDE_FROM_ALL "solution/trymove.sol.cpp" )
1515
add_dependencies( solution trymove.sol )

code/move/Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ solution: trymove.sol
44
clean:
55
rm -f *o trymove trymove.sol *~ callgrind.out.*
66

7-
trymove : trymove.cpp NVector.hpp
8-
${CXX} -g -std=c++11 -O0 -Wall -Wextra -L. -o $@ $<
7+
trymove : trymove.cpp
8+
${CXX} -g -std=c++17 -O2 -Wall -Wextra -L. -o $@ $<
99

10-
trymove.sol : solution/trymove.sol.cpp solution/NVector.sol.hpp
11-
${CXX} -g -std=c++11 -O0 -Wall -Wextra -L. -o $@ $<
10+
trymove.sol : solution/trymove.sol.cpp
11+
${CXX} -g -std=c++17 -O2 -Wall -Wextra -L. -o $@ $<

code/move/NVector.hpp

Lines changed: 0 additions & 134 deletions
This file was deleted.

code/move/README.md

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
1-
21
## Prerequisites
3-
4-
* be able to use simple templated code
2+
- Copy and move constructors
3+
- Copy and move assignment operators
54

65
## Instructions
76

8-
* look at the code and run it with callgrind
7+
* look at the code and run it with callgrind or time it e.g. using `/usr/bin/time ./trymove`
98
* understand how inefficient it is
10-
* implement move semantic the easy way in NVector
11-
* run with callgrind and see no improvement
129
* understand why and fix trymove.cpp
1310
* see efficiency improvements

code/move/solution/NVector.sol.hpp

Lines changed: 0 additions & 146 deletions
This file was deleted.

0 commit comments

Comments
 (0)