From ae0f11125a06d163a21f621e15f12102c544a683 Mon Sep 17 00:00:00 2001 From: Artyom Polkovnikov Date: Tue, 30 Dec 2014 20:27:06 +0300 Subject: [PATCH] [std] Define and use CONSTEXPR_VALUE macro to make code compilable under MSVC 2013. --- .../osrm-backend/Include/osrm/Coordinate.h | 4 +++- .../ThirdParty/variant/variant.hpp | 19 ++++++++++--------- std/constexpr.hpp | 7 +++++++ 3 files changed, 20 insertions(+), 10 deletions(-) create mode 100644 std/constexpr.hpp diff --git a/3party/osrm/osrm-backend/Include/osrm/Coordinate.h b/3party/osrm/osrm-backend/Include/osrm/Coordinate.h index 462ac0b63b..e49663c204 100644 --- a/3party/osrm/osrm-backend/Include/osrm/Coordinate.h +++ b/3party/osrm/osrm-backend/Include/osrm/Coordinate.h @@ -32,7 +32,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include -constexpr float COORDINATE_PRECISION = 1000000.f; +#include "../../../../../std/constexpr.hpp" + +CONSTEXPR_VALUE float COORDINATE_PRECISION = 1000000.f; struct FixedPointCoordinate { diff --git a/3party/osrm/osrm-backend/ThirdParty/variant/variant.hpp b/3party/osrm/osrm-backend/ThirdParty/variant/variant.hpp index 4e3eee6e16..d919ad2c77 100644 --- a/3party/osrm/osrm-backend/ThirdParty/variant/variant.hpp +++ b/3party/osrm/osrm-backend/ThirdParty/variant/variant.hpp @@ -12,6 +12,7 @@ #include "recursive_wrapper.hpp" +#include "../../../../../std/constexpr.hpp" #include "../../../../../std/noexcept.hpp" #ifdef _MSC_VER @@ -38,7 +39,7 @@ namespace mapbox { namespace util { namespace detail { -static constexpr std::size_t invalid_value = std::size_t(-1); +static CONSTEXPR_VALUE std::size_t invalid_value = std::size_t(-1); template struct direct_type; @@ -46,14 +47,14 @@ struct direct_type; template struct direct_type { - static constexpr std::size_t index = std::is_same::value + static CONSTEXPR_VALUE std::size_t index = std::is_same::value ? sizeof...(Types) : direct_type::index; }; template struct direct_type { - static constexpr std::size_t index = invalid_value; + static CONSTEXPR_VALUE std::size_t index = invalid_value; }; template @@ -62,21 +63,21 @@ struct convertible_type; template struct convertible_type { - static constexpr std::size_t index = std::is_convertible::value + static CONSTEXPR_VALUE std::size_t index = std::is_convertible::value ? sizeof...(Types) : convertible_type::index; }; template struct convertible_type { - static constexpr std::size_t index = invalid_value; + static CONSTEXPR_VALUE std::size_t index = invalid_value; }; template struct value_traits { - static constexpr std::size_t direct_index = direct_type::index; - static constexpr std::size_t index = + static CONSTEXPR_VALUE std::size_t direct_index = direct_type::index; + static CONSTEXPR_VALUE std::size_t index = (direct_index == invalid_value) ? convertible_type::index : direct_index; }; @@ -86,7 +87,7 @@ struct is_valid_type; template struct is_valid_type { - static constexpr bool value = std::is_convertible::value + static CONSTEXPR_VALUE bool value = std::is_convertible::value || is_valid_type::value; }; @@ -522,7 +523,7 @@ public: VARIANT_INLINE variant(T && val) NOEXCEPT_MODIFIER : type_index(detail::value_traits::type, Types...>::index) { - constexpr std::size_t index = sizeof...(Types) - detail::value_traits::type, Types...>::index - 1; + CONSTEXPR_VALUE std::size_t index = sizeof...(Types) - detail::value_traits::type, Types...>::index - 1; using target_type = typename detail::select_type::type; new (&data) target_type(std::forward(val)); // nothrow } diff --git a/std/constexpr.hpp b/std/constexpr.hpp new file mode 100644 index 0000000000..716eba0ca0 --- /dev/null +++ b/std/constexpr.hpp @@ -0,0 +1,7 @@ +#pragma once + +#if defined(_MSC_VER) && (_MSC_VER <= 1800) + #define CONSTEXPR_VALUE const +#else + #define CONSTEXPR_VALUE constexpr +#endif