Skip to content

Commit e1a3dd1

Browse files
committed
Merge pull request #13 from gfx/default_move
use std::move by default
2 parents 1d88817 + 3af4b0f commit e1a3dd1

File tree

5 files changed

+32
-14
lines changed

5 files changed

+32
-14
lines changed

.travis.yml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
# https://github.com/embarkmobile/android-maven-example
1+
sudo: false
22
language: cpp
33
compiler:
44
- clang
5-
install:
6-
- sudo apt-get -qq update
7-
- sudo apt-get -qq install time libboost-all-dev
5+
addons:
6+
apt:
7+
packages:
8+
- time
9+
- libboost-all-dev
810
script:
911
- make test

Makefile

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,31 @@ all:
1010
.bin:
1111
mkdir -p .bin
1212

13-
test: test-without-optimization test-with-optimization test-with-std-move
13+
test: test-without-optimization test-with-optimization test-with-cpp98 test-with-cpp11
1414

1515
test-without-optimization: test/test.cpp timsort.hpp .bin
16-
$(COMPILE) $(LIB_BOOST_TEST) $< -o .bin/$@
16+
$(COMPILE) $< $(LIB_BOOST_TEST) -o .bin/$@
1717
time ./.bin/$@
1818

1919
test-with-optimization: test/test.cpp timsort.hpp .bin
20-
$(COMPILE) $(OPTIMIZE) $(LIB_BOOST_TEST) $< -o .bin/$@
20+
$(COMPILE) $(OPTIMIZE) $< $(LIB_BOOST_TEST) -o .bin/$@
2121
time ./.bin/$@
2222

23-
test-with-std-move: test/test.cpp timsort.hpp .bin
24-
$(COMPILE) $(OPTIMIZE) $(LIB_BOOST_TEST) -std=c++11 -DENABLE_STD_MOVE $< -o .bin/$@
23+
test-with-cpp98: test/test.cpp timsort.hpp .bin
24+
$(COMPILE) -std=c++98 $< $(LIB_BOOST_TEST) -o .bin/$@
25+
time ./.bin/$@
26+
27+
test-with-cpp11: test/test.cpp timsort.hpp .bin
28+
$(COMPILE) -std=c++11 $< $(LIB_BOOST_TEST) -o .bin/$@
2529
time ./.bin/$@
2630

2731
bench: example/bench.cpp timsort.hpp .bin
2832
$(CXX) -v
29-
$(COMPILE) $(OPTIMIZE) -std=c++11 -DENABLE_STD_MOVE $< -o .bin/$@
33+
$(COMPILE) $(OPTIMIZE) -std=c++11 $< -o .bin/$@
3034
./.bin/$@
3135

3236
coverage:
33-
make test CXXFLAGS="-coverage -O0"
37+
make test-with-cpp11 CXXFLAGS="-coverage -O0"
3438
gcov test.gcda | grep -A 1 "File './timsort.hpp'"
3539
mv timsort.hpp.gcov coverage.txt
3640
rm -rf *.gc*

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ Run `make test` for testing and `make coverage` for test coverage.
2424
COMPATIBILITY
2525
==================
2626

27-
This library is compatible with C++03, but if you give the `-DENABLE_STD_MOVE` flag to the compiler, you can sort move-only types (see [#9](https://github.com/gfx/cpp-TimSort/pull/9) for details).
27+
This library is compatible with C++98, but if you give compile it with C++11 or later, this library uses `std::move()` instead of value copy and thus you can sort move-only types (see [#9](https://github.com/gfx/cpp-TimSort/pull/9) for details).
28+
29+
You can disable use of `std::move()` by passing the macro '-DDISABLE_STD_MOVE'.
2830

2931
SEE ALSO
3032
==================
@@ -42,7 +44,7 @@ An example output is as follows (timing scale: sec.):
4244
Apple LLVM version 7.0.0 (clang-700.0.72)
4345
Target: x86_64-apple-darwin14.5.0
4446
Thread model: posix
45-
c++ -I. -Wall -Wextra -g -DNDEBUG -O2 -std=c++11 -DENABLE_STD_MOVE example/bench.cpp -o .bin/bench
47+
c++ -I. -Wall -Wextra -g -DNDEBUG -O2 -std=c++11 example/bench.cpp -o .bin/bench
4648
./.bin/bench
4749
RANDOMIZED SEQUENCE
4850
[int]

test/test.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99

1010
#include "timsort.hpp"
1111

12+
#if ENABLE_STD_MOVE
13+
#warning std::move() enabled
14+
#else
15+
#warning std::move() disabled
16+
#endif
17+
1218
using namespace gfx;
1319

1420
BOOST_AUTO_TEST_CASE(simple0) {

timsort.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@
4242
#define GFX_TIMSORT_LOG(expr) ((void)0)
4343
#endif
4444

45-
#if ENABLE_STD_MOVE && __cplusplus >= 201103L
45+
#if __cplusplus >= 201103L && !DISABLE_STD_MOVE
46+
#define ENABLE_STD_MOVE 1
47+
#endif
48+
49+
#if ENABLE_STD_MOVE
4650
#define GFX_TIMSORT_MOVE(x) std::move(x)
4751
#define GFX_TIMSORT_MOVE_RANGE(in1, in2, out) std::move((in1), (in2), (out))
4852
#define GFX_TIMSORT_MOVE_BACKWARD(in1, in2, out) std::move_backward((in1), (in2), (out))

0 commit comments

Comments
 (0)