hebaishi / easy-cpp-print

C++11 header file that allows printing of STL containers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

easyprint

Build Status

C++11 header to print STL containers. All containers that contain a const_iterator are supported, as well as std::tuple. Simply include the header file, and use the stringify function to stringify your containers. A print function has also been provided for convenience, which prints to standard output.

CMake is required to compile the supplied test code.

Linux Compilation:

mkdir bin && cd bin && cmake .. && make && ./easyprint_demo

Windows Compilation

Use CMake-GUI to compile on windows using your compiler of choice.

Usage:

Simply include the header file easyprint.hpp and use the implemented print function to print your containers. All containers that contain a const_iterator are supported. std::tuple is also supported.

Arbitrary nested containers are also supported, with the exception of tuples of non-trivial types. Nested tuples are allowed, however.

Function signatures:

namespace easyprint {

// Stringify any container
template <typename T> void stringify(const T &container);

// Print container to stdout
std::string print(const T &container);

}  // namespace easyprint

Example:

#include <iostream>
#include <vector>

#include <easyprint.hpp>

using easyprint::stringify;

int main(int argc, char const *argv[]) {
    std::vector <int> int_vec = {1,3,5};
    std::cout << "My int vector is = " << stringify(int_vec) << std::endl;
    return 0;
}

Output:

My int vector is = {1, 3, 5}

About

C++11 header file that allows printing of STL containers


Languages

Language:C++ 99.9%Language:CMake 0.1%