Add LLVM_HAS_INITIALIZER_LISTS for upcoming C++11 support. Use it in ArrayRef
authorPete Cooper <peter_cooper@apple.com>
Mon, 11 Nov 2013 03:58:00 +0000 (03:58 +0000)
committerPete Cooper <peter_cooper@apple.com>
Mon, 11 Nov 2013 03:58:00 +0000 (03:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@194362 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/ADT/ArrayRef.h
include/llvm/Support/Compiler.h

index a0b6eff269f5ca0aa6934dc65ceb436cedd27ef2..61467e9b21c326f94c98032cc2302761838aceb6 100644 (file)
@@ -83,6 +83,13 @@ namespace llvm {
     /*implicit*/ LLVM_CONSTEXPR ArrayRef(const T (&Arr)[N])
       : Data(Arr), Length(N) {}
 
+#if LLVM_HAS_INITIALIZER_LISTS
+    /// Construct an ArrayRef from a std::initializer_list.
+    /*implicit*/ ArrayRef(const std::initializer_list<T> &Vec)
+    : Data(Vec.begin() == Vec.end() ? (T*)0 : Vec.begin()),
+      Length(Vec.size()) {}
+#endif
+
     /// @}
     /// @name Simple Operations
     /// @{
index 13920fcc5a89b7105ac01e2ff15f615c314a9d41..5ce9abc49d4835b3b5f82f4151e663cff263044a 100644 (file)
 # define LLVM_ENUM_INT_TYPE(intty)
 #endif
 
+/// \brief Does the compiler support generalized initializers (using braced
+/// lists and std::initializer_list).
+#if (__has_feature(cxx_generalized_initializers)   \
+|| defined(__GXX_EXPERIMENTAL_CXX0X__))
+#define LLVM_HAS_INITIALIZER_LISTS 1
+#else
+#define LLVM_HAS_INITIALIZER_LISTS 0
+#endif
+
 #endif