0

Note: pls don't be confused with other Stackoverflow questions that have the same title/errocode -- they are mostly due to missing #include <string> but it's not the issue here.

I'm reading Pretty-print C++ STL containers question and downloaed Kerrek's code from his GitHub Project cxx-prettyprint, when I try compile it (my environment is Windows 7, Visual Studio 2013, compiled project as a Console Application "Use Multi-Byte Character Set"), hit a template deduction error.

It's a bit weird as suggested by Mike Kinghan in the comment, it does compile compiles and runs fine with the current MSVC++ : see it online.

I'm confused, there must be something wrong with my configuration. I created a blank new Windows Console Application, and added Kerrek's code in, focus on a vector of string test cast, removed other scenarios such as set/map etc:

int main(int argc, char* argv[])
{ 
    std::vector<std::string> v;  

    v.push_back("hello, world"); 
    v.push_back("2nd line");
    v.push_back("last line");

    std::cout << v;
}

, now hit a error:

Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::vector>' (or there is no acceptable conversion)

If I explicitly call the pretty_print::operator <<,

pretty_print::operator<<(std::cout, v);

, hit another template deduction error:

Error 1 error C2784: 'std::basic_ostream<_Elem,_Traits> &pretty_print::operator <<(std::basic_ostream<_Elem,_Traits> &,const pretty_print::print_container_helper &)' : could not deduce template argument for 'const pretty_print::print_container_helper &' from 'std::vector>'

It only compiles if the print_container_helper is explictily created:

pretty_print::print_container_helper<std::vector<std::string>, char, ::std::char_traits<char>, pretty_print::delimiters<std::vector<std::string>, char>>
    vh(v);
pretty_print::operator<<(std::cout, vh);

The full code is here: http://rextester.com/RJX76690

Community
  • 1
  • 1
athos
  • 6,120
  • 5
  • 51
  • 95
  • The library as exercised by `ppdemo.cpp` compiles and runs fine with the current MSVC++, [See it live](http://rextester.com/JLBW44338). Your compiler is older but I suspect your problem lies in your own program, which you haven't posted. Please edit your post to include an [mcve]. – Mike Kinghan Dec 10 '16 at 17:00
  • @MikeKinghan I'm confused -- you code does not compile on my Visual Studio 2013! Now the error is in line ` std::cout << "Vector: " << v << std::endl // vector of strings`, error message: "Error 1 error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::vector>' (or there is no acceptable conversion) c:\playground\prettyprint\prettyprint\kerrek.cpp 522". what's your project setting? I created a new Console Application then compile with "Use Multi-Byte Character Set" – athos Dec 11 '16 at 01:37
  • Where is your [MCVE]? – Lightness Races in Orbit Dec 11 '16 at 02:53
  • @athos [The program that you says fails for you](http://rextester.com/RJX76690) when your `// option 1, original code` is compiled [works for me here](http://rextester.com/IUI77727). `// option 2` was never going to work, as there is no such function. I'm afraid I can't help you with this any further. – Mike Kinghan Dec 11 '16 at 09:24
  • @MikeKinghan I found the reason -- `decltype(static_cast(&C::begin))` compilation failure, so that the `has_begin_end` is not working. Seems this is a limitation of Visual Studio 2013, in VS2015 it's fine. – athos Dec 11 '16 at 14:18
  • @athos Well spotted :) Suggest you report your bug and fix on the GitHub repo. – Mike Kinghan Dec 11 '16 at 14:34
  • done. :) @MikeKinghan – athos Dec 12 '16 at 00:20

0 Answers0