Apply constexpr to initializer_list for c++1y.
git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@189271 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
bce2a4752a
commit
e1c5f9ec1b
@ -29,15 +29,15 @@ public:
|
|||||||
typedef const E* iterator;
|
typedef const E* iterator;
|
||||||
typedef const E* const_iterator;
|
typedef const E* const_iterator;
|
||||||
|
|
||||||
initializer_list() noexcept;
|
initializer_list() noexcept; // constexpr in C++14
|
||||||
|
|
||||||
size_t size() const noexcept;
|
size_t size() const noexcept; // constexpr in C++14
|
||||||
const E* begin() const noexcept;
|
const E* begin() const noexcept; // constexpr in C++14
|
||||||
const E* end() const noexcept;
|
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* begin(initializer_list<E> il) noexcept; // constexpr in C++14
|
||||||
template<class E> const E* end(initializer_list<E> il) noexcept;
|
template<class E> const E* end(initializer_list<E> il) noexcept; // constexpr in C++14
|
||||||
|
|
||||||
} // std
|
} // std
|
||||||
|
|
||||||
@ -62,6 +62,7 @@ class _LIBCPP_TYPE_VIS_ONLY initializer_list
|
|||||||
size_t __size_;
|
size_t __size_;
|
||||||
|
|
||||||
_LIBCPP_ALWAYS_INLINE
|
_LIBCPP_ALWAYS_INLINE
|
||||||
|
_LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||||
initializer_list(const _Ep* __b, size_t __s) _NOEXCEPT
|
initializer_list(const _Ep* __b, size_t __s) _NOEXCEPT
|
||||||
: __begin_(__b),
|
: __begin_(__b),
|
||||||
__size_(__s)
|
__size_(__s)
|
||||||
@ -75,15 +76,26 @@ public:
|
|||||||
typedef const _Ep* iterator;
|
typedef const _Ep* iterator;
|
||||||
typedef const _Ep* const_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
|
||||||
_LIBCPP_ALWAYS_INLINE const _Ep* begin() const _NOEXCEPT {return __begin_;}
|
_LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||||
_LIBCPP_ALWAYS_INLINE const _Ep* end() const _NOEXCEPT {return __begin_ + __size_;}
|
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>
|
template<class _Ep>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
_LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||||
const _Ep*
|
const _Ep*
|
||||||
begin(initializer_list<_Ep> __il) _NOEXCEPT
|
begin(initializer_list<_Ep> __il) _NOEXCEPT
|
||||||
{
|
{
|
||||||
@ -92,6 +104,7 @@ begin(initializer_list<_Ep> __il) _NOEXCEPT
|
|||||||
|
|
||||||
template<class _Ep>
|
template<class _Ep>
|
||||||
inline _LIBCPP_INLINE_VISIBILITY
|
inline _LIBCPP_INLINE_VISIBILITY
|
||||||
|
_LIBCPP_CONSTEXPR_AFTER_CXX11
|
||||||
const _Ep*
|
const _Ep*
|
||||||
end(initializer_list<_Ep> __il) _NOEXCEPT
|
end(initializer_list<_Ep> __il) _NOEXCEPT
|
||||||
{
|
{
|
||||||
|
@ -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
|
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@ -39,4 +56,7 @@ int main()
|
|||||||
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
|
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
|
||||||
A test1 = {3, 2, 1};
|
A test1 = {3, 2, 1};
|
||||||
#endif
|
#endif
|
||||||
|
#if _LIBCPP_STD_VER > 11
|
||||||
|
constexpr B test2 = {3, 2, 1};
|
||||||
|
#endif // _LIBCPP_STD_VER > 11
|
||||||
}
|
}
|
||||||
|
@ -22,4 +22,8 @@ int main()
|
|||||||
std::initializer_list<A> il;
|
std::initializer_list<A> il;
|
||||||
assert(il.size() == 0);
|
assert(il.size() == 0);
|
||||||
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
|
#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
|
||||||
}
|
}
|
||||||
|
@ -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
|
#endif // _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
@ -37,4 +53,7 @@ int main()
|
|||||||
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
|
#ifndef _LIBCPP_HAS_NO_GENERALIZED_INITIALIZERS
|
||||||
A test1 = {3, 2, 1};
|
A test1 = {3, 2, 1};
|
||||||
#endif
|
#endif
|
||||||
|
#if _LIBCPP_STD_VER > 11
|
||||||
|
constexpr B test2 = {3, 2, 1};
|
||||||
|
#endif // _LIBCPP_STD_VER > 11
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user