louisdx / cxx-prettyprint

A header-only library for C++(0x) that allows automagic pretty-printing of any container.
http://louisdx.github.com/cxx-prettyprint/
Boost Software License 1.0
557 stars 73 forks source link

prettyprint98.hpp is not compatible with C++11. #5

Closed Mizuchi closed 10 years ago

Mizuchi commented 12 years ago

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;
louisdx commented 11 years ago

prettyprint98.hpp is not intended for use with C++11. For C++11, use prettyprint.hpp. I don't plan on putting too much effort in maintaining prettyprint98.hpp, by the way.

lmachucab commented 11 years ago

When using the 098 header and my C++ backports library that offers std::begin() and std::end(), I get ambiguous calls as well. This is easily solvable adding the above patch but since you say you might not be maintaining the '98 version anymore, I've started a fork that uses my library's backports (the above functions and enable_if, mostly) and should be able to provide C++11/C++1y and C++03 compatibility in a single header. Will ping you for interest when I'm done testing.

jevinskie commented 10 years ago

Could prettyprint have a wrapper header that uses a preprocessor definition to detect the C++ version and include the appropriate header?

http://sourceforge.net/p/predef/wiki/Standards/

lmachucab commented 10 years ago

I've created a fork that reunites the C++03 and C++11 featureset in a single interface, and will probably add some minor goodies such as the option of distinguishing output for dictionary-like containers. It delegates special casing things like arrays and valarray (that lacks iterators interface in C++03) to my personal C++ backports library.

louisdx commented 10 years ago

Closing this for now unless you have a specific suggestion.