|
5 | 5 | * - http://svn.python.org/projects/python/trunk/Objects/listobject.c
|
6 | 6 | * - http://cr.openjdk.java.net/~martin/webrevs/openjdk7/timsort/raw_files/new/src/share/classes/java/util/TimSort.java
|
7 | 7 | *
|
8 |
| - * Copyright (c) 2011 Fuji, Goro (gfx) <gfuji@cpan.org>. |
| 8 | + * Copyright (c) 2011 Fuji, Goro (gfx) <gfuji@cpan.org>. C++03/move-compliance modifications by Matt Bentley 2017 (mattreecebentley@gmail.com) |
9 | 9 | *
|
10 | 10 | * Permission is hereby granted, free of charge, to any person obtaining a copy
|
11 | 11 | * of this software and associated documentation files (the "Software"), to
|
|
31 | 31 |
|
32 | 32 | #include <vector>
|
33 | 33 | #include <cassert>
|
34 |
| -#include <iterator> |
35 |
| -#include <algorithm> |
36 |
| -#include <utility> |
| 34 | +#include <algorithm> // std::copy |
| 35 | +#include <functional> // std::less |
37 | 36 |
|
38 | 37 | #ifdef ENABLE_TIMSORT_LOG
|
39 | 38 | #include <iostream>
|
|
42 | 41 | #define GFX_TIMSORT_LOG(expr) ((void)0)
|
43 | 42 | #endif
|
44 | 43 |
|
45 |
| -#if __cplusplus >= 201103L && !DISABLE_STD_MOVE |
46 |
| -#define ENABLE_STD_MOVE 1 |
47 |
| -#endif |
48 |
| - |
49 |
| -#if ENABLE_STD_MOVE |
50 |
| -#define GFX_TIMSORT_MOVE(x) std::move(x) |
51 |
| -#define GFX_TIMSORT_MOVE_RANGE(in1, in2, out) std::move((in1), (in2), (out)) |
52 |
| -#define GFX_TIMSORT_MOVE_BACKWARD(in1, in2, out) std::move_backward((in1), (in2), (out)) |
| 44 | +// If compiler supports both type traits and move semantics - will cover most but not all compilers/std libraries: |
| 45 | +#if (defined(_MSC_VER) && _MSC_VER >= 1700) || ((defined(__cplusplus) && __cplusplus >= 201103L && !defined(_LIBCPP_VERSION)) && ((!defined(__GNUC__) || __GNUC__ >= 5)) && (!defined(__GLIBCXX__) || __GLIBCXX__ >= 20150422)) |
| 46 | + #include <iterator> // iterator_traits |
| 47 | + #include <utility> // std::move |
| 48 | + |
| 49 | + #define GFX_TIMSORT_MOVE(x) (std::is_move_constructible<value_t>::value && std::is_move_assignable<value_t>::value) ? std::move(x) : (x) |
| 50 | + #define GFX_TIMSORT_MOVE_RANGE(in1, in2, out) \ |
| 51 | + if (std::is_move_constructible<value_t>::value && std::is_move_assignable<value_t>::value) \ |
| 52 | + { \ |
| 53 | + std::move((in1), (in2), (out)); \ |
| 54 | + } \ |
| 55 | + else \ |
| 56 | + { \ |
| 57 | + std::copy((in1), (in2), (out)); \ |
| 58 | + } |
| 59 | + #define GFX_TIMSORT_MOVE_BACKWARD(in1, in2, out) \ |
| 60 | + if (std::is_move_constructible<value_t>::value && std::is_move_assignable<value_t>::value) \ |
| 61 | + { \ |
| 62 | + std::move_backward((in1), (in2), (out)); \ |
| 63 | + } \ |
| 64 | + else \ |
| 65 | + { \ |
| 66 | + std::copy_backward((in1), (in2), (out)); \ |
| 67 | + } |
53 | 68 | #else
|
54 |
| -#define GFX_TIMSORT_MOVE(x) (x) |
55 |
| -#define GFX_TIMSORT_MOVE_RANGE(in1, in2, out) std::copy((in1), (in2), (out)) |
56 |
| -#define GFX_TIMSORT_MOVE_BACKWARD(in1, in2, out) std::copy_backward((in1), (in2), (out)) |
| 69 | + #define GFX_TIMSORT_MOVE(x) (x) |
| 70 | + #define GFX_TIMSORT_MOVE_RANGE(in1, in2, out) std::copy((in1), (in2), (out)); |
| 71 | + #define GFX_TIMSORT_MOVE_BACKWARD(in1, in2, out) std::copy_backward((in1), (in2), (out)); |
57 | 72 | #endif
|
58 | 73 |
|
| 74 | + |
| 75 | + |
59 | 76 | namespace gfx {
|
60 | 77 |
|
61 | 78 | // ---------------------------------------
|
|
0 commit comments