brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 9fb6785 Raw
70 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// flat_map()14//    noexcept(15//        is_nothrow_default_constructible_v<key_container_type> &&16//        is_nothrow_default_constructible_v<mapped_container_type> &&17//        is_nothrow_default_constructible_v<key_compare>);18 19// This tests a conforming extension20 21#include <cassert>22#include <flat_map>23#include <functional>24#include <vector>25 26#include "test_macros.h"27#include "MoveOnly.h"28#include "test_allocator.h"29 30struct ThrowingCtorComp {31  constexpr ThrowingCtorComp() noexcept(false) {}32  constexpr bool operator()(const auto&, const auto&) const { return false; }33};34 35constexpr bool test() {36#if defined(_LIBCPP_VERSION)37  {38    using C = std::flat_map<MoveOnly, MoveOnly>;39    static_assert(std::is_nothrow_default_constructible_v<C>);40    C c;41  }42  {43    using C = std::flat_map<MoveOnly, MoveOnly, std::less<MoveOnly>, std::vector<MoveOnly, test_allocator<MoveOnly>>>;44    static_assert(std::is_nothrow_default_constructible_v<C>);45    C c;46  }47#endif // _LIBCPP_VERSION48  {49    using C = std::flat_map<MoveOnly, MoveOnly, std::less<MoveOnly>, std::vector<MoveOnly, other_allocator<MoveOnly>>>;50    static_assert(!std::is_nothrow_default_constructible_v<C>);51    C c;52  }53  {54    using C = std::flat_map<MoveOnly, MoveOnly, ThrowingCtorComp>;55    static_assert(!std::is_nothrow_default_constructible_v<C>);56    C c;57  }58 59  return true;60}61 62int main(int, char**) {63  test();64#if TEST_STD_VER >= 2665  static_assert(test());66#endif67 68  return 0;69}70