Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1001\1002template<TINYFORMAT_ARGTYPES(n)> \1003void init(int i, TINYFORMAT_VARARGS(n)) \1004{ \1005m_formatterStore[i] = FormatArg(v1); \1006init(i+1 TINYFORMAT_PASSARGS_TAIL(n)); \1007}1009TINYFORMAT_FOREACH_ARGNUM(TINYFORMAT_MAKE_FORMATLIST_CONSTRUCTOR)1010# undef TINYFORMAT_MAKE_FORMATLIST_CONSTRUCTOR1011#endif1012FormatListN(const FormatListN& other)1013: FormatList(&m_formatterStore[0], N)1014{ std::copy(&other.m_formatterStore[0], &other.m_formatterStore[N],1015&m_formatterStore[0]); }1017private:1018FormatArg m_formatterStore[N];1019};1021// Special 0-arg version - MSVC says zero-sized C array in struct is nonstandard1022template<> class FormatListN<0> : public FormatList1023{1024public:1025FormatListN() : FormatList(nullptr, 0) {}1026};1028} // namespace detail1031//------------------------------------------------------------------------------1032// Primary API functions1034#ifdef TINYFORMAT_USE_VARIADIC_TEMPLATES1036/// Make type-agnostic format list from list of template arguments.1037///1038/// The exact return type of this function is an implementation detail and1039/// shouldn't be relied upon. Instead it should be stored as a FormatListRef:1040///1041/// FormatListRef formatList = makeFormatList( /*...*/ );1042template<typename... Args>1043detail::FormatListN<sizeof...(Args)> makeFormatList(const Args&... args)1044{1045return detail::FormatListN<sizeof...(args)>(args...);1046}1048#else // C++98 version1050inline detail::FormatListN<0> makeFormatList()1051{1052return detail::FormatListN<0>();1053}1054#define TINYFORMAT_MAKE_MAKEFORMATLIST(n) \1055template<TINYFORMAT_ARGTYPES(n)> \1056detail::FormatListN<n> makeFormatList(TINYFORMAT_VARARGS(n)) \1057{ \1058return detail::FormatListN<n>(TINYFORMAT_PASSARGS(n)); \1059}1060TINYFORMAT_FOREACH_ARGNUM(TINYFORMAT_MAKE_MAKEFORMATLIST)1061#undef TINYFORMAT_MAKE_MAKEFORMATLIST1063#endif1065/// Format list of arguments to the stream according to the given format string.1066///1067/// The name vformat() is chosen for the semantic similarity to vprintf(): the1068/// list of format arguments is held in a single function argument.1069inline void vformat(std::ostream& out, const char* fmt, FormatListRef list)1070{1071detail::formatImpl(out, fmt, list.m_args, list.m_N);1072}1075#ifdef TINYFORMAT_USE_VARIADIC_TEMPLATES1077/// Format list of arguments to the stream according to given format string.1078template<typename... Args>1079void format(std::ostream& out, FormatStringCheck<sizeof...(Args)> fmt, const Args&... args)1080{1081vformat(out, fmt, makeFormatList(args...));1082}1084/// Format list of arguments according to the given format string and return1085/// the result as a string.1086template<typename... Args>1087std::string format(FormatStringCheck<sizeof...(Args)> fmt, const Args&... args)1088{1089std::ostringstream oss;1090format(oss, fmt, args...);1091return oss.str();1092}1094/// Format list of arguments to std::cout, according to the given format string1095template<typename... Args>1096void printf(FormatStringCheck<sizeof...(Args)> fmt, const Args&... args)1097{1098format(std::cout, fmt, args...);1099}1101template<typename... Args>1102void printfln(FormatStringCheck<sizeof...(Args)> fmt, const Args&... args)1103{1104format(std::cout, fmt, args...);1105std::cout << '\n';1106}1109#else // C++98 version1111inline void format(std::ostream& out, const char* fmt)1112{1113vformat(out, fmt, makeFormatList());1114}1116inline std::string format(const char* fmt)1117{1118std::ostringstream oss;1119format(oss, fmt);1120return oss.str();1121}1123inline void printf(const char* fmt)1124{1125format(std::cout, fmt);1126}1128inline void printfln(const char* fmt)1129{1130format(std::cout, fmt);1131std::cout << '\n';1132}1134#define TINYFORMAT_MAKE_FORMAT_FUNCS(n) \1135\1136template<TINYFORMAT_ARGTYPES(n)> \1137void format(std::ostream& out, const char* fmt, TINYFORMAT_VARARGS(n)) \1138{ \1139vformat(out, fmt, makeFormatList(TINYFORMAT_PASSARGS(n))); \1140} \1141\1142template<TINYFORMAT_ARGTYPES(n)> \1143std::string format(const char* fmt, TINYFORMAT_VARARGS(n)) \1144{ \1145std::ostringstream oss; \1146format(oss, fmt, TINYFORMAT_PASSARGS(n)); \1147return oss.str(); \1148} \1149\1150template<TINYFORMAT_ARGTYPES(n)> \1151void printf(const char* fmt, TINYFORMAT_VARARGS(n)) \1152{ \1153format(std::cout, fmt, TINYFORMAT_PASSARGS(n)); \1154} \1155\1156template<TINYFORMAT_ARGTYPES(n)> \1157void printfln(const char* fmt, TINYFORMAT_VARARGS(n)) \1158{ \1159format(std::cout, fmt, TINYFORMAT_PASSARGS(n)); \1160std::cout << '\n'; \1161}1163TINYFORMAT_FOREACH_ARGNUM(TINYFORMAT_MAKE_FORMAT_FUNCS)1164#undef TINYFORMAT_MAKE_FORMAT_FUNCS1166#endif1168} // namespace tinyformat1170// Added for Bitcoin Core:1171/** Format arguments and return the string or write to given std::ostream (see tinyformat::format doc for details) */1172#define strprintf tfm::format1174#endif // TINYFORMAT_H_INCLUDED
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.