rollbear / trompeloeil

Header only C++14 mocking framework
Boost Software License 1.0
802 stars 85 forks source link

Problematic traits for ``streamer`` primary template #313

Closed DNKpp closed 10 months ago

DNKpp commented 11 months ago

Hello, with the arise of c++20 and its ranges namespace, providing views as parameters become more and more common. Unfortunatly trompeloeil doesn't fully support that, because the traits for the streamer primary template aren't precise enough.

Currently we have

template <typename T,
          bool = is_output_streamable<T>::value,
          bool = is_collection<detail::remove_reference_t<T>>::value>
struct streamer

This is problematic in situations, where T provides begin and end members, but only for non-const access. This may and will happen, when you use some advanced views. Unfortuantly this results in a huge compile error. Have a look at std::views::owning, which always offers a begin and end implementation, but conditionally enables the const overloads.

I think, the constraint can simply be fixed by simply adding const (at least in my project that works like a charm), as the streamer also uses a const T&.

template <typename T,
          bool = is_output_streamable<const T>::value,
          bool = is_collection<detail::remove_reference_t<const T>>::value>
struct streamer

EDIT: An alternative would be, to relax the streamer::print param to non-const, but this is probably not desired, as a streamer should not alter the streamed object in any way. So, I think it would be best, to stick with the const T& and strengthening the traits.

DNKpp commented 11 months ago

So, any comments on this? Shall I compile a pull request or is there any information needed?

rollbear commented 11 months ago

Sorry, I completely missed this. Thank you for pinging me. Please do make a PR, that would be very much appreciated.

rollbear commented 11 months ago

Thank you so much for the fix. I'm leaving this open until a new release has been tagged.

rollbear commented 10 months ago

Tagged v46 so closing now. Thanks again.