From 2ef2054358a0a48aae17a8bb2cfe4278d81154af Mon Sep 17 00:00:00 2001 From: "FUJI Goro (gfx)" Date: Sun, 18 Oct 2015 13:39:37 +0900 Subject: [PATCH 1/6] use std::move by default --- Makefile | 18 +++++++++++++----- README.md | 6 ++++-- test/test.cpp | 6 ++++++ timsort.hpp | 6 +++++- 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 96d44d7..867ccaf 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ 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-with-cpp14 test-without-optimization: test/test.cpp timsort.hpp .bin $(COMPILE) $(LIB_BOOST_TEST) $< -o .bin/$@ @@ -20,17 +20,25 @@ test-with-optimization: test/test.cpp timsort.hpp .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) $(LIB_BOOST_TEST) -std=c++98 $< -o .bin/$@ + time ./.bin/$@ + +test-with-cpp11: test/test.cpp timsort.hpp .bin + $(COMPILE) $(LIB_BOOST_TEST) -std=c++11 $< -o .bin/$@ + time ./.bin/$@ + +test-with-cpp14: test/test.cpp timsort.hpp .bin + $(COMPILE) $(LIB_BOOST_TEST) -std=c++14 $< -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)) From 8b8f1df928dfe3161d4c5623244cba0c44f6d134 Mon Sep 17 00:00:00 2001 From: "FUJI Goro (gfx)" Date: Sun, 18 Oct 2015 13:43:54 +0900 Subject: [PATCH 2/6] travis clang (v3.4) does not support -std=c++14 --- Makefile | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 867ccaf..7f89cc0 100644 --- a/Makefile +++ b/Makefile @@ -10,7 +10,7 @@ all: .bin: mkdir -p .bin -test: test-without-optimization test-with-optimization test-with-cpp98 test-with-cpp11 test-with-cpp14 +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/$@ @@ -28,10 +28,6 @@ test-with-cpp11: test/test.cpp timsort.hpp .bin $(COMPILE) $(LIB_BOOST_TEST) -std=c++11 $< -o .bin/$@ time ./.bin/$@ -test-with-cpp14: test/test.cpp timsort.hpp .bin - $(COMPILE) $(LIB_BOOST_TEST) -std=c++14 $< -o .bin/$@ - time ./.bin/$@ - bench: example/bench.cpp timsort.hpp .bin $(CXX) -v $(COMPILE) $(OPTIMIZE) -std=c++11 $< -o .bin/$@ From 4a325da19a35550a0a3eacf7291c3005b300964b Mon Sep 17 00:00:00 2001 From: "FUJI Goro (gfx)" Date: Sun, 18 Oct 2015 13:44:21 +0900 Subject: [PATCH 3/6] test with gcc on travis --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 0bc83fc..a60c79b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: cpp compiler: - clang + - gcc install: - sudo apt-get -qq update - sudo apt-get -qq install time libboost-all-dev From 6a6087b9e224ba5d21e581b537f01fa69642ce60 Mon Sep 17 00:00:00 2001 From: "FUJI Goro (gfx)" Date: Sun, 18 Oct 2015 13:45:22 +0900 Subject: [PATCH 4/6] use container-based CI http://docs.travis-ci.com/user/migrating-from-legacy/ --- .travis.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index a60c79b..3acaa9d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,12 @@ -# https://github.com/embarkmobile/android-maven-example +sudo: false language: cpp compiler: - clang - gcc -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 From 5c6c748d512b19e3446ce494820a9fb1e00cc43d Mon Sep 17 00:00:00 2001 From: "FUJI Goro (gfx)" Date: Sun, 18 Oct 2015 14:00:21 +0900 Subject: [PATCH 5/6] fix gcc link errors --- Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 7f89cc0..657bdc6 100644 --- a/Makefile +++ b/Makefile @@ -13,19 +13,19 @@ all: 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-cpp98: test/test.cpp timsort.hpp .bin - $(COMPILE) $(LIB_BOOST_TEST) -std=c++98 $< -o .bin/$@ + $(COMPILE) -std=c++98 $< $(LIB_BOOST_TEST) -o .bin/$@ time ./.bin/$@ test-with-cpp11: test/test.cpp timsort.hpp .bin - $(COMPILE) $(LIB_BOOST_TEST) -std=c++11 $< -o .bin/$@ + $(COMPILE) -std=c++11 $< $(LIB_BOOST_TEST) -o .bin/$@ time ./.bin/$@ bench: example/bench.cpp timsort.hpp .bin From 3af4b0fcef3d74d0c5e75c41e6ef94efceade198 Mon Sep 17 00:00:00 2001 From: "FUJI Goro (gfx)" Date: Sun, 18 Oct 2015 14:02:21 +0900 Subject: [PATCH 6/6] travis gcc (4.6) does not support -std=c++11 https://travis-ci.org/gfx/cpp-TimSort/jobs/85993141 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 3acaa9d..ee4b005 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,7 +2,6 @@ sudo: false language: cpp compiler: - clang - - gcc addons: apt: packages: