ExcaliburHash icon indicating copy to clipboard operation
ExcaliburHash copied to clipboard

Static_assert using Excalibur::HashTable<string, unique_ptr<...>> and Emplace

Open naricc opened this issue 1 year ago • 0 comments

I am seeing this error:

am seeing this static_assert error when trying to use build a program using ExcaliburHash<string, unique_ptr<...>> and Emplace for at least some kinds of unique_ptr:

In file included from hash_test.cpp:3:
../ExcaliburHash/ExcaliburHash/ExcaliburHash.h: In instantiation of 'std::pair<Excalibur::HashTable<TKey, TValue, kNumInlineItems, TKeyInfo>::TIteratorKV<TValue>, bool> Excalibur::HashTable<TKey, TValue, kNumInlineItems, TKeyInfo>::emplace(TK&&, Args&& ...) [with TK = const char (&)[1]; Args = {std::unique_ptr<StringInternStringData, std::default_delete<StringInternStringData> >}; TKey = std::__cxx11::basic_string<char>; TValue = std::unique_ptr<StringInternStringData>; unsigned int kNumInlineItems = 1; TKeyInfo = Excalibur::KeyInfo<std::__cxx11::basic_string<char> >]':
hash_test.cpp:27:34:   required from here
  27 |     auto inserted = exMap.emplace("", make_unique<StringInternStringData>(""));
     |                     ~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
../ExcaliburHash/ExcaliburHash/ExcaliburHash.h:741:119: error: static assertion failed: Expected unversal reference of TKey type. Wrong key type?
 741 |         static_assert(std::is_same<TKey, typename std::remove_const<typename std::remove_reference<TK>::type>::type>::value,
     |                                                                                                                       ^~~~~
../ExcaliburHash/ExcaliburHash/ExcaliburHash.h:741:119: note: 'std::integral_constant<bool, false>::value' evaluates to false

contests of hash_test3.cpp

#include <memory>
#include "ExcaliburHash.h"

using namespace std;

class StringInternStringData
{
public:
	inline StringInternStringData()
		: refCount(0), string()
	{	}

	inline StringInternStringData(const std::string &string)
		: refCount(1), string(string)
	{	}

    int64_t refCount;
	std::string string;
};


int main(void) 
{
    Excalibur::HashTable<string, unique_ptr<StringInternStringData>>  exMap;

    auto inserted = exMap.emplace("", make_unique<StringInternStringData>(""));

    // auto res = inserted.first->second.get();
    return 0;
}

If I replace Excalibur::HashTable with a std::map, it works fine (or at least builds). So I am confused if I am doing something wrong, or the interface of ExcaliburHash is different some how, or what the problem is.

Building was attempted with g++-14

naricc avatar Nov 06 '24 19:11 naricc