Hi
i revised the whole BullCowCartridge to include FStringView which is similar to std::string_view which basically const TCHAR* to FString . It is a pointer to first character and has the size info . it is quite light weight but has negative side as lifetime issues;
Here is my BullCowCartridge.h with FStringView
class BULLCOWGAME_API UBullCowCartridge : public UCartridge
{
GENERATED_BODY()
public:
virtual void BeginPlay() override;
virtual void OnInput(const FString& Input) override;
//virtual void OnInput(FStringView Input) override;
void SetupGame();
void EndGame();
void ProcessGuess(FStringView Guess); // Guess=Input
void GetValidWords(TArray<FString>& wordlist);
bool IsIsogram(FStringView Guess) const;
private:
FString HiddenWord;
int32 Lives{0};
bool bGameOver{false};
TArray<FString>WordList;
};
I also made an alternative version with OnInput(); with FStringView
virtual void OnInput(FStringView Input) override;
but to do that i had to revise the base class Cartridge.h because OnInput() is a virtual function and made a copy of it with FStringView .
But i was not sure if it will be safe since it will be temporary value . Althoug OnInput() function runs over the lifetime of the game it should not be a problem as all other functions are called from here . Here is the Cartridge.h version with FStringView (both versions works with no problem)
class BULLCOWGAME_API UCartridge : public UActorComponent
{
GENERATED_BODY()
public:
virtual void OnInput(FStringView Input) PURE_VIRTUAL(UCartridge::OnInput, );
protected:
void BeginPlay() override;
void PrintLine(const FString& Line) const;
void PrintLine(const TCHAR* Line) const; // Avoid template for this case.
template<SIZE_T N, typename ...Types>
void PrintLine(const TCHAR (&Fmt)[N], Types... Args) const
{
PrintLine(FString::Printf(Fmt, Args...));
}
void ClearScreen() const;
private:
class UTerminal* Terminal;
};