Not sure how to keep Type out of the template while still referencing it from the templated class. i.e. How would I do this: "DualLookup::Type"?

This commit is contained in:
David Vereb 2017-11-10 15:42:32 -05:00
parent 757f877a5b
commit 6e603b412f
2 changed files with 13 additions and 7 deletions

View File

@ -2,11 +2,8 @@
#define DVEREB_DUALLOOKUP_H
#include <unordered_map>
template <class T>
class DualLookup {
public:
DualLookup();
struct DualLookupBase {
// NOTE(dev): Used to determine which version of the string you want:
// 1 / OPPOSITE: The string it maps to, opposite of the one you pass in.
// 2 / VALUE: The string passed via the first paramater of 'add.'
@ -17,6 +14,15 @@ public:
EQUIVALENT,
};
protected:
DualLookupBase() {}
};
template <class T>
class DualLookup : public DualLookupBase {
public:
DualLookup();
/* Add a mapped pair to the container
* returns false if it already exists, regardless of direction
* (i.e. value->equivilent is a duplicate of equivilent->value)

View File

@ -65,13 +65,13 @@ TEST_CASE("all tests", "all") {
REQUIRE(container.get(1, container_result));
CHECK(container_result == 2);
container_result = 0;
REQUIRE(container.get(1, container_result, DualLookup<int>::Type::OPPOSITE));
REQUIRE(container.get(1, container_result, DualLookupBase::Type::OPPOSITE));
CHECK(container_result == 2);
container_result = 0;
REQUIRE(container.get(1, container_result, DualLookup<int>::Type::EQUIVALENT));
REQUIRE(container.get(1, container_result, DualLookupBase::Type::EQUIVALENT));
CHECK(container_result == 2);
container_result = 0;
REQUIRE(container.get(1, container_result, DualLookup<int>::Type::VALUE));
REQUIRE(container.get(1, container_result, DualLookupBase::Type::VALUE));
CHECK(container_result == 1);
container_result = 0;