C++ Technical Specifications
A panel discussion
Library Fundamentals TS
Marshall Clow
Library Fundamentals V1 (published in May 2015)
● Calling a function with a tuple of arguments.
● _v shortcut for <type_traits>
● Allocator support for std::experimental::
function.
● optional, any, string_view
● New searching algorithms: Boyer-Moore and
Boyer-Moore-Horspool Searching
● New sampling algorithms
Library Fundamentals V2 (being published now)
● ostream_joiner
● propagate_const
● GCD and LCM
● Source location information
● Uniform Container erasure
Concurrency TS
Gor Nishanov
future<int> tcp_reader(int64_t total) {
struct State {
char buf[4 * 1024];
int64_t total;
Tcp::Connection conn;
explicit State(int64_t total) : total(total) {}
};
auto state = make_shared<State>(total);
return Tcp::Connect("127.0.0.1", 1337).then(
[state](future<Tcp::Connection> conn) {
state->conn = std::move(conn.get());
return do_while([state]()->future<bool> {
if (state->total <= 0) return make_ready_future(false);
return state->conn.read(state->buf, sizeof(state->buf)).then(
[state](future<int> nBytesFut) {
auto nBytes = nBytesFut.get()
if (nBytes == 0) return make_ready_future(false);
state->total -= nBytes;
return make_ready_future(true);
});
});
}); future<void> do_while(function<future<bool>()> body) {
} return body().then([=](future<bool> notDone) {
return notDone.get() ? do_while(body) :
make_ready_future(); });
}
auto tcp_reader(int total) -> future<int>
{
char buf[4 * 1024];
auto conn = await Tcp::Connect("127.0.0.1", 1337);
for (;;)
{
auto bytesRead = await conn.Read(buf, sizeof
(buf));
total -= bytesRead;
if (total <= 0 || bytesRead == 0) return total;
}
}
Parallelism TS
Gabriel Dos Reis
•
• seq par par_vec
std::vector<int> v = acquire_data();
// C++14
std::sort(v.begin(), v.end()); // standard
sequential sort
// C++14 + Parallelism TS
using namespace std::experimental::parallel;
sort(seq, v.begin(), v.end()); // explicitly
sequential sort
sort(par, v.begin(), v.end()); // permitting parallel
execution
sort(par_vec, v.begin(), v.end()); // permitting
vectorization as well
// Dynamic selection of execution policy
execution_policy policy = seq;
if (v.size() > threshold)
policy = par;
sort(with_policy, v.begin(), v.end());
std::reduce
o std::accumulate
o
std::exclusive_scan std::inclusive_scan
o std::partial_sum
o
op(x1, …, xn) == op(op(y1,…,yk), op(ym,…, yn))
op(x1, …, xn) == op(op(x1,…, xk), op(xm, …, xn))
adjacent_differen
adjacent_find all_of any_of
ce
copy copy_if copy_n count
std::for_each count_if equal exclusive_scan fill
fill_n find find_end find_first_of
find_if find_if_not for_each for_each_n
generate generate_n includes inclusive_scan
inner_product inplace_merge is_heap is_heap_until
lexicographical_c
is_partitioned is_sorted is_sorted_until
ompare
max_element merge min_element minmax_element
mismatch move none_of nth_element
partial_sort partial_sort_copy partition partition_copy
std::for_each_n reduce remove remove_copy remove_copy_if
std:: remove_if replace replace_copy replace_copy_if
generate_n std::copy_n replace_if reverse reverse_copy rotate
rotate_copy search search_n set_difference
set_symmetric_dif
set_intersection set_union sort
ference
stable_partition stable_sort swap_ranges transform
transform_exclusi transform_inclusi uninitialized_cop
transform_reduce
ve_scan ve_scan y
uninitialized_cop uninitialized_fil uninitialized_fil
unique
y_n l l_n
unique_copy
Transactional Memory TS
Michael Wong
–
–
–
–
–
–
16
17
18
Networking TS
Michael Caisse
Networking TS
TS Addresses
Doc : N4478
• Networking using TCP and UDP,
Author : Christopher Kohloff including support for multicast.
• Client and server applications.
• Scalability to handle many
Boost.Asio concurrent connections.
reference implementation
• Protocol independence between
Standalone Asio IPv4 and IPv6.
http://think-async.com/
• Name resolution (i.e. DNS).
• Timers.
class async_connection : public std::enable_shared_from_this<async_connection>
{
public:
async_connection(tcp::socket socket) : socket_(std::move(socket))
{}
void start() { do_read(); }
private:
void do_read()
{
auto self(shared_from_this());
socket_.async_read_some(buffer(buffer_space_),
[this, self](std::error_code ec, std::size_t length)
{
if (!ec)
{
uppercase(buffer_space_.begin(), buffer_space_.begin() + length);
do_write(length);
}
});
}
void do_write(std::size_t length)
{
auto self(shared_from_this());
async_write(socket_, buffer(buffer_space_, length),
[this, self](std::error_code ec, std::size_t /*length*/)
{
if (!ec)
{
do_read();
}
});
}
tcp::socket socket_;
std::vector<char> buffer_space_{1024};
};
Networking TS
Asynchronous Models
auto self(shared_from_this());
socket_.async_read_some(buffer(buffer_space_),
[this, self](std::error_code ec, std::size_t length)
Callbacks {
if (!ec){ /* do work ... */ }
});
std::future<std::size_t> fut =
socket.async_read_some(buffer(buf_space_), use_future);
Futures
// ...
std::size_t length = fut.get();
try {
std::vector<char> buf_space(1024);
for (;;)
{
Coroutines std::size_t len = socket.async_read_some(buffer(buf_space_),
/ resumable yield);
// do work ...
functions async_write(socket, buffer(buf_space_, len), yield);
}
}
catch (std::system_error& e) { ... }
Filesystem TS
Beman Dawes
Concepts TS
Eric Niebler
Please ask questions!