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

Open
#409 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
28/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
cpp
Domain
testing

Research direction

Start by reviewing boost_test_print_type_impl::operator() and how BOOST_TEST processes wide string literals such as L"expectations" under C++20. Compare the existing std::wstring specialization with the array and pointer cases. Done means BOOST_TEST can understand wide string literals and wide strings when compiled with C++20, including the reported Xcode 15 environment.

Written by the indexing model from the issue text.

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. 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

Dominant language
C++
Stars
213
Forks
149
Avg merge
18h 17m
Merged PRs (30d)
2

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from boostorg/test

All issues in boostorg/test

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.