[libcxx] r189271 - Apply constexpr to initializer_list for c++1y.
Howard Hinnant
hhinnant at apple.com
Mon Aug 26 13:11:32 PDT 2013
Author: hhinnant
Date: Mon Aug 26 15:11:32 2013
New Revision: 189271
URL: http://llvm.org/viewvc/llvm-project?rev=189271&view=rev
Log:
Apply constexpr to initializer_list for c++1y.
Modified:
libcxx/trunk/include/initializer_list
libcxx/trunk/test/language.support/support.initlist/support.initlist.access/access.pass.cpp
libcxx/trunk/test/language.support/support.initlist/support.initlist.cons/default.pass.cpp
libcxx/trunk/test/language.support/support.initlist/support.initlist.range/begin_end.pass.cpp
Modified: libcxx/trunk/include/initializer_list
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/initializer_list?rev=189271&r1=189270&r2=189271&view=diff
==============================================================================
--- libcxx/trunk/include/initializer_list (original)
+++ libcxx/trunk/include/initializer_list Mon Aug 26 15:11:32 2013
@@ -29,15 +29,15 @@ public:
typedef const E* iterator;
typedef const E* const_iterator;
- initializer_list() noexcept;
+ initializer_list() noexcept; // constexpr in C++14
- size_t size() const noexcept;
- const E* begin() const noexcept;
- const E* end() const noexcept;
+ size_t size() const noexcept; // constexpr in C++14
+ const E* begin() const noexcept; // constexpr in C++14
+ const E* end() const noexcept; // constexpr in C++14
};
-template<class E> const E* begin(initializer_list<E> il) noexcept;
-template<class E> const E* end(initializer_list<E> il) noexcept;
+template<class E> const E* begin(initializer_list<E> il) noexcept; // constexpr in C++14
+template<class E> const E* end(initializer_list<E> il) noexcept; // constexpr in C++14
} // std
@@ -62,6 +62,7 @@ class _LIBCPP_TYPE_VIS_ONLY initializer_
size_t __size_;
_LIBCPP_ALWAYS_INLINE
+ _LIBCPP_CONSTEXPR_AFTER_CXX11
initializer_list(const _Ep* __b, size_t __s) _NOEXCEPT
: __begin_(__b),
__size_(__s)
@@ -75,15 +76,26 @@ public:
typedef const _Ep* iterator;
typedef const _Ep* const_iterator;
- _LIBCPP_ALWAYS_INLINE initializer_list() _NOEXCEPT : __begin_(nullptr), __size_(0) {}
+ _LIBCPP_ALWAYS_INLINE
+ _LIBCPP_CONSTEXPR_AFTER_CXX11
+ initializer_list() _NOEXCEPT : __begin_(nullptr), __size_(0) {}
- _LIBCPP_ALWAYS_INLINE size_t size() const _NOEXCEPT {return __size_;}
- _LIBCPP_ALWAYS_INLINE const _Ep* begin() const _NOEXCEPT {return __begin_;}
- _LIBCPP_ALWAYS_INLINE const _Ep* end() const _NOEXCEPT {return __begin_ + __size_;}
+ _LIBCPP_ALWAYS_INLINE
+ _LIBCPP_CONSTEXPR_AFTER_CXX11
+ size_t size() const _NOEXCEPT {return __size_;}
+
+ _LIBCPP_ALWAYS_INLINE
+ _LIBCPP_CONSTEXPR_AFTER_CXX11
+ const _Ep* begin() const _NOEXCEPT {return __begin_;}
+
+ _LIBCPP_ALWAYS_INLINE
+ _LIBCPP_CONSTEXPR_AFTER_CXX11
+ const _Ep* end() const _NOEXCEPT {return __begin_ + __size_;}
};
template<class _Ep>
inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_AFTER_CXX11
const _Ep*
begin(initializer_list<_Ep> __il) _NOEXCEPT
{
@@ -92,6 +104,7 @@ begin(initializer_list<_Ep> __il) _NOEXC
template<class _Ep>
inline _LIBCPP_INLINE_VISIBILITY
+_LIBCPP_CONSTEXPR_AFTER_CXX11
const _Ep*
end(initializer_list<_Ep> __il) _NOEXCEPT
{
Modified: libcxx/trunk/test/language.support/support.initlist/support.initlist.access/access.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/language.support/support.initlist/support.initlist.access/access.pass.cpp?rev=189271&r1=189270&r2=189271&view=diff
==============================================================================
--- libcxx/trunk/test/language.support/support.initlist/support.initlist.access/access.pass.cpp (original)
+++ libcxx/trunk/test/language.support/support.initlist/support.initlist.access/access.pass.cpp Mon Aug 26 15:11:32 2013
@@ -32,6 +32,23 @@ struct A
}
};
+#if _LIBCPP_STD_VER > 11
+struct B
+{
+ constexpr B(std::initializer_list<int> il)
+ {
+ const int* b = il.begin();
+ const int* e = il.end();
+ assert(il.size() == 3);
+ assert(e - b == il.size());
+ assert(*b++ == 3);
+ assert(*b++ == 2);
+ assert(*b++ == 1);
+ }
+};
+
+#endif // _LIBCPP_STD_VER > 11
+
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
int main()
@@ -39,4 +56,7 @@ int main()
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
A test1 = {3, 2, 1};
#endif
+#if _LIBCPP_STD_VER > 11
+ constexpr B test2 = {3, 2, 1};
+#endif // _LIBCPP_STD_VER > 11
}
Modified: libcxx/trunk/test/language.support/support.initlist/support.initlist.cons/default.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/language.support/support.initlist/support.initlist.cons/default.pass.cpp?rev=189271&r1=189270&r2=189271&view=diff
==============================================================================
--- libcxx/trunk/test/language.support/support.initlist/support.initlist.cons/default.pass.cpp (original)
+++ libcxx/trunk/test/language.support/support.initlist/support.initlist.cons/default.pass.cpp Mon Aug 26 15:11:32 2013
@@ -22,4 +22,8 @@ int main()
std::initializer_list<A> il;
assert(il.size() == 0);
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
+#if _LIBCPP_STD_VER > 11
+ constexpr std::initializer_list<A> il2;
+ static_assert(il2.size() == 0, "");
+#endif // _LIBCPP_STD_VER > 11
}
Modified: libcxx/trunk/test/language.support/support.initlist/support.initlist.range/begin_end.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/language.support/support.initlist/support.initlist.range/begin_end.pass.cpp?rev=189271&r1=189270&r2=189271&view=diff
==============================================================================
--- libcxx/trunk/test/language.support/support.initlist/support.initlist.range/begin_end.pass.cpp (original)
+++ libcxx/trunk/test/language.support/support.initlist/support.initlist.range/begin_end.pass.cpp Mon Aug 26 15:11:32 2013
@@ -30,6 +30,22 @@ struct A
}
};
+#if _LIBCPP_STD_VER > 11
+struct B
+{
+ constexpr B(std::initializer_list<int> il)
+ {
+ const int* b = begin(il);
+ const int* e = end(il);
+ assert(il.size() == 3);
+ assert(e - b == il.size());
+ assert(*b++ == 3);
+ assert(*b++ == 2);
+ assert(*b++ == 1);
+ }
+};
+
+#endif // _LIBCPP_STD_VER > 11
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
int main()
@@ -37,4 +53,7 @@ int main()
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
A test1 = {3, 2, 1};
#endif
+#if _LIBCPP_STD_VER > 11
+ constexpr B test2 = {3, 2, 1};
+#endif // _LIBCPP_STD_VER > 11
}
More information about the cfe-commits
mailing list