0

I'm reading source codes in spdlog(https://github.com/gabime/spdlog).

There are some codes like

using default_factory = synchronous_factory;
template<typename Sink, typename... SinkArgs>
inline std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&... sink_args)
{
    return default_factory::create<Sink>(std::move(logger_name), std::forward<SinkArgs>(sink_args)...);
}

And It's prototype is like

struct synchronous_factory
{
    template<typename Sink, typename... SinkArgs>
    static std::shared_ptr<spdlog::logger> create(std::string logger_name, SinkArgs &&... args)
    {
        auto sink = std::make_shared<Sink>(std::forward<SinkArgs>(args)...);
        auto new_logger = std::make_shared<spdlog::logger>(std::move(logger_name), std::move(sink));
        details::registry::instance().initialize_logger(new_logger);
        return new_logger;
    }
};

And now my question is in the first parameter of create why using move to call string's move construct but not using refference with const string? Like

create(const std::string &logger_name ....)

cigien
  • 57,834
  • 11
  • 73
  • 112
f1msch
  • 509
  • 2
  • 12
  • 2
    Please use the [c++] tag for questions. If your question is really about a specific language revision, then you can *additionally* add the revision specific tag. Also, it looks like you're going through a code base, and planning on asking questions each time you encounter something you don't understand https://stackoverflow.com/q/76099446/ This isn't necessarily a problem, so long as the questions are clear, narrowly scoped etc, but I would note that this is quite an inefficient way of learning how a code base (or the language) works. – cigien Apr 25 '23 at 09:28

0 Answers0