diff --git a/.travis.yml b/.travis.yml index 0bc83fc..ee4b005 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,11 @@ -# https://github.com/embarkmobile/android-maven-example +sudo: false language: cpp compiler: - clang -install: - - sudo apt-get -qq update - - sudo apt-get -qq install time libboost-all-dev +addons: + apt: + packages: + - time + - libboost-all-dev script: - make test diff --git a/Makefile b/Makefile index 96d44d7..657bdc6 100644 --- a/Makefile +++ b/Makefile @@ -10,27 +10,31 @@ all: .bin: mkdir -p .bin -test: test-without-optimization test-with-optimization test-with-std-move +test: test-without-optimization test-with-optimization test-with-cpp98 test-with-cpp11 test-without-optimization: test/test.cpp timsort.hpp .bin - $(COMPILE) $(LIB_BOOST_TEST) $< -o .bin/$@ + $(COMPILE) $< $(LIB_BOOST_TEST) -o .bin/$@ time ./.bin/$@ test-with-optimization: test/test.cpp timsort.hpp .bin - $(COMPILE) $(OPTIMIZE) $(LIB_BOOST_TEST) $< -o .bin/$@ + $(COMPILE) $(OPTIMIZE) $< $(LIB_BOOST_TEST) -o .bin/$@ time ./.bin/$@ -test-with-std-move: test/test.cpp timsort.hpp .bin - $(COMPILE) $(OPTIMIZE) $(LIB_BOOST_TEST) -std=c++11 -DENABLE_STD_MOVE $< -o .bin/$@ +test-with-cpp98: test/test.cpp timsort.hpp .bin + $(COMPILE) -std=c++98 $< $(LIB_BOOST_TEST) -o .bin/$@ + time ./.bin/$@ + +test-with-cpp11: test/test.cpp timsort.hpp .bin + $(COMPILE) -std=c++11 $< $(LIB_BOOST_TEST) -o .bin/$@ time ./.bin/$@ bench: example/bench.cpp timsort.hpp .bin $(CXX) -v - $(COMPILE) $(OPTIMIZE) -std=c++11 -DENABLE_STD_MOVE $< -o .bin/$@ + $(COMPILE) $(OPTIMIZE) -std=c++11 $< -o .bin/$@ ./.bin/$@ coverage: - make test CXXFLAGS="-coverage -O0" + make test-with-cpp11 CXXFLAGS="-coverage -O0" gcov test.gcda | grep -A 1 "File './timsort.hpp'" mv timsort.hpp.gcov coverage.txt rm -rf *.gc* diff --git a/README.md b/README.md index 748e425..6af46f4 100644 --- a/README.md +++ b/README.md @@ -24,7 +24,9 @@ Run `make test` for testing and `make coverage` for test coverage. COMPATIBILITY ================== -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). +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). + +You can disable use of `std::move()` by passing the macro '-DDISABLE_STD_MOVE'. SEE ALSO ================== @@ -42,7 +44,7 @@ An example output is as follows (timing scale: sec.): Apple LLVM version 7.0.0 (clang-700.0.72) Target: x86_64-apple-darwin14.5.0 Thread model: posix - c++ -I. -Wall -Wextra -g -DNDEBUG -O2 -std=c++11 -DENABLE_STD_MOVE example/bench.cpp -o .bin/bench + c++ -I. -Wall -Wextra -g -DNDEBUG -O2 -std=c++11 example/bench.cpp -o .bin/bench ./.bin/bench RANDOMIZED SEQUENCE [int] diff --git a/test/test.cpp b/test/test.cpp index 7019422..eab1783 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -9,6 +9,12 @@ #include "timsort.hpp" +#if ENABLE_STD_MOVE +#warning std::move() enabled +#else +#warning std::move() disabled +#endif + using namespace gfx; BOOST_AUTO_TEST_CASE(simple0) { diff --git a/timsort.hpp b/timsort.hpp index 6005a5b..67c55ba 100644 --- a/timsort.hpp +++ b/timsort.hpp @@ -42,7 +42,11 @@ #define GFX_TIMSORT_LOG(expr) ((void)0) #endif -#if ENABLE_STD_MOVE && __cplusplus >= 201103L +#if __cplusplus >= 201103L && !DISABLE_STD_MOVE +#define ENABLE_STD_MOVE 1 +#endif + +#if ENABLE_STD_MOVE #define GFX_TIMSORT_MOVE(x) std::move(x) #define GFX_TIMSORT_MOVE_RANGE(in1, in2, out) std::move((in1), (in2), (out)) #define GFX_TIMSORT_MOVE_BACKWARD(in1, in2, out) std::move_backward((in1), (in2), (out))