64 lines · cpp
1//===----------------------------------------------------------------------===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9// UNSUPPORTED: c++03, c++11, c++14, c++17, c++2010 11// <flat_map>12 13// [[nodiscard]] bool empty() const noexcept;14 15#include <flat_map>16#include <cassert>17#include <deque>18#include <functional>19#include <utility>20#include <vector>21 22#include "MinSequenceContainer.h"23#include "test_macros.h"24#include "min_allocator.h"25 26template <class KeyContainer, class ValueContainer>27constexpr void test() {28 using Key = typename KeyContainer::value_type;29 using Value = typename ValueContainer::value_type;30 using M = std::flat_map<Key, Value, std::less<int>, KeyContainer, ValueContainer>;31 M m;32 ASSERT_SAME_TYPE(decltype(m.empty()), bool);33 ASSERT_NOEXCEPT(m.empty());34 assert(m.empty());35 assert(std::as_const(m).empty());36 m = {{1, 1.0}};37 assert(!m.empty());38 m.clear();39 assert(m.empty());40}41 42constexpr bool test() {43 test<std::vector<int>, std::vector<double>>();44#ifndef __cpp_lib_constexpr_deque45 if (!TEST_IS_CONSTANT_EVALUATED)46#endif47 {48 test<std::deque<int>, std::vector<double>>();49 }50 test<MinSequenceContainer<int>, MinSequenceContainer<double>>();51 test<std::vector<int, min_allocator<int>>, std::vector<double, min_allocator<double>>>();52 53 return true;54}55 56int main(int, char**) {57 test();58#if TEST_STD_VER >= 2659 static_assert(test());60#endif61 62 return 0;63}64