muqsitnawaz / sfy

Post modern c++ library for string-fying objects

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sfy (pronounced es-phi)

sfy is a thin wrapper library (currently in beta) built on top of fmtlib library which allows you to stringi-fy objects for inspection or debugging purposes. sfy implements sfy::to_string's overloads for several built-in standard library types and performs resolution using C++20's concepts (so you pay no-runtime overhead of plain-old templates and get better error diagnostics).

Features

sfy::to_string works with:

  • Fundamental types e.g int, long, double etc
  • Standard container types std::vector, std::map etc
  • Custom containers types implementing standard interfaces
  • Old c-style arrays or strings e.g int[N], char[]
  • Data types such as std::pair, std::tuple etc
  • Numeric types such as std::ratio and std::complex
  • Nested types e.g std::pair<std::vector, std::unordered_set>

Upcoming

  • Support for working with C++20's ranges

Examples

std::complex<double> complex(1.0, 2.0);
sfy::to_string(complex);                  // outputs "1.0 + 2.0i";
auto pair = std::make_pair(5, 10);
auto tuple = std::make_tuple(1, 'a', "Hello world");
sfy::to_string(pair);                   // outputs "(5, 10)";
sfy::to_string(tuple);                  // outputs "(1, 'a', "Hello world")";
std::tuple<int, std::string, char> tuples[] = { {1, "hello", 'h'}, {2, "world", 'w'} };
sfy::to_string(tuples);                 // outputs "[(1, "hello", 'h'), (2, "world", 'w')]"
std::chrono::milliseconds dur(500);
sfy::to_string(dur);                    // outputs "500ms"
std::map<char, int> map = { {'a', 97}, {'b', 98} };
sfy::to_string(map);                    // outputs "{'a': 97, 'b': 98}");

Usage

  • Copy contents of ./include/ directory to your project's include directory path
  • All functions are implemented in a single header file so you can do #include <sfy/sfy.hppp>

Disclaimer

  • Currently tested on Clang v10.0.0 only
  • Project is in early beta stage so there could be bugs
  • Recommendations, bug-fixes and PRs are welcome!

About

Post modern c++ library for string-fying objects

License:MIT License


Languages

Language:C++ 99.7%Language:CMake 0.3%