Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not build on VC++ 2013 #18

Closed
mfeemster opened this issue Jun 19, 2015 · 0 comments · Fixed by #21
Closed

Does not build on VC++ 2013 #18

mfeemster opened this issue Jun 19, 2015 · 0 comments · Fixed by #21

Comments

@mfeemster
Copy link

I am running Visual Studio 2013 with update 4 installed. This code has multiple build issues.

  1. In the pair and tuple specializations for print_container_helper::printer, it chokes on this line:
using ostream_type = print_container_helper<T, TChar, TCharTraits, TDelimiters>::ostream_type;

I've fixed it locally with this:

#ifdef _MSC_VER
    using ostream_type = std::basic_ostream<TChar, TCharTraits>;
#else
    using ostream_type = print_container_helper<T, TChar, TCharTraits, TDelimiters>::ostream_type;
#endif

This isn't the greatest fix because it hardcodes it to basic_ostream, rather than referencing print_container_helper::ostream_type, but at least it works.

  1. Once that builds, the library is unusable since it now chokes on the main interface that a caller would use: the << operator.
template<typename T, typename TChar, typename TCharTraits>
inline typename enable_if<::pretty_print::is_container<T>::value,
       basic_ostream<TChar, TCharTraits> &>::type
       operator<<(basic_ostream<TChar, TCharTraits>& stream, const T& container)
{
    return stream << ::pretty_print::print_container_helper<T, TChar, TCharTraits>(container);
}

Cannot resolve to the proper type in your most basic example:

  std::vector<int> foo;
  foo.push_back(1);
  foo.push_back(2);
  foo.push_back(3);

  std::cout << "My vector: " << foo << std::endl;

VS says:

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

The user must specifically add each type they want the overloaded << operator to work with, such as:

template <typename T>
struct is_container<std::vector<T>> : std::true_type { };

template <typename T1, typename T2>
struct is_container<std::unordered_map<T1, T2>> : std::true_type { };

IMHO, if the main example shows it working with a vector, then it should work like that out of the box without the user having to specifically enter each type they want to work with.

With those changes, I have it working locally. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant