From fcc593875c9e7a45b3ffea76a02cb6e3d9d35f7d Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Fri, 28 May 2010 17:53:59 +0000 Subject: [PATCH] [support.initlist.range] git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@104975 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/initializer_list | 19 ++++++++++ .../support.initlist.range/begin_end.pass.cpp | 36 +++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 test/language.support/support.initlist/support.initlist.range/begin_end.pass.cpp diff --git a/include/initializer_list b/include/initializer_list index 266c0f559..671aa2710 100644 --- a/include/initializer_list +++ b/include/initializer_list @@ -36,6 +36,9 @@ public: const E* end() const; }; +template const E* begin(initializer_list il); +template const E* end(initializer_list il); + } // std */ @@ -75,6 +78,22 @@ public: _LIBCPP_ALWAYS_INLINE const _E* end() const {return __begin_ + __size_;} }; +template +inline _LIBCPP_INLINE_VISIBILITY +const _E* +begin(initializer_list<_E> __il) +{ + return __il.begin(); +} + +template +inline _LIBCPP_INLINE_VISIBILITY +const _E* +end(initializer_list<_E> __il) +{ + return __il.end(); +} + } // std #endif // _LIBCPP_INITIALIZER_LIST diff --git a/test/language.support/support.initlist/support.initlist.range/begin_end.pass.cpp b/test/language.support/support.initlist/support.initlist.range/begin_end.pass.cpp new file mode 100644 index 000000000..7c6dc1c4b --- /dev/null +++ b/test/language.support/support.initlist/support.initlist.range/begin_end.pass.cpp @@ -0,0 +1,36 @@ +//===----------------------------------------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +// + +// template const E* begin(initializer_list il); + +#include +#include + +struct A +{ + A(std::initializer_list 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); + } +}; + +int main() +{ +#ifdef _LIBCPP_MOVE + A test1 = {3, 2, 1}; +#endif +}