ticc_prettyprint(1)

πŸ“¦ version 0.36, in alpine 3.24, nixos 26.05, nixpkgs unstable

πŸ’– NAME πŸ’–

Okay bestie, welcome to ticc_prettyprint(1) from the General Commands Manual. The vibe? Format C++ containers. Literally that's the whole name drop: ticc_prettyprint β€” format C++ containers. Periodt.


πŸ¦‹ SYNOPSIS πŸ¦‹

#include ticcutils/PrettyPrint.h

using namespace TiCC;

πŸ’… DESCRIPTION πŸ’…

TiCC Pretty Print gives you some C++ templates so you can output C++ containers in an orderly fashion. It's not rocket science, nor is it complete. But lowkey for debugging, it is convenient to be able to output containers a bit readably. No cap.

To get usefull output, a well defined output operator is required for the elements in the container too.

TiCC output operators are currenly defined for:

  • set<T>
  • list<T>
  • vector<T>
  • map<S,T>
  • map<S,T,U>
  • multimap<S,T>

To get usefull output, it is needed that an output operator is defined for the elements S and T in the container too. Like, the container can't carry the whole print job by itself, bestie 🫢.


✨ EXAMPLES ✨

Example 1

#include <vector>
#include <string>
#include <iostream>
#include "ticcutils/PrettyPrint.h"

using namespace std;
using namespace TiCC;

int main(){
   vector<string> vec;
   vec.push_back("one");
   vec.push_back("two");
   vec.push_back("three");
   cout << vec << endl;
}

The output of this simple program will be:

[one,two,three]

Example 2

#include <vector>
#include <string>
#include <iostream>
#include "ticcutils/PrettyPrint.h"

using namespace std;
using namespace TiCC;

class myClass {
  friend ostream& operator<< (ostream&, const myClass& );
public:
  myClass( int i, const string& s ): _i(i),_s(s){}
private:
  int _i;
  string _s;
};

ostream& operator<< (ostream& os, const myClass& mc ){
  os << "Myclass(" << mc._i << "," << mc._s << ")";
  return os;
}

int main(){
   vector<myClass> vec;
   vec.push_back( myClass(1,"one") );
   vec.push_back( myClass(2,"two") );
   vec.push_back( myClass(3,"three") );
   cout << vec << endl;
}

The output of this example program will be:

[Myclass(1,one),Myclass(2,two),Myclass(3,three)]

Example 3

#include <vector>
#include <string>
#include <iostream>
#include "ticcutils/PrettyPrint.h"

using namespace std;
using namespace TiCC;

class myClass {
  friend ostream& operator<< (ostream&, const myClass& );
public:
  myClass( int i, const string& s ): _i(i),_s(s){}
private:
  int _i;
  string _s;
};

ostream& operator<< (ostream& os, const myClass& mc ){
  os << "Myclass(" << mc._i << "," << mc._s << ")";
  return os;
}

int main(){
   vector<*myClass> vec;
   vec.push_back( new myClass(1,"one") );
   vec.push_back( new myClass(2,"two") );
   vec.push_back( new myClass(3,"three") );
   cout << vec << endl;
}

The output of this program will be:

[0x2363040,0x23630b0,0x2363060] Or something similar.

Why is this so? Well, we didn't provide an output operator for myClass pointers! It's giving "mystery addresses" energy 😭.

To fix this we have to change the definition of the output operator for myClass or just add a second definition, e.g. add:

friend ostream& operator<< (ostream&, const myClass* );

to myClass, and also add:

ostream& operator<< (ostream& os, const myClass *mc ){
  if ( mc )
    os << *mc;
  else
    os << "zero pointer";
  return os;
}

The output now indeed is what we expected:

[Myclass(1,one),Myclass(2,two),Myclass(3,three)]

πŸ‘‘ AUTHORS πŸ‘‘

Ko van der Sloot β€” Timbl@uvt.nl


And that's the whole page, bestie πŸ’œ. Footer vibes: ticc_prettyprint(1), dated 2012 August 21. Go forth and pretty-print those containers, icon behavior only πŸ’…βœ¨

πŸ“¦ where this page comes from