dimanche 27 novembre 2022

Is abseil strcat overload useless?

In Abseil StrCat, it has a few of overload functions like

ABSL_MUST_USE_RESULT inline std::string StrCat() { return std::string(); }

ABSL_MUST_USE_RESULT inline std::string StrCat(const AlphaNum& a) {
  return std::string(a.data(), a.size());
}

ABSL_MUST_USE_RESULT std::string StrCat(const AlphaNum& a, const AlphaNum& b);
ABSL_MUST_USE_RESULT std::string StrCat(const AlphaNum& a, const AlphaNum& b,
                                        const AlphaNum& c);
ABSL_MUST_USE_RESULT std::string StrCat(const AlphaNum& a, const AlphaNum& b,
                                        const AlphaNum& c, const AlphaNum& d);

// Support 5 or more arguments
template <typename... AV>
ABSL_MUST_USE_RESULT inline std::string StrCat(
    const AlphaNum& a, const AlphaNum& b, const AlphaNum& c, const AlphaNum& d,
    const AlphaNum& e, const AV&... args) {
  return strings_internal::CatPieces(
      {a.Piece(), b.Piece(), c.Piece(), d.Piece(), e.Piece(),
       static_cast<const AlphaNum&>(args).Piece()...});
}

The CatPieces which supports multiple parameters by using initializer_list. These functions' implementation all similar. I can't see any optimisation happening for particular overload. Why not just provide one variadic parameter function to cover all?

Thanks

Aucun commentaire:

Enregistrer un commentaire