Skip to content

Commit

Permalink
C++03/move compliance, better support for compiler/library feature de…
Browse files Browse the repository at this point in the history
…tection (#22)

C++03/move compliance, better support for compiler/library feature detection
  • Loading branch information
mattreecebentley authored and gfx committed May 22, 2017
1 parent 2c1a5da commit e39ca95
Showing 1 changed file with 32 additions and 15 deletions.
47 changes: 32 additions & 15 deletions timsort.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* - http://svn.python.org/projects/python/trunk/Objects/listobject.c
* - http://cr.openjdk.java.net/~martin/webrevs/openjdk7/timsort/raw_files/new/src/share/classes/java/util/TimSort.java
*
* Copyright (c) 2011 Fuji, Goro (gfx) <gfuji@cpan.org>.
* Copyright (c) 2011 Fuji, Goro (gfx) <gfuji@cpan.org>. C++03/move-compliance modifications by Matt Bentley 2017 (mattreecebentley@gmail.com)
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
Expand All @@ -31,9 +31,8 @@

#include <vector>
#include <cassert>
#include <iterator>
#include <algorithm>
#include <utility>
#include <algorithm> // std::copy
#include <functional> // std::less

#ifdef ENABLE_TIMSORT_LOG
#include <iostream>
Expand All @@ -42,20 +41,38 @@
#define GFX_TIMSORT_LOG(expr) ((void)0)
#endif

#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))
// If compiler supports both type traits and move semantics - will cover most but not all compilers/std libraries:
#if (defined(_MSC_VER) && _MSC_VER >= 1700) || ((defined(__cplusplus) && __cplusplus >= 201103L && !defined(_LIBCPP_VERSION)) && ((!defined(__GNUC__) || __GNUC__ >= 5)) && (!defined(__GLIBCXX__) || __GLIBCXX__ >= 20150422))
#include <iterator> // iterator_traits
#include <utility> // std::move

#define GFX_TIMSORT_MOVE(x) (std::is_move_constructible<value_t>::value && std::is_move_assignable<value_t>::value) ? std::move(x) : (x)
#define GFX_TIMSORT_MOVE_RANGE(in1, in2, out) \
if (std::is_move_constructible<value_t>::value && std::is_move_assignable<value_t>::value) \
{ \
std::move((in1), (in2), (out)); \
} \
else \
{ \
std::copy((in1), (in2), (out)); \
}
#define GFX_TIMSORT_MOVE_BACKWARD(in1, in2, out) \
if (std::is_move_constructible<value_t>::value && std::is_move_assignable<value_t>::value) \
{ \
std::move_backward((in1), (in2), (out)); \
} \
else \
{ \
std::copy_backward((in1), (in2), (out)); \
}
#else
#define GFX_TIMSORT_MOVE(x) (x)
#define GFX_TIMSORT_MOVE_RANGE(in1, in2, out) std::copy((in1), (in2), (out))
#define GFX_TIMSORT_MOVE_BACKWARD(in1, in2, out) std::copy_backward((in1), (in2), (out))
#define GFX_TIMSORT_MOVE(x) (x)
#define GFX_TIMSORT_MOVE_RANGE(in1, in2, out) std::copy((in1), (in2), (out));
#define GFX_TIMSORT_MOVE_BACKWARD(in1, in2, out) std::copy_backward((in1), (in2), (out));
#endif



namespace gfx {

// ---------------------------------------
Expand Down

0 comments on commit e39ca95

Please sign in to comment.