From 08bce1754d62bdee550b71aa0e9073f506676a6f Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 20 Jul 2012 19:20:49 +0000 Subject: [PATCH] constexpr applied to . git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@160564 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/array | 8 ++++---- .../sequences/array/array.size/size.pass.cpp | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/include/array b/include/array index c11f4bd7..029bfd00 100644 --- a/include/array +++ b/include/array @@ -55,7 +55,7 @@ struct array // capacity: constexpr size_type size() const noexcept; constexpr size_type max_size() const noexcept; - bool empty() const noexcept; + constexpr bool empty() const noexcept; // element access: reference operator[](size_type n); @@ -173,11 +173,11 @@ struct _LIBCPP_VISIBLE array // capacity: _LIBCPP_INLINE_VISIBILITY - /*constexpr*/ size_type size() const _NOEXCEPT {return _Size;} + _LIBCPP_CONSTEXPR size_type size() const _NOEXCEPT {return _Size;} _LIBCPP_INLINE_VISIBILITY - /*constexpr*/ size_type max_size() const _NOEXCEPT {return _Size;} + _LIBCPP_CONSTEXPR size_type max_size() const _NOEXCEPT {return _Size;} _LIBCPP_INLINE_VISIBILITY - bool empty() const _NOEXCEPT {return _Size == 0;} + _LIBCPP_CONSTEXPR bool empty() const _NOEXCEPT {return _Size == 0;} // element access: _LIBCPP_INLINE_VISIBILITY reference operator[](size_type __n) {return __elems_[__n];} diff --git a/test/containers/sequences/array/array.size/size.pass.cpp b/test/containers/sequences/array/array.size/size.pass.cpp index 87344ae5..4078fd5c 100644 --- a/test/containers/sequences/array/array.size/size.pass.cpp +++ b/test/containers/sequences/array/array.size/size.pass.cpp @@ -28,4 +28,18 @@ int main() C c = {}; assert(c.size() == 0); } +#ifndef _LIBCPP_HAS_NO_CONSTEXPR + { + typedef double T; + typedef std::array C; + constexpr C c = {1, 2, 3.5}; + static_assert(c.size() == 3, ""); + } + { + typedef double T; + typedef std::array C; + constexpr C c = {}; + static_assert(c.size() == 0, ""); + } +#endif }