Home | History | Annotate | Download | only in iterator.container
      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 #if __cplusplus <= 201402L
     16 int main () {}
     17 #else
     18 
     19 #include <iterator>
     20 #include <cassert>
     21 #include <vector>
     22 #include <array>
     23 #include <list>
     24 #include <initializer_list>
     25 
     26 template<typename C>
     27 void test_const_container( const C& c )
     28 {
     29     assert ( std::empty(c)   == c.empty());
     30 }
     31 
     32 template<typename T>
     33 void test_const_container( const std::initializer_list<T>& c )
     34 {
     35     assert ( std::empty(c)   == (c.size() == 0));
     36 }
     37 
     38 template<typename C>
     39 void test_container( C& c )
     40 {
     41     assert ( std::empty(c)   == c.empty());
     42 }
     43 
     44 template<typename T>
     45 void test_container( std::initializer_list<T>& c )
     46 {
     47     assert ( std::empty(c)   == (c.size() == 0));
     48 }
     49 
     50 template<typename T, size_t Sz>
     51 void test_const_array( const T (&array)[Sz] )
     52 {
     53     assert (!std::empty(array));
     54 }
     55 
     56 int main()
     57 {
     58     std::vector<int> v; v.push_back(1);
     59     std::list<int>   l; l.push_back(2);
     60     std::array<int, 1> a; a[0] = 3;
     61     std::initializer_list<int> il = { 4 };
     62 
     63     test_container ( v );
     64     test_container ( l );
     65     test_container ( a );
     66     test_container ( il );
     67 
     68     test_const_container ( v );
     69     test_const_container ( l );
     70     test_const_container ( a );
     71     test_const_container ( il );
     72 
     73     static constexpr int arrA [] { 1, 2, 3 };
     74     test_const_array ( arrA );
     75 }
     76 
     77 #endif
     78