1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 // <iterator> 11 // template <class C> constexpr auto empty(const C& c) -> decltype(c.empty()); // C++17 12 // template <class T, size_t N> constexpr bool empty(const T (&array)[N]) noexcept; // C++17 13 // template <class E> constexpr bool empty(initializer_list<E> il) noexcept; // C++17 14 15 #include "test_macros.h" 16 17 #if TEST_STD_VER <= 14 main()18int main () {} 19 #else 20 21 #include <iterator> 22 #include <cassert> 23 #include <vector> 24 #include <array> 25 #include <list> 26 #include <initializer_list> 27 28 template<typename C> test_const_container(const C & c)29void test_const_container( const C& c ) 30 { 31 assert ( std::empty(c) == c.empty()); 32 } 33 34 template<typename T> test_const_container(const std::initializer_list<T> & c)35void test_const_container( const std::initializer_list<T>& c ) 36 { 37 assert ( std::empty(c) == (c.size() == 0)); 38 } 39 40 template<typename C> test_container(C & c)41void test_container( C& c ) 42 { 43 assert ( std::empty(c) == c.empty()); 44 } 45 46 template<typename T> test_container(std::initializer_list<T> & c)47void test_container( std::initializer_list<T>& c ) 48 { 49 assert ( std::empty(c) == (c.size() == 0)); 50 } 51 52 template<typename T, size_t Sz> test_const_array(const T (& array)[Sz])53void test_const_array( const T (&array)[Sz] ) 54 { 55 assert (!std::empty(array)); 56 } 57 main()58int main() 59 { 60 std::vector<int> v; v.push_back(1); 61 std::list<int> l; l.push_back(2); 62 std::array<int, 1> a; a[0] = 3; 63 std::initializer_list<int> il = { 4 }; 64 65 test_container ( v ); 66 test_container ( l ); 67 test_container ( a ); 68 test_container ( il ); 69 70 test_const_container ( v ); 71 test_const_container ( l ); 72 test_const_container ( a ); 73 test_const_container ( il ); 74 75 static constexpr int arrA [] { 1, 2, 3 }; 76 test_const_array ( arrA ); 77 } 78 79 #endif 80