Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 11 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
==================
Expand All @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions test/test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion timsort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down