This is a library mainly meant to increase the efficiency of debugging C++ programs. Very handy when used for competetive programming.
The efficiency increase is possible thanks to the watch()
function introduced by this library.
It can print out the value of almost every variable, structure or expression, along with the context that it appears in (line number, variables name and type name).
The current version compiles only with the c++17 standard! (and probably higher standards when they come out)
- all numeric variables (
bool
,char
,short
,int
,long
,long long
,float
,double
,long double
) bothsigned
andunsigned
std::string
std::bitset
std::vector
,std::array
and arrays with defined dimensionsstd::stack
,std::queue
,std::deque
,std::priority_queue
std::list
std::pair
std::map
,std::multimap
,std::set
,std::multiset
- all pointers of any type that is supported
- all
const
variants of supported types - all arithmetic expressions of supported types
- binary trees
- probably more are supported but we haven't tested them (everything from STL)
- Adam Jeliński (charodziej)
- Kajetan Lewandowski (LegwanXDL)
- Clone this repository using
or by downloading it from here
git clone https://github.com/chariguanaCode/universal-print-in-cpp
- Make sure that everything works on your platform by compiling at least one of the examples in your programming environment
- If everything is working properly, include the
universal_print.h
library from thelib
folder in your project and copy the contents oftemplate.cpp
to the main file of that project (not necessary but recommended)
The full documentation describing all the functions can be found here
-
To enable the library, you only need to add
#define DEBUG 1
to the beginning of a project based on
template.cpp
. At this point your program should print a banner, informing you that you are in debug mode. -
To make use of the basic functionality you only need to call
watch(<variable_name>);
where
<variable_name>
is the name of your variable. -
If you do not fancy seeing the names of types you can disable them using
cupl::showTypes(false);
and re-enable them using
cupl::showTypes(true);
if that's what you need to do.
-
If your data type isn't supported you will need to implement an expansion to the library in your main cpp file.
You can do it as follows:
void print_process(<data_type> name){ <custom_printing_code> }
where
<data_type>
would be the your custom data type and<custom_printing_code>
would be your method of printing the variable.Each
endln
or\n
printed by your<custom_printing_code>
has to be followed by the variablecupl::indentation
to make everything look properly.Please notice that if your custom type contains other types that are supported by our library you can just call
cupl::print_process();
on those members of your type.Due to C++ limitations
struct
s aren't supported by default and eachstruct
has to have their members provided to cupl like so:struct my_struct{ type1 member1; type2 member2; <more_members> ... declare_struct(member1, member2, <more_members>...); }
You may want to check out this example to better understand how to implement this.
If you would like to change the colours of objects, change the precision std::cout
uses or binary trees look weird on your system, you should take a look at the beginning of the universal_print.h
file.
The "User setup" section will allow you to change all of those things easily.
- support for const
- examples
- screenshots
- printing binary trees nicely
- embracing new features of c++17
- printing other graphs nicely
If you encounter any issues or come up with nice improvements please report them on the Issue Tracker.
Merge requests are welcome too :).