boostorg / boostorg/test

question: how to correctly create print helpers for '<<' explicitly removed in C++20?

Open
#409 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
213
Forks
149
Avg merge
18h 17m
Merged PRs (30d)
2

Description

Hello!
while project description states that this framework is for C++17 max, could anyone possibly help me with C++20 compatibility issue?
my problem is that in C++20 operator `<<` for printing wide strings (`std::wstring`, `const wchar_t*, etc) was explicitly [removed](https://en.cppreference.com/w/cpp/io/basic_ostream/operator_ltlt2l). In C++17 I could define helper template like
```
template<> std::ostream& operator<<(std::ostream& o, const std::wstring& what) { o << convert_to_char(what); return o; }
```
and it worked perfectly. In C++20 this no longer works, as this operator is explicitly deleted, so this template is not even considered. I found that I can partially solve the issue for `std::wstring` by defining this specialization
```
namespace boost {
namespace test_tools {
namespace tt_detail {
namespace impl {
template<> std::ostream& boost_test_print_type_impl::operator()(std::ostream& o, const std::wstring& what) const
{
o << convert_to_char(what); return o;
}
} // impl
} // tt_detail
} // test_tools
} // boost
```
but this works only for `std::wstring`, not for any wide string literals in a test like
```
BOOST_TEST(someWideString == L"expectations");
```
as I found no way to match `R const& r` against `wchar_t[12]` so I can't create a specialization in similar manner.

what need to be done, so BOOST_TEST could understand wide string literals in C++20?

if you need compiler specifics: this is Xcode 15 on macOS

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.