cxx-prettyprint =============== A pretty printing library for C++ containers. Synopsis: Simply by including this header-only library in your source file, you can say "std::cout << x" for any container object x. Sensible defaults are provided, but the behaviour (i.e. the delimiters) are compile-time customizable to a great extent via partial specializiation. Usage: Just add "#include "prettyprint.hpp" to your source file and make sure that prettyprint.hpp is findable. Language requirements: C++0x for prettyprint.hpp, C++98/03 for prettyprint98.hpp Example: Some usage examples are provided by ppdemo.cpp. Using GCC, compile with g++ -W -Wall -pedantic -O2 -s ppdemo.cpp -o ppdemo -std=c++0x g++ -W -Wall -pedantic -O2 -s ppdemo98.cpp -o ppdemo98 For the C++98/03-version, define "NO_TR1" to prevent any inclusion of TR1 headers and to disable std::tr1::tuple support. For details, please see the website (http://louisdx.github.com/cxx-prettyprint/). License: Boost Software License, Version 1.0. See http://www.boost.org/LICENSE_1_0.txt.
A header-only library for C++(0x) that allows automagic pretty-printing of any container.
Overview
Comments
-
License
I'm looking to use this library in a GPLv3+ project, but I can't find a license on this code. Would it be possible that you make explicit the license it is under (or point me to where this is done)?
It would be better to select an existing license, like CC0 for the closest one can legally get to releasing into public domain in many jurisdictions, zlib license for a permissive Free/Open Source license, or GNU GPLv3 for a strong copyleft Free/Open Source license. This is preferable to a statement such as "You can use this however you want" -- that statement is ambiguous in to whom the license refers, so it might actually not be a Free/Open Source license!
-
prettyprint98.hpp is not compatible with C++11.
Use clang++ or g++ with
-std=c++11
get an error::/tmp/prettyprint.hpp:207:17: error: call to 'begin' is ambiguous if (begin(_container) != end(_container)) ^~~~~
Here is a simple patch to fix this:
--- prettyprint_old.hpp 2012-07-13 10:37:02.521452515 +0800 +++ prettyprint.hpp 2012-07-13 10:39:05.604789149 +0800 @@ -204,8 +204,9 @@ if (delimiters_type::values.prefix != NULL) stream << delimiters_type::values.prefix; - if (begin(_container) != end(_container)) - for (TIter it = begin(_container), it_end = end(_container); ; ) + if (::pretty_print::begin(_container) != ::pretty_print::end(_container)) + for (TIter it = ::pretty_print::begin(_container), + it_end = ::pretty_print::end(_container); ; ) { stream << *it;
-
GCC with -Wshadow generates warnings
prettyprint98.hpp
generates this with GCC 4.7 and-Wshadow
:prettyprint98.hpp: In constructor 'pretty_print::custom_delims_wrapper<T, Delims>::custom_delims_wrapper(const T&)': prettyprint98.hpp:241:44: warning: declaration of 't' shadows a member of 'this' [-Wshadow] prettyprint98.hpp: In member function 'std::ostream& pretty_print::custom_delims_wrapper<T, Delims>::stream(std::ostream&)': prettyprint98.hpp:244:9: warning: declaration of 'stream' shadows a member of 'this' [-Wshadow] prettyprint98.hpp: In member function 'std::wostream& pretty_print::custom_delims_wrapper<T, Delims>::stream(std::wostream&)': prettyprint98.hpp:248:9: warning: declaration of 'stream' shadows a member of 'this' [-Wshadow]
As
-Wshadow
is a very useful warning and I would like my programs to be warning-free, I kindly ask to fix this :-) -
Custom delimiters with tuples
Apparently, it is not possible to define custom delimiters for tuples.
#include <iostream> #include <tuple> #include <prettyprint/prettyprint.hpp> struct delims { static const pretty_print::delimiters_values<char> values;}; const pretty_print::delimiters_values<char> delims::values = {"<", "," ">"}; int main() { auto t = std::make_tuple(12.5, 4, "hello"); std::cout << pretty_print::custom_delims<delims>(t) << std::endl; }
Compiled with:
clang++ -std=c++11 -stdlib=libc++ pretty.cpp -o pretty
compiler:
$ clang --version Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn) Target: x86_64-apple-darwin13.1.0 Thread model: posix
Error:
/usr/local/include/prettyprint/prettyprint.hpp:205:27: error: no matching function for call to 'begin'
Thanks, Ilio.
-
Standard C++ violation?
Having a look to your code I see you add to namaspace std the following: inline basic_ostream<TChar, TCharTraits> & operator<<(basic_ostream<TChar, TCharTraits> & stream, const tuple<TUPLE_ARGS> & value)
Is this legal c++? because of: [C++11: 17.6.4.2.1/1]: The behavior of a C++ program is undefined if it adds declarations or definitions to namespace std or to a namespace within namespace std unless otherwise specified. A program may add a template specialization for any standard library template to namespace std only if the declaration depends on a user-defined type and the specialization meets the standard library requirements for the original template and is not explicitly prohibited.
this is not legal. I'm missing something? Anyway, thank a lot for this nice piece of code.
-
Print strings in quotes (optional feature)
- Added function need_qoute, that returns true if it's argument is a string (this behavior can be turned off by #define DONT_QUOTE_STRINGS before including this file).
- Changed output for containers, pairs and tupels. Now they call need_qoute and add quotes if need
-
prints std::wstring to std::cout as an array of short
This code:
#include <iostream> #include <prettyprint.hpp> int main() { std::wstring ws = L"Hi"; std::cout << "ws = " << ws << std::endl; }
prints:
ws = [72, 105]
instead of producing compiler error (as it do without second include)
-
Error: invalid operands to binary expression ('ostream_type' <...> and 'const value_type')
I am attempting to build this with
Apple LLVM version 4.2 (clang-425.0.24) (based on LLVM 3.2svn) Target: x86_64-apple-darwin12.4.0 Thread model: posix
The incantation is
clang++ -g -O3 -std=c++0x -stdlib=libc++ <...>
(use of
-O2
or-O0
did not alleviate the problem) -
GCC 4.7: error: 'valarray' is not a member of 'std'
With GCC 4.7.2 (flags:
-Wall -Wextra -pedantic -std=c++11 -O2
) and the latestprettyprint.hpp
I getprettyprint.hpp:89:48: error: 'valarray' is not a member of 'std' prettyprint.hpp:89:48: error: 'valarray' is not a member of 'std' prettyprint.hpp:89:64: error: template argument 1 is invalid prettyprint.hpp:89:65: error: expected unqualified-id before '>' token prettyprint.hpp:89:97: warning: extra ';' [-pedantic]
The header needs to
#include <valarray>
. -
prettyprint98.hpp: foward declaration of std names leads to undefined behaviour
The foward declaration of set and multiset in prettyprint98.hpp leads to undefined behaviour. See the following discussion: https://groups.google.com/forum/?fromgroups=#!topic/comp.lang.c++.moderated/XBKFjGNquDM
Please remove the forward declarations and just include
. I think the impact on compilation speed is negligible, too. (This is a real world issue since I can't compile prettyprint together with boost/archive due to that.)
-
can I delete some code?
I am a beginner in language and I found some problems Since we already have
https://github.com/louisdx/cxx-prettyprint/blob/master/prettyprint.hpp#L107
Can I delete this?
https://github.com/louisdx/cxx-prettyprint/blob/master/prettyprint.hpp#L160
Is it redundant?I have try and no error find.
-
Intel Compiler Error: invalid partial specialization
The following code fails to compile with the Intel Compiler
icc (ICC) 2021.1 Beta 20200827
: gcc and clang compile this code without problems.// ex.cpp #include<iostream> #include<vector> #include<utility> #include "prettyprint.hpp" int main() { std::vector<std::pair<int, std::vector<int>>> v; std::cout << v << std::endl; return 1; }
I ran the code using a docker container based on the official intel image intel/oneapi-hpckit. The following is the slightly cleaned-up output of
icc
including the setup of the docker container.> ls ex.cpp prettyprint.hpp > docker run --rm -it -v$(pwd):/src:ro intel/oneapi-hpckit # icc -I /src/ /src/ex.cpp /src/prettyprint.hpp(152): error: invalid partial specialization -- class "pretty_print::print_container_helper<T, TChar, TCharTraits, TDelimiters>::printer<std::pair<int, std::vector<int, std::allocator<int>>>> [with T=std::vector<int, std::allocator<int>>, TChar=char, TCharTraits=std::char_traits<char>, TDelimiters=pretty_print::delimiters<std::vector<int, std::allocator<int>>, char>]" is already fully specialized struct print_container_helper<T, TChar, TCharTraits, TDelimiters>::printer<std::pair<T1, T2>> { ^ detected during: instantiation of class "pretty_print::print_container_helper<T, TChar, TCharTraits, TDelimiters> [with T=std::vector<int, std::allocator<int>>, TChar=char, TCharTraits=std::char_traits<char>, TDelimiters=pretty_print::delimiters<std::vector<int, std::allocator<int>>, char>]" at line 475 instantiation of "std::enable_if<pretty_print::is_container<T>::value, std::basic_ostream<TChar, TCharTraits> &>::type std::operator<<(std::basic_ostream<TChar, TCharTraits> &, const T &) [with T=std::vector<int, std::allocator<int>>, TChar=char, TCharTraits=std::char_traits<char>]" at line 160 instantiation of "void pretty_print::print_container_helper<T, TChar, TCharTraits, TDelimiters>::printer<std::pair<T1, T2>>::print_body(const std::pair<T1, T2> &, pretty_print::print_container_helper<T, TChar, TCharTraits, TDelimiters>::printer<std::pair<T1, T2>>::ostream_type &) [with T=std::pair<int, std::vector<int, std::allocator<int>>>, TChar=char, TCharTraits=std::char_traits<char>, TDelimiters=pretty_print::delimiters<std::pair<int, std::vector<int, std::allocator<int>>>, char>, T1=int, T2=std::vector<int, std::allocator<int>>]" at line 138 instantiation of "void pretty_print::print_container_helper<T, TChar, TCharTraits, TDelimiters>::operator()(pretty_print::print_container_helper<T, TChar, TCharTraits, TDelimiters>::ostream_type &) const [with T=std::pair<int, std::vector<int, std::allocator<int>>>, TChar=char, TCharTraits=std::char_traits<char>, TDelimiters=pretty_print::delimiters<std::pair<int, std::vector<int, std::allocator<int>>>, char>]" at line 211 instantiation of "std::basic_ostream<TChar, TCharTraits> &pretty_print::operator<<(std::basic_ostream<TChar, TCharTraits> &, const pretty_print::print_container_helper<T, TChar, TCharTraits, TDelimiters> &) [with T=std::pair<int, std::vector<int, std::allocator<int>>>, TChar=char, TCharTraits=std::char_traits<char>, TDelimiters=pretty_print::delimiters<std::pair<int, std::vector<int, std::allocator<int>>>, char>]" at line 475 instantiation of "std::enable_if<pretty_print::is_container<T>::value, std::basic_ostream<TChar, TCharTraits> &>::type std::operator<<(std::basic_ostream<TChar, TCharTraits> &, const T &) [with T=std::pair<int, std::vector<int, std::allocator<int>>>, TChar=char, TCharTraits=std::char_traits<char>]" at line 116 instantiation of "void pretty_print::print_container_helper<T, TChar, TCharTraits, TDelimiters>::printer<U>::print_body(const U &, pretty_print::print_container_helper<T, TChar, TCharTraits, TDelimiters>::ostream_type &) [with T=std::vector<std::pair<int, std::vector<int, std::allocator<int>>>, std::allocator<std::pair<int, std::vector<int, std::allocator<int>>>>>, TChar=char, TCharTraits=std::char_traits<char>, TDelimiters=pretty_print::delimiters<std::vector<std::pair<int, std::vector<int, std::allocator<int>>>, std::allocator<std::pair<int, std::vector<int, std::allocator<int>>>>>, char>, U=std::vector<std::pair<int, std::vector<int, std::allocator<int>>>, std::allocator<std::pair<int, std::vector<int, std::allocator<int>>>>>]" at line 138 instantiation of "void pretty_print::print_container_helper<T, TChar, TCharTraits, TDelimiters>::operator()(pretty_print::print_container_helper<T, TChar, TCharTraits, TDelimiters>::ostream_type &) const [with T=std::vector<std::pair<int, std::vector<int, std::allocator<int>>>, std::allocator<std::pair<int, std::vector<int, std::allocator<int>>>>>, TChar=char, TCharTraits=std::char_traits<char>, TDelimiters=pretty_print::delimiters<std::vector<std::pair<int, std::vector<int, std::allocator<int>>>, std::allocator<std::pair<int, std::vector<int, std::allocator<int>>>>>, char>]" at line 211 instantiation of "std::basic_ostream<TChar, TCharTraits> &pretty_print::operator<<(std::basic_ostream<TChar, TCharTraits> &, const pretty_print::print_container_helper<T, TChar, TCharTraits, TDelimiters> &) [with T=std::vector<std::pair<int, std::vector<int, std::allocator<int>>>, std::allocator<std::pair<int, std::vector<int, std::allocator<int>>>>>, TChar=char, TCharTraits=std::char_traits<char>, TDelimiters=pretty_print::delimiters<std::vector<std::pair<int, std::vector<int, std::allocator<int>>>, std::allocator<std::pair<int, std::vector<int, std::allocator<int>>>>>, char>]" at line 475 instantiation of "std::enable_if<pretty_print::is_container<T>::value, std::basic_ostream<TChar, TCharTraits> &>::type std::operator<<(std::basic_ostream<TChar, TCharTraits> &, const T &) [with T=std::vector<std::pair<int, std::vector<int, std::allocator<int>>>, std::allocator<std::pair<int, std::vector<int, std::allocator<int>>>>>, TChar=char, TCharTraits=std::char_traits<char>]" at line 9 of "/src/ex.cpp" compilation aborted for /src/ex.cpp (code 2)
-
Internal compiler error with MSVC (VS Community 2017, ver. 15.9.14)
I was trying to compile
ppdemo.cpp
with the latest version of VS 2017 (ver. 15.9.14), and got the following internal compiler error:D:\Work_OSS\cxx-prettyprint>cl /EHsc ppdemo.cpp Microsoft (R) C/C++ Optimizing Compiler Version 19.16.27032.1 for x64 Copyright (C) Microsoft Corporation. All rights reserved. ppdemo.cpp d:\work_oss\cxx-prettyprint\prettyprint.hpp(62): fatal error C1001: An internal error has occurred in the compiler. (compiler file 'd:\agent\_work\2\s\src\vctools\compiler\cxxfe\sl\p1\c\types.c', line 4563) To work around this problem, try simplifying or changing the program near the locations listed above. Please choose the Technical Support command on the Visual C++ Help menu, or open the Technical Support help file for more information d:\work_oss\cxx-prettyprint\prettyprint.hpp(69): note: see reference to class template instantiation 'pretty_print::detail::has_begin_end<T>' being compiled
-
Accept iterators with a non-void value_type
This PR changes
has_const_iterator
to additionally check- for
std::iterator_traits
to exist and - for its
return_type
to be non-void
.
This catches additional cases and is compatible with the iterator rules up to C++20.
Motivation for this change is the incompatibility with the new iterator interface of Eigen3, which sets
const_iterator = void
for non-vector types. This breaksprettyprint
. - for
-
Support std::optional
This adds support for std::optional. It uses a feature-test macro to determine whether the compiler supports that. I added a fourth delimiter type in order to print "nullopt" when the optional is empty.
Loads a signed kernel driver which allows you to map any driver to kernel mode without any traces of the signed / mapped driver.
CosMapper Loads a signed kernel driver (signed with leaked cert) which allows you to map any driver to kernel mode without any traces of the signed /
Flat map - Header only associative linear container.
flat_map flat_map is a header only associative container library that constructed on linear container. It compliants C++17/20 standard associative con
PRINT++ is a simple, open source print library for C++, the main usage of PRINT++ is printing out "log" messages
note that for now, print++ is using std::cout. In future it will be using own print function. Windows version can be unstable That library is in alpha
Pattern Printing For beginners!
Patterns Project on Patterns Installation Download the source files and compile it. Linux g++ main.cpp -o patterns.out ./patterns.out Windows g++ mai
Upgraded from Pixar postcard path tracing, instead of printing Pixar, this program print my name, which pose to be more challenging than the original code. The upgraded is also more readable and run 9x faster than the original source code.
SDF-Sphere-Tracing Upgraded from Pixar postcard path tracing, instead of printing Pixar, this program print my name, which pose to be more challenging
Creates 3D lithophanes from image files, exports them to stl files, ready for slicing and 3D printing.
LithoMaker Creates 3D lithophanes from PNG image files and exports them to STL files, ready for slicing and 3D printing. Download the latest release h
MKS TinyBee is a mainboard for 3d printing, based on ESP32 module
MKS-TinyBee MKS TinyBee is a mainboard for 3d printing, based on ESP32 module. Support Marlin2.0 firmware, in addition to ordinary LCD2004, 12864 scre
Converter for X3's .bod files to OBJs for 3D printing
Quick and dirty tool to convert X3 .bod files to OBJ for 3D printing. No, really, it is probably the worst code I've ever written. Don't judge me on t
Pretty Printer for Modern C++
Highlights Single header file Requires C++17 MIT License Quick Start Simply include pprint.hpp and you're good to go. #include <pprint.hpp> To start p
Localify "ウマ娘: Pretty Derby" DMM client
中文 赛马娘 (DMM版) 本地化补丁 使用方法: 将 version.dll 和 config.json 以及 config.json 中引用的字典放置于 umamusume.exe 边上 启动游戏 设置选项: enableConsole 启用用来输出调试信息的控制台 (true/false) e
Juice the carrots from ウマ娘プリティーダービー (Umamusume Pretty Derby) - Windows implementation
Hooks the decryption function in libnative.dll of ウマ娘プリティーダービー (Umamusume Pretty Derby), to allow inspecting the packets (and provide some useful information during the game).
Pretty much the repo name sums it up.
?? Console_Calculator Version Supported Date Ended Support v.1.0 ✔️ ?? Features The ?? Console_Calculator can do basic arithmatic, and yes there is no
its a pretty dodo 0.1% os
Dodo OS why did i make this os? idk im bored and i wanted to learn alot of new stuff. so i decided to make dodo os. i will see for how far i will go i
Embed read-only filesystems into any C++11 program w. a single header, zero dependencies and zero modifications to your code
c-embed Embed read-only filesystems into any C++11 program w. a single header, zero dependencies and zero modifications to your code. Usage c-embed al
Allows you to easily control via MQTT any Micronova equiped pellet stove. (MCZ, Extraflame, Laminox, and many others brands!)
micronova_controller Kits are available on Tindie! Currently out of stock. V2 will be in stock soon! Here is an overview of the additions: possibility
Static reflection for enums (to string, from string, iteration) for modern C++, work with any enum type without any macro or boilerplate code
__ __ _ ______ _____ | \/ | (_) | ____| / ____|_ _ | \ / |
Automatically load dlls into any executables without replacing any files!
Automatically loaded dll using xinput9_1_0 proxy. Please put the modified xinput9_1_0.dll in the executable's directory.
Create a calculator of any kind in any language, create a pr.
calculators Create a calculator of any kind in any language, create a pr. Create a calculator of any type using the programming language of your choic
A sketch that not only parses NMEA sentences, but also allows sending UBX commands and decrypt answers from the ublox module
RAK4631-ublox-Commander This is a tokenizer and parser for raw NMEA sentences. This is not intended (yet anyway) for production, but as an exercice in