| 1 | // Copyright 2021 Peter Dimov |
|---|---|
| 2 | // Distributed under the Boost Software License, Version 1.0. |
| 3 | // https://www.boost.org/LICENSE_1_0.txt |
| 4 | |
| 5 | #include <boost/core/detail/string_view.hpp> |
| 6 | #include <boost/core/lightweight_test.hpp> |
| 7 | #include <boost/config.hpp> |
| 8 | |
| 9 | #if !defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE) |
| 10 | # if defined(__apple_build_version__) |
| 11 | // Under macOS, it's possible for the header |
| 12 | // <memory_resource> to be present, but for |
| 13 | // libc++.dylib to not have support for it. |
| 14 | // https://github.com/boostorg/core/issues/162 |
| 15 | # define BOOST_NO_CXX17_HDR_MEMORY_RESOURCE |
| 16 | # endif |
| 17 | #endif |
| 18 | |
| 19 | #include <string> |
| 20 | #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) |
| 21 | # include <string_view> |
| 22 | #endif |
| 23 | #if !defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE) |
| 24 | # include <memory_resource> |
| 25 | #endif |
| 26 | |
| 27 | boost::core::string_view f( boost::core::string_view const& str ) |
| 28 | { |
| 29 | return str; |
| 30 | } |
| 31 | |
| 32 | int main() |
| 33 | { |
| 34 | { |
| 35 | std::string s1( "123"); |
| 36 | std::string s2 = f( str: s1 ); |
| 37 | |
| 38 | BOOST_TEST_EQ( s1, s2 ); |
| 39 | } |
| 40 | |
| 41 | #if !defined(BOOST_NO_CXX17_HDR_STRING_VIEW) |
| 42 | |
| 43 | { |
| 44 | std::string_view s1( "123"); |
| 45 | std::string_view s2 = f( str: s1 ); |
| 46 | |
| 47 | BOOST_TEST_EQ( s1, s2 ); |
| 48 | } |
| 49 | |
| 50 | #endif |
| 51 | |
| 52 | #if !defined(BOOST_NO_CXX17_HDR_MEMORY_RESOURCE) |
| 53 | |
| 54 | { |
| 55 | using pmr_string = std::basic_string<char, std::char_traits<char>, std::pmr::polymorphic_allocator<char>>; |
| 56 | |
| 57 | pmr_string s1( "123"); |
| 58 | pmr_string s2 = f( str: s1 ); |
| 59 | |
| 60 | BOOST_TEST_EQ( s1, s2 ); |
| 61 | } |
| 62 | |
| 63 | #endif |
| 64 | |
| 65 | return boost::report_errors(); |
| 66 | } |
| 67 |
