MCPcopy Create free account
hub / github.com/c42f/tinyformat / FormatListN

Class FormatListN

tinyformat.h:959–994  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

957// Format list subclass with fixed storage to avoid dynamic allocation
958template<int N>
959class FormatListN : public FormatList
960{
961 public:
962#ifdef TINYFORMAT_USE_VARIADIC_TEMPLATES
963 template<typename... Args>
964 FormatListN(const Args&... args)
965 : FormatList(&m_formatterStore[0], N),
966 m_formatterStore { FormatArg(args)... }
967 { static_assert(sizeof...(args) == N, "Number of args must be N"); }
968#else // C++98 version
969 void init(int) {}
970# define TINYFORMAT_MAKE_FORMATLIST_CONSTRUCTOR(n) \
971 \
972 template<TINYFORMAT_ARGTYPES(n)> \
973 FormatListN(TINYFORMAT_VARARGS(n)) \
974 : FormatList(&m_formatterStore[0], n) \
975 { TINYFORMAT_ASSERT(n == N); init(0, TINYFORMAT_PASSARGS(n)); } \
976 \
977 template<TINYFORMAT_ARGTYPES(n)> \
978 void init(int i, TINYFORMAT_VARARGS(n)) \
979 { \
980 m_formatterStore[i] = FormatArg(v1); \
981 init(i+1 TINYFORMAT_PASSARGS_TAIL(n)); \
982 }
983
984 TINYFORMAT_FOREACH_ARGNUM(TINYFORMAT_MAKE_FORMATLIST_CONSTRUCTOR)
985# undef TINYFORMAT_MAKE_FORMATLIST_CONSTRUCTOR
986#endif
987 FormatListN(const FormatListN& other)
988 : FormatList(&m_formatterStore[0], N)
989 { std::copy(&other.m_formatterStore[0], &other.m_formatterStore[N],
990 &m_formatterStore[0]); }
991
992 private:
993 FormatArg m_formatterStore[N];
994};
995
996// Special 0-arg version - MSVC says zero-sized C array in struct is nonstandard
997template<> class FormatListN<0> : public FormatList

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected