From 03d7181b0e6e38e1096bd50c1d5ed83c8f0a1205 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 20 Jul 2012 19:09:12 +0000 Subject: [PATCH] constexpr applied to . git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@160563 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/string | 86 ++++++++++++++++++++++++++------------------------ 1 file changed, 44 insertions(+), 42 deletions(-) diff --git a/include/string b/include/string index 620e6f82..7c022dca 100644 --- a/include/string +++ b/include/string @@ -51,8 +51,8 @@ struct char_traits typedef mbstate_t state_type; static void assign(char_type& c1, const char_type& c2) noexcept; - static bool eq(char_type c1, char_type c2) noexcept; - static bool lt(char_type c1, char_type c2) noexcept; + static constexpr bool eq(char_type c1, char_type c2) noexcept; + static constexpr bool lt(char_type c1, char_type c2) noexcept; static int compare(const char_type* s1, const char_type* s2, size_t n); static size_t length(const char_type* s); @@ -61,11 +61,11 @@ struct char_traits static char_type* copy(char_type* s1, const char_type* s2, size_t n); static char_type* assign(char_type* s, size_t n, char_type a); - static int_type not_eof(int_type c) noexcept; - static char_type to_char_type(int_type c) noexcept; - static int_type to_int_type(char_type c) noexcept; - static bool eq_int_type(int_type c1, int_type c2) noexcept; - static int_type eof() noexcept; + static constexpr int_type not_eof(int_type c) noexcept; + static constexpr char_type to_char_type(int_type c) noexcept; + static constexpr int_type to_int_type(char_type c) noexcept; + static constexpr bool eq_int_type(int_type c1, int_type c2) noexcept; + static constexpr int_type eof() noexcept; }; template <> struct char_traits; @@ -506,10 +506,10 @@ struct _LIBCPP_VISIBLE char_traits static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} _LIBCPP_INLINE_VISIBILITY - static bool eq(char_type __c1, char_type __c2) _NOEXCEPT + static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 == __c2;} _LIBCPP_INLINE_VISIBILITY - static bool lt(char_type __c1, char_type __c2) _NOEXCEPT + static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 < __c2;} static int compare(const char_type* __s1, const char_type* __s2, size_t __n); @@ -519,19 +519,20 @@ struct _LIBCPP_VISIBLE char_traits static char_type* copy(char_type* __s1, const char_type* __s2, size_t __n); static char_type* assign(char_type* __s, size_t __n, char_type __a); - _LIBCPP_INLINE_VISIBILITY static int_type not_eof(int_type __c) _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT {return eq_int_type(__c, eof()) ? ~eof() : __c;} _LIBCPP_INLINE_VISIBILITY - static char_type to_char_type(int_type __c) _NOEXCEPT + static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT {return char_type(__c);} _LIBCPP_INLINE_VISIBILITY - static int_type to_int_type(char_type __c) _NOEXCEPT + static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT {return int_type(__c);} _LIBCPP_INLINE_VISIBILITY - static bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT + static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT {return __c1 == __c2;} _LIBCPP_INLINE_VISIBILITY - static int_type eof() _NOEXCEPT + static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT {return int_type(EOF);} }; @@ -631,10 +632,10 @@ struct _LIBCPP_VISIBLE char_traits static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} _LIBCPP_INLINE_VISIBILITY - static bool eq(char_type __c1, char_type __c2) _NOEXCEPT + static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 == __c2;} _LIBCPP_INLINE_VISIBILITY - static bool lt(char_type __c1, char_type __c2) _NOEXCEPT + static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT {return (unsigned char)__c1 < (unsigned char)__c2;} _LIBCPP_INLINE_VISIBILITY @@ -655,19 +656,20 @@ struct _LIBCPP_VISIBLE char_traits static char_type* assign(char_type* __s, size_t __n, char_type __a) {return (char_type*)memset(__s, to_int_type(__a), __n);} - _LIBCPP_INLINE_VISIBILITY static int_type not_eof(int_type __c) _NOEXCEPT + _LIBCPP_INLINE_VISIBILITY + static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT {return eq_int_type(__c, eof()) ? ~eof() : __c;} _LIBCPP_INLINE_VISIBILITY - static char_type to_char_type(int_type __c) _NOEXCEPT + static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT {return char_type(__c);} _LIBCPP_INLINE_VISIBILITY - static int_type to_int_type(char_type __c) _NOEXCEPT + static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT {return int_type((unsigned char)__c);} _LIBCPP_INLINE_VISIBILITY - static bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT + static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT {return __c1 == __c2;} _LIBCPP_INLINE_VISIBILITY - static int_type eof() _NOEXCEPT + static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT {return int_type(EOF);} }; @@ -686,10 +688,10 @@ struct _LIBCPP_VISIBLE char_traits static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} _LIBCPP_INLINE_VISIBILITY - static bool eq(char_type __c1, char_type __c2) _NOEXCEPT + static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 == __c2;} _LIBCPP_INLINE_VISIBILITY - static bool lt(char_type __c1, char_type __c2) _NOEXCEPT + static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 < __c2;} _LIBCPP_INLINE_VISIBILITY @@ -712,19 +714,19 @@ struct _LIBCPP_VISIBLE char_traits {return (char_type*)wmemset(__s, __a, __n);} _LIBCPP_INLINE_VISIBILITY - static int_type not_eof(int_type __c) _NOEXCEPT + static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT {return eq_int_type(__c, eof()) ? ~eof() : __c;} _LIBCPP_INLINE_VISIBILITY - static char_type to_char_type(int_type __c) _NOEXCEPT + static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT {return char_type(__c);} _LIBCPP_INLINE_VISIBILITY - static int_type to_int_type(char_type __c) _NOEXCEPT + static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT {return int_type(__c);} _LIBCPP_INLINE_VISIBILITY - static bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT + static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT {return __c1 == __c2;} _LIBCPP_INLINE_VISIBILITY - static int_type eof() _NOEXCEPT + static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT {return int_type(WEOF);} }; @@ -743,10 +745,10 @@ struct _LIBCPP_VISIBLE char_traits static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} _LIBCPP_INLINE_VISIBILITY - static bool eq(char_type __c1, char_type __c2) _NOEXCEPT + static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 == __c2;} _LIBCPP_INLINE_VISIBILITY - static bool lt(char_type __c1, char_type __c2) _NOEXCEPT + static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 < __c2;} static int compare(const char_type* __s1, const char_type* __s2, size_t __n); @@ -757,19 +759,19 @@ struct _LIBCPP_VISIBLE char_traits static char_type* assign(char_type* __s, size_t __n, char_type __a); _LIBCPP_INLINE_VISIBILITY - static int_type not_eof(int_type __c) _NOEXCEPT + static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT {return eq_int_type(__c, eof()) ? ~eof() : __c;} _LIBCPP_INLINE_VISIBILITY - static char_type to_char_type(int_type __c) _NOEXCEPT + static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT {return char_type(__c);} _LIBCPP_INLINE_VISIBILITY - static int_type to_int_type(char_type __c) _NOEXCEPT + static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT {return int_type(__c);} _LIBCPP_INLINE_VISIBILITY - static bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT + static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT {return __c1 == __c2;} _LIBCPP_INLINE_VISIBILITY - static int_type eof() _NOEXCEPT + static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT {return int_type(0xDFFF);} }; @@ -863,10 +865,10 @@ struct _LIBCPP_VISIBLE char_traits static void assign(char_type& __c1, const char_type& __c2) _NOEXCEPT {__c1 = __c2;} _LIBCPP_INLINE_VISIBILITY - static bool eq(char_type __c1, char_type __c2) _NOEXCEPT + static _LIBCPP_CONSTEXPR bool eq(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 == __c2;} _LIBCPP_INLINE_VISIBILITY - static bool lt(char_type __c1, char_type __c2) _NOEXCEPT + static _LIBCPP_CONSTEXPR bool lt(char_type __c1, char_type __c2) _NOEXCEPT {return __c1 < __c2;} static int compare(const char_type* __s1, const char_type* __s2, size_t __n); @@ -877,19 +879,19 @@ struct _LIBCPP_VISIBLE char_traits static char_type* assign(char_type* __s, size_t __n, char_type __a); _LIBCPP_INLINE_VISIBILITY - static int_type not_eof(int_type __c) _NOEXCEPT + static _LIBCPP_CONSTEXPR int_type not_eof(int_type __c) _NOEXCEPT {return eq_int_type(__c, eof()) ? ~eof() : __c;} _LIBCPP_INLINE_VISIBILITY - static char_type to_char_type(int_type __c) _NOEXCEPT + static _LIBCPP_CONSTEXPR char_type to_char_type(int_type __c) _NOEXCEPT {return char_type(__c);} _LIBCPP_INLINE_VISIBILITY - static int_type to_int_type(char_type __c) _NOEXCEPT + static _LIBCPP_CONSTEXPR int_type to_int_type(char_type __c) _NOEXCEPT {return int_type(__c);} _LIBCPP_INLINE_VISIBILITY - static bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT + static _LIBCPP_CONSTEXPR bool eq_int_type(int_type __c1, int_type __c2) _NOEXCEPT {return __c1 == __c2;} _LIBCPP_INLINE_VISIBILITY - static int_type eof() _NOEXCEPT + static _LIBCPP_CONSTEXPR int_type eof() _NOEXCEPT {return int_type(0xFFFFFFFF);} };