В моем заголовочном файле у меня есть это:
std::string StringExtend(const std::string Source, const unsigned int Length, const bool Reverse);
std::string StringExtend(const std::string Source, const unsigned int Length);
В моем файле cpp у меня есть это:
std::string Cranberry::StringExtend(const std::string Source, const unsigned int Length, const bool Reverse)
{
unsigned int StartIndex = (Source.length() - 1) * Reverse;
short int Increment = 1 - (Reverse * 2);
int Index = StartIndex;
std::string Result;
while (Result.length() < Length)
{
if (Reverse) Result = Source.at(Index) + Result;
else Result += Source.at(Index);
Index += Increment;
if (!InRange(Index, 0, Source.length() - 1)) Index = StartIndex;
}
return Result;
}
std::string Cranberry::StringExtend(const std::string Source, const unsigned int Length)
{
return StringExtend(Source, Length, false);
}
Как вы можете видеть, вторая форма функцииэто то же самое с опущенным аргументом Reverse
.Есть ли способ сократить это, или мне нужно иметь прототип функции и определение для каждой формы?