std::net, c++ ,,, std::experimental::net

td::net, the c++ networking library, gcc compiler has implemented it as std::experimental::net. std::net design is based on the boost asio library.

Asio is a cross-platform low-level library for network and I/O programming.

https://think-async.com/Asio

https://www.boost.org/libs/asio

Header:
<experimental/net>

Using std::net with gcc compiler:

namespace std
{
	using namespace std::experimental;
}

Build install gcc compiler from git:

git clone --depth=1 https://gcc.gnu.org/git/gcc

After building installing git gcc compiler, the experimental c++ net headers will be installed to gcc c++ system header directory experimental/.

c++ example:

#include <experimental/net>
#include <iostream>

namespace std
{
	using namespace std::experimental;
}

int main()
{
	std::net::io_context io_context;
	io_context.restart();
	std::net::io_context::executor_type exec = io_context.get_executor();
	std::cout << std::boolalpha << exec.running_in_this_thread() << std::endl;
	std::net::io_context & context = exec.context();
}

Compile it:

g++ net-prog.cpp -std=c++26 -o net-prog


May 14, 2025

Up: c++