Can't use Add function on a TMap with a TDoubleLinkedList as its value

I declare a variable like this :

TMap<int32, TDoubleLinkedList<int32>> newMap;

And call Add or Emplace function like this :

newMap.Add(1);
or
newMap.Add(1, TDoubleLinkedList<int32>());

But error occurred.
Is there any solution that use TMap with TDoubleLinkedList?

Below is error log.

D:\Program Files\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Map.h(51): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'TTuple<KeyType,ValueType>'
          with
          [
              KeyType=int32,
              ValueType=TDoubleLinkedList<int32>
          ]
  D:\Program Files\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Map.h(51): note: No constructor could take the source type, or constructor overload resolution was ambiguous
  D:\Program Files\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Set.h(207): note: see reference to function template instantiation 'TPairInitializer<InitKeyType &&,InitValueType &&>::operator TTuple<KeyType,ValueType>(void) const<KeyType,ValueType>' being compiled
          with
          [
              InitKeyType=int,
              InitValueType=TDoubleLinkedList<int32>,
              KeyType=int32,
              ValueType=TDoubleLinkedList<int32>
          ]
  D:\Program Files\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Set.h(206): note: see reference to function template instantiation 'TPairInitializer<InitKeyType &&,InitValueType &&>::operator TTuple<KeyType,ValueType>(void) const<KeyType,ValueType>' being compiled
          with
          [
              InitKeyType=int,
              InitValueType=TDoubleLinkedList<int32>,
              KeyType=int32,
              ValueType=TDoubleLinkedList<int32>
          ]
  D:\Program Files\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Set.h(242): note: see reference to function template instantiation 'TSetElementBase<InElementType,true>::TSetElementBase<T,void>(InitType &&)' being compiled
          with
          [
              InElementType=TTuple<int32,TDoubleLinkedList<int32>>,
              T=TPairInitializer<int &&,TDoubleLinkedList<int32> &&>,
              InitType=TPairInitializer<int &&,TDoubleLinkedList<int32> &&>
          ]
  D:\Program Files\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Set.h(241): note: see reference to function template instantiation 'TSetElementBase<InElementType,true>::TSetElementBase<T,void>(InitType &&)' being compiled
          with
          [
              InElementType=TTuple<int32,TDoubleLinkedList<int32>>,
              T=TPairInitializer<int &&,TDoubleLinkedList<int32> &&>,
              InitType=TPairInitializer<int &&,TDoubleLinkedList<int32> &&>
          ]
  D:\Program Files\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Set.h(717): note: see reference to function template instantiation 'TSetElement<InElementType>::TSetElement<T,void>(InitType &&)' being compiled
          with
          [
              InElementType=TTuple<int32,TDoubleLinkedList<int32>>,
              T=TPairInitializer<int &&,TDoubleLinkedList<int32> &&>,
              InitType=TPairInitializer<int &&,TDoubleLinkedList<int32> &&>
          ]
  D:\Program Files\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Set.h(717): note: see reference to function template instantiation 'TSetElement<InElementType>::TSetElement<T,void>(InitType &&)' being compiled
          with
          [
              InElementType=TTuple<int32,TDoubleLinkedList<int32>>,
              T=TPairInitializer<int &&,TDoubleLinkedList<int32> &&>,
              InitType=TPairInitializer<int &&,TDoubleLinkedList<int32> &&>
          ]
  D:\Program Files\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Map.h(404): note: see reference to function template instantiation 'FSetElementId TSet<TTuple<KeyType,ValueType>,KeyFuncs,SetAllocator>::Emplace<TPairInitializer<InitKeyType &&,InitValueType &&>>(ArgsType &&,bool *)' being compiled
          with
          [
              KeyType=int32,
              ValueType=TDoubleLinkedList<int32>,
              KeyFuncs=TDefaultMapHashableKeyFuncs<int32,TDoubleLinkedList<int32>,false>,
              SetAllocator=FDefaultSetAllocator,
              InitKeyType=int,
              InitValueType=TDoubleLinkedList<int32>,
              ArgsType=TPairInitializer<int &&,TDoubleLinkedList<int32> &&>
          ]
  D:\Program Files\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Map.h(404): note: see reference to function template instantiation 'FSetElementId TSet<TTuple<KeyType,ValueType>,KeyFuncs,SetAllocator>::Emplace<TPairInitializer<InitKeyType &&,InitValueType &&>>(ArgsType &&,bool *)' being compiled
          with
          [
              KeyType=int32,
              ValueType=TDoubleLinkedList<int32>,
              KeyFuncs=TDefaultMapHashableKeyFuncs<int32,TDoubleLinkedList<int32>,false>,
              SetAllocator=FDefaultSetAllocator,
              InitKeyType=int,
              InitValueType=TDoubleLinkedList<int32>,
              ArgsType=TPairInitializer<int &&,TDoubleLinkedList<int32> &&>
          ]
  D:\Program Files\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Map.h(365): note: see reference to function template instantiation 'ValueType &TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs>::Emplace<int,TDoubleLinkedList<int32>>(InitKeyType &&,InitValueType &&)' being compiled
          with
          [
              ValueType=TDoubleLinkedList<int32>,
              KeyType=int32,
              SetAllocator=FDefaultSetAllocator,
              KeyFuncs=TDefaultMapHashableKeyFuncs<int32,TDoubleLinkedList<int32>,false>,
              InitKeyType=int,
              InitValueType=TDoubleLinkedList<int32>
          ]
  D:\Program Files\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Map.h(365): note: see reference to function template instantiation 'ValueType &TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs>::Emplace<int,TDoubleLinkedList<int32>>(InitKeyType &&,InitValueType &&)' being compiled
          with
          [
              ValueType=TDoubleLinkedList<int32>,
              KeyType=int32,
              SetAllocator=FDefaultSetAllocator,
              KeyFuncs=TDefaultMapHashableKeyFuncs<int32,TDoubleLinkedList<int32>,false>,
              InitKeyType=int,
              InitValueType=TDoubleLinkedList<int32>
          ]
  D:\Program Files\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Map.h(365): note: while compiling class template member function 'ValueType &TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs>::Add(KeyType &&,ValueType &&)'
          with
          [
              ValueType=TDoubleLinkedList<int32>,
              KeyType=int32,
              SetAllocator=FDefaultSetAllocator,
              KeyFuncs=TDefaultMapHashableKeyFuncs<int32,TDoubleLinkedList<int32>,false>
          ]
 [The line and path of Add function called in my project]: note: see reference to function template instantiation 'ValueType &TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs>::Add(KeyType &&,ValueType &&)' being compiled
          with
          [
              ValueType=TDoubleLinkedList<int32>,
              KeyType=int32,
              SetAllocator=FDefaultSetAllocator,
              KeyFuncs=TDefaultMapHashableKeyFuncs<int32,TDoubleLinkedList<int32>,false>
          ]
  D:\Program Files\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Map.h(966): note: see reference to class template instantiation 'TMapBase<KeyType,ValueType,SetAllocator,KeyFuncs>' being compiled
          with
          [
              KeyType=int32,
              ValueType=TDoubleLinkedList<int32>,
              SetAllocator=FDefaultSetAllocator,
              KeyFuncs=TDefaultMapHashableKeyFuncs<int32,TDoubleLinkedList<int32>,false>
          ]
  D:\Program Files\UE_5.2\Engine\Source\Runtime\Core\Public\Containers\Map.h(1102): note: see reference to class template instantiation 'TSortableMapBase<InKeyType,InValueType,SetAllocator,KeyFuncs>' being compiled
          with
          [
              InKeyType=int32,
              InValueType=TDoubleLinkedList<int32>,
              SetAllocator=FDefaultSetAllocator,
              KeyFuncs=TDefaultMapHashableKeyFuncs<int32,TDoubleLinkedList<int32>,false>
          ]
  [The line and path of Add function called in my project]: note: see reference to class template instantiation 'TMap<int32,TDoubleLinkedList<int32>,FDefaultSetAllocator,TDefaultMapHashableKeyFuncs<InKeyType,InValueType,false>>' being compiled
          with
          [
              InKeyType=int32,
              InValueType=TDoubleLinkedList<int32>
          ]
Build failed.

Thank you for your help :grinning:

+) I try to wrap TDoubleLinkedList by struct or class. But results are the same.

struct FListWrapper
{
	TDoubleLinkedList<int32> list;
}

Hey @happyfun3280,

I believe for the add you need to do it as follows:

newMap.Add(1, TDoubleLinkedList<int32>()); for a new key with an empty TDoubleLinkedList<int32>

Or

newMap[1].AddTail(42); to access the list and add elements to it

Let me know if this helps!

1 Like

Unfortunately, when I call Add function, it’s throwing error immediately.

Maybe TMap seems not to add TDoubleLinkedList.
I couldn’t attempt to access double linked list, because I couldn’t have put it in TMap.

I can’t understand why TArray can but TDoubleLinkedList not.

Thanks for the reply :smiling_face_with_tear:

1 Like

I found solution through https://forums.unrealengine.com/t/note-see-reference-to-class-template-instantiation-tarray-being-compiled/349351/2.

Solution :

TMap<int32, TDoubleLinkedList<int32>*> newMap;

newMap.Add(1, new TDoubleLinkedList<int32>());

I think also that wrapping TDoubleLinkedList by smart pointer is possible.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.