Stroika Library 3.0d18
 
Loading...
Searching...
No Matches
Mapping.cpp
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#include "Stroika/Foundation/StroikaPreComp.h"
5
8#include "Stroika/Foundation/Containers/Mapping.h"
10
11// Not generally included, but you can include these if you want to select a particular backend implementation
15
17
18#include "Mapping.h"
19
20using namespace std;
21
22using namespace Stroika::Foundation;
24
25namespace {
26 void SimplestMappingTest_ ()
27 {
28 /*
29 * Mapping which allows for the association of two elements: a key and
30 * a value. The key UNIQUELY specifies its associated value.
31 *
32 * This is much like std::map, except that Stroika Mapping's can be implemented with different data structures (e..g hash table
33 * tree) and don't always require a less<> comparsion operator to be defined.
34 */
36 m.Add (3, -3);
37 m.Add (19, -19);
38 for ([[maybe_unused]] KeyValuePair<int, int> p : m) {
39 Assert (p.fKey == -p.fValue);
40 }
41 if (m.Lookup (5)) {
42 AssertNotReached (); // better not find it
43 }
44 if (auto v = m.Lookup (3)) {
45 Assert (v == -3);
46 }
47 Assert (m.LookupValue (3) == -3);
48 Assert (m.LookupValue (5, -1) == -1); // since 5 not found, default used
49 }
50}
51
52void Samples::Containers::Mapping::RunDemo ()
53{
54 SimplestMappingTest_ ();
55}
#define AssertNotReached()
Definition Assertions.h:355
nonvirtual bool Add(ArgByValueType< key_type > key, ArgByValueType< mapped_type > newElt, AddReplaceMode addReplaceMode=AddReplaceMode::eAddReplaces)
Definition Mapping.inl:188
nonvirtual optional< mapped_type > Lookup(ArgByValueType< key_type > key) const
Definition Mapping.inl:142
nonvirtual mapped_type LookupValue(ArgByValueType< key_type > key, ArgByValueType< mapped_type > defaultValue=mapped_type{}) const
Definition Mapping.inl:166
STL namespace.