From 27b4fd30ef673b28b3c6014cd56888abfa0e7797 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Mon, 2 Apr 2012 00:40:41 +0000 Subject: [PATCH] This is an initial commit of constexpr support as proposed by Richard Smith. This by no means completes constexpr support. Indeed, it hardly scratches the surface. All it does is lay the foundation in <__config> and changes those few places in the library that are already using that foundation. git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@153856 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/__config | 4 +++- include/algorithm | 4 ++-- include/random | 4 ++-- include/type_traits | 13 +++---------- 4 files changed, 10 insertions(+), 15 deletions(-) diff --git a/include/__config b/include/__config index 6b290145..7cd01dc1 100644 --- a/include/__config +++ b/include/__config @@ -384,7 +384,9 @@ template struct __static_assert_check {}; #endif #ifdef _LIBCPP_HAS_NO_CONSTEXPR -#define constexpr const +#define _LIBCPP_CONSTEXPR +#else +#define _LIBCPP_CONSTEXPR constexpr #endif #ifndef __has_feature diff --git a/include/algorithm b/include/algorithm index f9c6843a..68e989a0 100644 --- a/include/algorithm +++ b/include/algorithm @@ -2712,8 +2712,8 @@ public: result_type operator()(); - static constexpr result_type min() {return _Min;} - static constexpr result_type max() {return _Max;} + static _LIBCPP_CONSTEXPR result_type min() {return _Min;} + static _LIBCPP_CONSTEXPR result_type max() {return _Max;} friend __rs_default __rs_get(); }; diff --git a/include/random b/include/random index 02ea9b63..7099af5e 100644 --- a/include/random +++ b/include/random @@ -3374,9 +3374,9 @@ public: static const result_type _Max = 0xFFFFFFFFu; _LIBCPP_INLINE_VISIBILITY - static constexpr result_type min() { return _Min;} + static _LIBCPP_CONSTEXPR result_type min() { return _Min;} _LIBCPP_INLINE_VISIBILITY - static constexpr result_type max() { return _Max;} + static _LIBCPP_CONSTEXPR result_type max() { return _Max;} // constructors explicit random_device(const string& __token = "/dev/urandom"); diff --git a/include/type_traits b/include/type_traits index 13129f31..f68ed6dd 100644 --- a/include/type_traits +++ b/include/type_traits @@ -163,22 +163,15 @@ struct __two {char _[2];}; template struct _LIBCPP_VISIBLE integral_constant { - static constexpr _Tp value = __v; + static _LIBCPP_CONSTEXPR const _Tp value = __v; typedef _Tp value_type; typedef integral_constant type; _LIBCPP_INLINE_VISIBILITY -#ifndef _LIBCPP_HAS_NO_CONSTEXPR - constexpr -#endif - operator value_type() -#ifdef _LIBCPP_HAS_NO_CONSTEXPR - const -#endif - {return value;} + _LIBCPP_CONSTEXPR operator value_type() const {return value;} }; template -constexpr _Tp integral_constant<_Tp, __v>::value; +_LIBCPP_CONSTEXPR const _Tp integral_constant<_Tp, __v>::value; typedef integral_constant true_type; typedef integral_constant false_type;