Unable to use std::distance from the STL but unclear why ;;

Simply put, I’m trying to use std::distance to find the position of an iterator in an FString.

Here’s the code I’m trying to build (HiddenWord and Input are both FString types):
image

and I get the pre-compiler error:
no instance of function template “std::distance” matches the argument list – argument types are: (TCheckedPointerIterator<const TCHAR, int32>, TCheckedPointerIterator<const TCHAR, int32>)

I copied this snippet over to VS2019 just to see if it compiles without the context of UE4 and it’s completely fine, so this is definitely UE specific.

I also tried creating a vector and assigning the Input data which actually solved my problem, but I’d like to understand why this didn’t work in the first place.

Could someone help me in understanding why my FString variables work fine for some STL functions (find, for_each etc) but not for distance?

Because the algorithms depend on members being defined. In this case difference_type, which Unreal’s iterator doesn’t define. This is all of the members

private:
    ElementType*    Ptr;
    const SizeType& CurrentNum;
    SizeType        InitialNum;

Unreal has their own algorithms in Algo.

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

Privacy & Terms