2

As the title says, TBitArray<> does not have an exact type, so does it mean that this method can accept any such as TBitArray<int32>, TBitArray<float>, ... as parameters?

FORCEINLINE bool HasAll(const TBitArray<>& Other) const
{
    FConstWordIterator ThisIterator(*this);
    FConstWordIterator OtherIterator(Other);

    while (ThisIterator || OtherIterator)
    {
        const uint32 A = ThisIterator ? ThisIterator.GetWord() : 0;
        const uint32 B = OtherIterator ? OtherIterator.GetWord() : 0;
        if ((A & B) != B)
        {
            return false;
        }

        ++ThisIterator;
        ++OtherIterator;
    }

    return true;
}

And what difference with this code

template<class T>
FORCEINLINE bool HasAll(const TBitArray<T>& Other) const
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Marsir
  • 105
  • 1
  • 2
  • 8

2 Answers2

5

TBitArray<> is a template class with all default template parameters. If it's TBitArray<int32> or TBitArray<float> depends on the template definition.

Here is its definition:

template<typename Allocator = FDefaultBitArrayAllocator>
class TBitArray;

So, it's neither int32 nor float, it's the default array allocator.

273K
  • 29,503
  • 10
  • 41
  • 64
  • If the template parameter expects an allocator, then how would types like `TBitArray` and `TBitArray` even work in the first place? – Remy Lebeau Mar 31 '23 at 02:57
  • 3
    @RemyLebeau They cannot work, they are OP assumptions, but not valid. – 273K Mar 31 '23 at 02:58
  • OK, so now I see from [Unreal's documentation](https://docs.unrealengine.com/5.1/en-US/API/Runtime/Core/Containers/TBitArray/) that `TBitArray` is just a dynamic array of bits, and you can't instantiate a type like `TBitArray` or `TBitArray` in the first place. Got it, thanks – Remy Lebeau Mar 31 '23 at 03:00
2

so does it mean that this method can accept any such as TBitArray<int32>, TBitArray<float>, ... as parameters?

No.

From the definition of the TBitArray class:

template<typename Allocator = FDefaultBitArrayAllocator>
class TBitArray;

You can see that its template argument takes an Allocator type, and defaults to FDefaultBitArrayAllocator. So, TBitArray<> is just shorthand for TBitArray<FDefaultBitArrayAllocator>.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770