1// Unit test for boost::lexical_cast.
2//
3// See http://www.boost.org for most recent version, including documentation.
4//
5// Copyright Antony Polukhin, 2012-2024.
6//
7// Distributed under the Boost
8// Software License, Version 1.0. (See accompanying file
9// LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt).
10
11
12#include <boost/lexical_cast.hpp>
13
14#include <boost/utility/string_view.hpp>
15
16#ifndef BOOST_NO_CXX17_HDR_STRING_VIEW
17#include <string_view>
18#endif
19
20#include <boost/core/lightweight_test.hpp>
21
22using namespace boost;
23
24
25int main() {
26 boost::string_view bsw = "1";
27 BOOST_TEST_EQ(lexical_cast<std::string>(bsw), "1");
28 BOOST_TEST_EQ(lexical_cast<int>(bsw), 1);
29
30#ifndef BOOST_NO_CXX17_HDR_STRING_VIEW
31 std::string_view ssw = "42";
32 BOOST_TEST_EQ(lexical_cast<std::string>(ssw), "42");
33 BOOST_TEST_EQ(lexical_cast<int>(ssw), 42);
34#endif
35
36 return boost::report_errors();
37}
38

source code of boost/libs/lexical_cast/test/string_view_test.cpp