Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct badType;
- template <typename TType = badType>
- struct type_decl {
- static constexpr const char * format_string() {
- return (std::is_integral_v<TType>
- ? "%d"
- : (std::is_floating_point_v<TType>
- ? "%f"
- : (std::is_pointer_v<TType>
- ? "%X"
- : "")
- )
- );
- }
- };
- template <>
- struct type_decl<const char *> {
- static constexpr const char * format_string() {
- return "%s";
- }
- };
- template <typename TType>
- constexpr const char * get_fmt_string(TType value) {
- return type_decl<TType>::format_string();
- };
- template <typename ...TArgs>
- void brain_fuck(TArgs ...args) {
- using unpacker_t = int[];
- string_buf<4096> buffer;
- int num_args = 0;
- (void)unpacker_t
- {
- (
- args,
- buffer.append(" arg[%d] : ", num_args++),
- buffer.append("%s : ", typeid(args).name()),
- buffer.append("%X : '", sizeof(args)),
- buffer.append(get_fmt_string(args), args),
- buffer.append("'\n"),
- 0)...,
- };
- debugf("**** %d args ****\n", num_args);
- debugf(buffer);
- }
- brain_fuck("oh", "my", "god", 2.0f, 1, true);
- /*
- Output:
- **** 6 args ****
- arg[0] : char const * : 4 : 'oh'
- arg[1] : char const * : 4 : 'my'
- arg[2] : char const * : 4 : 'god'
- arg[3] : float : 4 : '2.000000'
- arg[4] : int : 4 : '1'
- arg[5] : bool : 1 : '1'
- */
Add Comment
Please, Sign In to add comment