Close the forms of forgetting that are not named like removal
The retention claim covered methods named like removal and nothing else,
so the archive forgot everything on assignment: archive = LineageArchive{}
discarded every record, and assigning a copy taken before a death
restored that organism's living state, defeating terminal death as well.
The copy and move policy is now part of the interface rather than left to
the defaults. Both forms of assignment are deleted, which also makes the
archive unswappable since swapping needs them. Declaring the copy
constructor suppresses the implicit moves, so a move decays to a copy and
a moved-from archive still holds every record rather than being emptied
the way a moved-from container would be.
Copying stays available on purpose: a clone takes nothing from the
original, and GENOME_MODEL expects migrations to be rehearsed on cloned
worlds. Deleting the move constructor as well would be stricter but would
stop an archive being returned from a function, so it decays instead.
The interface tests now cover assignment, replacement from a temporary
and swapping alongside the named methods, each with a std::vector
positive control so the checks are known to be live. Runtime checks
confirm a copy taken before a death leaves the original's terminal record
standing, and that a moved-from archive still holds everything. All four
static assertions were confirmed to fail with the deletions removed.
ADR-0034 said the type offered no way to forget. That was too narrow, and
the Decision and Alternatives now say why assignment counts.
Native Release, clang-tidy analysis, ASan and format checks pass 21/21.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
@@ -7,6 +7,7 @@
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
namespace {
|
||||
@@ -179,6 +180,42 @@ template <typename Archive>
|
||||
concept clears = requires(Archive& archive) { archive.clear(); };
|
||||
template <typename Archive>
|
||||
concept prunes = requires(Archive& archive) { archive.prune(); };
|
||||
// Forgetting has forms that are not named like removal. Replacing an archive
|
||||
// wholesale discards every record it held, and swapping needs the same
|
||||
// assignment that makes replacement possible.
|
||||
template <typename Archive>
|
||||
concept replaceable = requires(Archive& archive) { archive = Archive{}; };
|
||||
template <typename Archive>
|
||||
concept exchangeable = requires(Archive& left, Archive& right) { std::swap(left, right); };
|
||||
|
||||
void the_archive_cannot_be_replaced_or_rewound() {
|
||||
static_assert(!replaceable<LineageArchive>);
|
||||
static_assert(!exchangeable<LineageArchive>);
|
||||
static_assert(!std::is_copy_assignable_v<LineageArchive>);
|
||||
static_assert(!std::is_move_assignable_v<LineageArchive>);
|
||||
// These checks are live: an ordinary container admits all of them.
|
||||
static_assert(replaceable<std::vector<std::uint64_t>>);
|
||||
static_assert(exchangeable<std::vector<std::uint64_t>>);
|
||||
// Copying stays available, because a clone takes nothing from the original.
|
||||
static_assert(std::is_copy_constructible_v<LineageArchive>);
|
||||
auto archive = branching();
|
||||
CHECK(archive.record_birth(800, 3, evo::Tick{1}));
|
||||
const auto taken_while_living = archive; // A copy from before the death.
|
||||
CHECK(archive.record_death(800, evo::Tick{9}));
|
||||
CHECK(!archive.organism(800)->alive);
|
||||
// The copy is a separate archive. Nothing can write it back over the
|
||||
// original, so the terminal record stands.
|
||||
CHECK(taken_while_living.organism(800)->alive);
|
||||
CHECK(!archive.organism(800)->alive);
|
||||
// A move decays to a copy, so the source still holds every record rather
|
||||
// than being emptied the way a moved-from container would be.
|
||||
// NOLINTNEXTLINE(performance-move-const-arg)
|
||||
const auto moved = std::move(archive);
|
||||
// NOLINTNEXTLINE(bugprone-use-after-move): the point of the check.
|
||||
CHECK(archive.archived() == moved.archived() && archive.recorded() == 1);
|
||||
// NOLINTNEXTLINE(bugprone-use-after-move)
|
||||
CHECK(archive.find(1) && !archive.organism(800)->alive);
|
||||
}
|
||||
|
||||
void the_archive_offers_no_way_to_forget() {
|
||||
static_assert(!erases<LineageArchive>);
|
||||
@@ -221,6 +258,7 @@ int main() try {
|
||||
admission_refuses_duplicates_and_dangling_parents();
|
||||
death_is_terminal_and_births_are_unique();
|
||||
absence_is_never_reported_as_extinction();
|
||||
the_archive_cannot_be_replaced_or_rewound();
|
||||
the_archive_offers_no_way_to_forget();
|
||||
capacity_refuses_loudly_rather_than_dropping();
|
||||
std::cout << "PASS lineage retention, branching ancestry and provisional absence\n";
|
||||
|
||||
Reference in New Issue
Block a user