diff --git a/research/try.cpp b/research/try.cpp index b8540359e..3fd2439b2 100644 --- a/research/try.cpp +++ b/research/try.cpp @@ -79,22 +79,17 @@ typedef unsigned int uint; #include #include -using lib::diff::GenNode; using lib::P; -using lib::meta::enable_if; -using lib::meta::typeStr; +using lib::diff::GenNode; using lib::meta::is_basically; +using lib::meta::is_StringLike; using lib::meta::can_lexical2string; using lib::meta::can_convertToString; using lib::meta::use_StringConversion4Stream; using lib::meta::CustomStringConv; using lib::meta::Strip; -using std::__and_; -using std::__not_; using std::string; -using std::cout; -using std::endl; @@ -102,30 +97,6 @@ using std::endl; -///////////////////////////////shall go into the implementation of lib::P -template -inline string -stringz (P ptr) -{ - if (not ptr) - return "⟂ P<"+typeStr(ptr.get())+">"; - else - return CustomStringConv::invoke (*ptr); -} - - -namespace std { - - template - std::ostream& - operator<< (std::ostream& os, P const& ptr) - { - return os << stringz (ptr); - } -} - - - class Reticent { uint neigh_ = 42; @@ -144,7 +115,7 @@ newP (ARGS&&... ctorArgs) template using BasicallyString = is_basically; template -using BasicallyChar = is_basically::type, char>; +using BasicallyChar = std::is_convertible; void @@ -154,11 +125,12 @@ showTypes() #define SHOW_CHECK(_EXPR_) cout << STRINGIFY(_EXPR_) << "\t : " << (_EXPR_::value? "Yes":"No") << endl; #define ANALYSE(_TYPE_) \ cout << "Type: " STRINGIFY(_TYPE_) " ......"<); \ - SHOW_CHECK (BasicallyString<_TYPE_>); \ - SHOW_CHECK (std::is_arithmetic<_TYPE_>);\ - SHOW_CHECK (can_lexical2string<_TYPE_>); \ - SHOW_CHECK (can_convertToString<_TYPE_>); \ + SHOW_CHECK (is_StringLike<_TYPE_>); \ + SHOW_CHECK (BasicallyChar<_TYPE_>); \ + SHOW_CHECK (BasicallyString<_TYPE_>); \ + SHOW_CHECK (std::is_arithmetic<_TYPE_>); \ + SHOW_CHECK (can_lexical2string<_TYPE_>); \ + SHOW_CHECK (can_convertToString<_TYPE_>); \ SHOW_CHECK (use_StringConversion4Stream<_TYPE_>); diff --git a/src/lib/p.hpp b/src/lib/p.hpp index d88a51717..01d5c69c6 100644 --- a/src/lib/p.hpp +++ b/src/lib/p.hpp @@ -51,6 +51,8 @@ #include "lib/error.hpp" +#include "lib/meta/util.hpp" + #include @@ -98,6 +100,8 @@ namespace lib { void swap(P& b) { BASE::swap (b);} + operator std::string() const noexcept; + private: /* === friend operators injected into enclosing namespace for ADL === */ //////////////////TICKET #932 Clang is unable to fill in the default template argument. Resolved in newer versions of Clang. Temporary workaround: add second parameter B @@ -128,5 +132,24 @@ namespace lib { }; + + /** + * use custom string conversion on pointee, if applicable, + * otherwise fall back to a human readable type string.S + */ + template + inline + P::operator std::string() const noexcept + try { + if (this->get()) + return meta::CustomStringConv::invoke (this->operator*()); + else + return "⟂ P<"+meta::typeStr(this->get())+">"; + } + catch(...) + { return "↯"; } + + + } // namespace lib #endif