/** * \file libipc/fmt_cpo.h * \author mutouyun (orz@orzz.org) * \brief String formatting CPO. */ #pragma once #include #include #include #include "libipc/imp/generic.h" #include "libipc/imp/detect_plat.h" #include "libipc/imp/span.h" #include "libipc/imp/export.h" namespace ipc { /** * \class class IPC_EXPORT fmt_context * \brief The context of fmt. */ class IPC_EXPORT fmt_context { std::array sbuf_; ///< stack buffer std::string &joined_; std::size_t offset_; public: fmt_context(std::string &j) noexcept; std::size_t capacity() noexcept; void reset() noexcept; bool finish() noexcept; span buffer(std::size_t sz) noexcept; void expend(std::size_t sz) noexcept; bool append(span const &str) noexcept; }; /// \brief Supports custom fmt_to methods for ipc::fmt. namespace detail_tag_invoke { class fmt_to_t { template bool get_result(fmt_context &ctx, A1 && a1) const { return ipc::tag_invoke(fmt_to_t{}, ctx, std::forward(a1)); } template bool get_result(fmt_context &ctx, A1 && a1, A &&...args) const { return get_result(ctx, std::forward(a1)) && get_result(ctx, std::forward(args)...); } public: template bool operator()(fmt_context &ctx, A &&...args) const { return get_result(ctx, std::forward(args)...); } }; } // namespace detail_tag_invoke constexpr detail_tag_invoke::fmt_to_t fmt_to{}; } // namespace ipc