-
Notifications
You must be signed in to change notification settings - Fork 27
Open
Description
When compiling with MSVC (2017 and 2017.3), the following code works just fine. If I try to compile it with LLVM/Clang (4.0.1 with libcxx), I have to replace std::string_view with std::string.
#include <exception>
#include <iostream>
#include <net>
#include <string_view>
#include <system_error>
int main(int argc, char* argv[]) {
try {
// Must be std::string for clang.
const std::string_view address = argc > 1 ? argv[1] : "localhost";
const std::string_view service = argc > 2 ? argv[2] : "8080";
std::net::io_context io_context;
std::net::ip::tcp::socket socket(io_context);
std::net::ip::tcp::resolver resolver(io_context);
using results_type = std::net::ip::tcp::resolver::results_type;
resolver.async_resolve(address, service, [&](const std::error_code& ec, results_type results) {
if (ec) {
throw std::system_error(ec, "resolve");
}
// Cannot use results->endpoint() because of private inheritance.
std::cout << results.begin()->endpoint() << std::endl;
});
io_context.run();
}
catch (const std::exception& e) {
std::cerr << e.what() << std::endl;
}
return 0;
}The error is caused by NET_TS_HAS_STD_STRING_VIEW being set to 0.
Here is the <net> header:
//
// net
// ~~~~~~~~~~~~~~~~
//
// Copyright (c) 2003-2017 Christopher M. Kohlhoff (chris at kohlhoff dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef NET_TS_NET_INCLUDED
#define NET_TS_NET_INCLUDED
#include <experimental/__net_ts/ts/net.hpp>
namespace std {
namespace net = experimental::net;
} // namespace std
#endif // NET_TS_NET_INCLUDEDP.S.: Is it intentional that basic_resolver_results inherits privately from basic_resolver_iterator? Should I create a second issue regarding this?
P.P.S.: Great implementation even if it's "just" converted from ASIO. I even see a slight performance increase (~5%). Thank you!
Metadata
Metadata
Assignees
Labels
No labels