Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20

// <flat_set>

// https://github.com/llvm/llvm-project/issues/119016

#include <flat_set>

#include <cassert>

#include "../flat_helpers.h"
#include "test_macros.h"

bool test() {
using M = std::flat_multiset<TrackCopyMove>;
{
M m;
TrackCopyMove t;
m.insert(t);
assert(m.begin()->copy_count == 1);
assert(m.begin()->move_count == 0);
}
{
M m;
TrackCopyMove t;
m.emplace(t);
assert(m.begin()->copy_count == 1);
assert(m.begin()->move_count == 0);
}

return true;
}

int main(int, char**) {
test();

return 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

// UNSUPPORTED: c++03, c++11, c++14, c++17, c++20

// <flat_set>

// https://github.com/llvm/llvm-project/issues/119016

#include <flat_set>

#include <cassert>

#include "../flat_helpers.h"
#include "test_macros.h"

bool test() {
using M = std::flat_set<TrackCopyMove>;
{
M m;
TrackCopyMove t;
m.insert(t);
assert(m.begin()->copy_count == 1);
assert(m.begin()->move_count == 0);
}
{
M m;
TrackCopyMove t;
m.emplace(t);
assert(m.begin()->copy_count == 1);
assert(m.begin()->move_count == 0);
}

return true;
}

int main(int, char**) {
test();

return 0;
}
40 changes: 40 additions & 0 deletions libcxx/test/libcxx/containers/container.adaptors/flat_helpers.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#ifndef TEST_LIBCXX_CONTAINERS_CONTAINER_ADAPTORS_FLAT_HELPERS_H
#define TEST_LIBCXX_CONTAINERS_CONTAINER_ADAPTORS_FLAT_HELPERS_H

struct TrackCopyMove {
mutable int copy_count = 0;
int move_count = 0;

constexpr TrackCopyMove() = default;
constexpr TrackCopyMove(const TrackCopyMove& other) : copy_count(other.copy_count), move_count(other.move_count) {
++copy_count;
++other.copy_count;
}

constexpr TrackCopyMove(TrackCopyMove&& other) noexcept : copy_count(other.copy_count), move_count(other.move_count) {
++move_count;
++other.move_count;
}
constexpr TrackCopyMove& operator=(const TrackCopyMove& other) {
++copy_count;
++other.copy_count;
return *this;
}
constexpr TrackCopyMove& operator=(TrackCopyMove&& other) noexcept {
++move_count;
++other.move_count;
return *this;
}
constexpr bool operator==(const TrackCopyMove&) const { return true; }
constexpr bool operator<(const TrackCopyMove&) const { return false; }
};

#endif // TEST_LIBCXX_CONTAINERS_CONTAINER_ADAPTORS_FLAT_HELPERS_H
Loading