repr 0.1
Reconstructable string representations and more
|
librepr is a C++ static reflection and serialization library that provides a convenient way to generate string representations of C++ objects that can be used to reconstruct those objects. It is inspired by Python's repr
function and is primarily designed to assist developers in debugging and logging.
Navigate to your project directory in the terminal and run the following command to add repr as a submodule:
Note that the path external/repr
is chosen arbitrarily. You can add the submodule at any path you like.
You may need to adjust your include path. To do so add
to your CMakeLists.txt (replace your_target
with the name of your target).
Alternatively if you do not use CMake simply pass your compiler an additional -Iexternal/repr/include
(clang, gcc) or /Iexternal/repr/include
(msvc) argument.
You can download a single-header distribution of repr from the URL provided:
This command downloads the single-header file and saves it as repr.h
to the current working directory. You can place this file wherever convenient (ie external/repr.h
).
Compiler Explorer supports including headers from URLs directly, hence you can simply do
[!IMPORTANT] repr is not yet in Conan's package repository. The following will only work if you have the package installed locally.
You can include librepr in your C++ project using the Conan package manager:
Add librepr as a dependency in your conanfile.txt
:
Replace 0.1
with the desired version of librepr.
Install the dependencies using Conan:
In your CMakeLists.txt, link against librepr:
Include the repr
header in your C++ source files:
You now have added librepr as a dependency to your project using Conan.
The following example showcases usage of the repr
function (or well, function object to be pedantic), which generates a reconstructible string representation of the given object. Furthermore we'll use librepr::code_for
to also print the type.
librepr is provided under the [MIT License](LICENSE). Feel free to use and modify it in your projects.
If you'd like to contribute to librepr, please fork the repository, make your changes, and submit a pull request. We welcome any contributions, including bug fixes, new features, and improvements. Bug reports submitted as issues are also very welcome.
For questions or issues related to this library, please open an issue.