LoginSignup
3
3

More than 5 years have passed since last update.

cpp_inspect - pretty printer for C++ STL containers

Last updated at Posted at 2014-12-03
cpp_libraries article
cpp_binarysearch http://qiita.com/cielavenir/items/852e2458cd327ca73613
cpp_inspect http://qiita.com/cielavenir/items/95615185b5ca47d9111d
cpp_range http://qiita.com/cielavenir/items/94c9abbb7767bd57607b
cpp_rational http://qiita.com/cielavenir/items/2171327462d2afd98b65

Download

What's this?

You can print the content of C++ STL container and use it as C++11 uniform initialization.

Example

#include "inspect.hpp"
int main(){
    std::map<std::pair<int,std::string>,std::vector<std::array<int,3>>> val=
    {
        {{1,"2"},{
            {{1,2,3}},
            {{4,5,6}},
        }},
        {{4,"5"},{
            {{4,5,6}},
            {{7,8,9}},
        }},
        {{7,"8"},{
            {{7,8,9}},
            {{1,2,3}},
        }},
    };
    std::cout<<val<<std::endl;
}

Note std::cout<<val<<std::endl is not usually possible, because ostream operator<<(std::map<T,S>&) is not defined.

When you execute this program, you can get:

{{{1,"2"},{{{1,2,3,}},{{4,5,6,}},}},{{4,"5"},{{{4,5,6,}},{{7,8,9,}},}},{{7,"8"},{{{7,8,9,}},{{1,2,3,}},}},}

which you can confirm to be the same as the original declaration.

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3